Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - fallahn

Pages: [1] 2 3 ... 31
1
Graphics / Re: Touch joystick border radius
« on: June 22, 2022, 10:40:21 am »
Regular circle-circle collision detection will work (there are plenty of tutorials out there), but instead of making sure the minimum distance between centres is always >= the sum of the radii, you make sure the *maximum* distance is <= large radius minus the small radius

2
Audio / Re: music sound lowered
« on: May 10, 2022, 10:55:24 am »
It's an automatic gain control applied by OpenAL to try to make sure that the total volume doesn't exceed an internal limit and start to distort. It can even vary between speaker setups, I've noticed the effect is much more noticeable with 2 channels than it is for surround.

I've experimented a bit and found that the best way to try and counteract the effect is to lower the gain of OpenAL sources - which is the same as setting their volume in SFML. As a starting point assuming that the internal max gain is 100, set both of your sources to 50. If you play both at once you should find that the music shouldn't get as quiet, if at all, when both sounds play, because the total gain is <= max gain.

These numbers are a rough guess, and to find the perfect amount of gain with minimal quietening effect you'll have to experiment, but it should demonstrate what I mean. A good estimation for an average gain is to take the max gain and divide it by the number of sounds you expect to be playing at any one time.

Of course the overall volume will now sound quieter. This can be compensated for by increasing the listener volume, but it also helps to set the actual level of your audio files (in an audio editor) to as loud as possible (or at the very least make sure they all have the same level), then let OpenAL/SFML attenuate as needed.

HTH

3
Graphics / Re: Can't draw 2 big textures
« on: May 04, 2022, 07:35:39 pm »
12000px is *very* large for a texture and your GPU might not support it. You can check the max texture size your hardware supports with sf::Texture::getMaximumSize() https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Texture.php#a0bf905d487b104b758549c2e9e20a3fb and split it into smaller textures if you need to.

For southpark style animation a better choice might be to use software like Spine or Spriter

4
General / Re: link errors
« on: April 05, 2022, 10:26:02 am »
To clarify: It doesn't matter if Visual Studio itself is a 32 bit or 64 bit application. Either version can compile 32 or 64 bit programs. You just need SFML to match the program you're compiling.

5
General / Re: link errors
« on: April 04, 2022, 11:13:38 pm »
I downloaded SFML-2.5.1-windows-vc14-32-bit from the SFML site.

 I'm compiling for debug x64

You can't mix 32/64 bit libs/build. You either need the 64bit libs, or switch to a 32 bit build  :)

6
Graphics / Re: sf::RenderTexture not working properly
« on: March 31, 2022, 05:31:49 pm »
A couple of things:
First I can't see where you call display() on the render texture, this could well be the problem. However it might also be worth doing the drawing with each target sequentially:

texture.clear();
....
texture.display();

window.clear();
....
window.display();
 

Also rather than use a reference to the active target, use a pointer, as it's possible you may end up copying something at some point, and SFML will create a new texture (and potentially even discard the old one) if a RenderTexture is copied, which could end up throwing things out of sync.

7
Window / Re: Failed to activate OpenGL: the handle is invalid
« on: March 12, 2022, 11:18:03 am »
If you're going to require a thread for each window then the next best thing is to try and isolate the threads as much as possible, so that you don't need to share (memory space) data between them. X Windows (https://en.wikipedia.org/wiki/X_Window_System) uses a client/server architecture so you might gain something by that approach.

Run the logic of your application in its own thread, and use it to create a 'server'. You can then create individual threads for each window you need, completely self containing the drawing and event handling, and then communicate with the server thread using a library such as Enet (http://enet.bespin.org/). Forward events from your window to the server, process them, then have the server broadcast the results to all connected windows (clients) for them to draw.

In this situation you also get the added bonus that your main logic processing is effectively run in a separate thread to graphics and rendering.

Will this introduce lag? Yes, some, but if it's all running on a local machine it will likely be negligible. Depending on your application, it will be fine, for example if you're running some kind of graphing simulation. Turn based games will probably work very well too (I know this from experience 8) https://fallahn.itch.io/vga-golf ). For fast action games there are tried and tested methods which can be implemented to negate perceivable lag, should it be deemed necessary:
https://www.gabrielgambetta.com/client-server-game-architecture.html
https://gafferongames.com/categories/networked-physics/

HTH

8
Graphics / Re: How to color the lines of a Vertex Array
« on: March 03, 2022, 10:39:47 am »

9
(r - expand) / (1 - expand)

Depending on your driver/implementation the '1' maybe interpreted as an int, causing an implicit conversion. Try

(r - expand) / (1.0 - expand)

You could (and probably should as general good practice) also include the #version 120 directive at the top of your shader, to make sure you're getting the GLSL version SFML expects.

10
Graphics / Re: Resizing of an Image in SFML 2.5
« on: February 15, 2022, 04:20:21 pm »
Once you have your sprite and have resized it you can draw it to sf::RenderTexture then use sf::RenderTexture::getTexture()::copyToImage() to get it back to an image object. It can be slow but might be fast enough for what you need.

11
General / Re: Rectangle bottom collision issues
« on: February 06, 2022, 04:48:33 pm »
Detecting the collision and stopping falling is not enough on its own. You also have to calculate how much overlap (aka penetration) the collision created and move the character back by that much, so that it lines up with the platform. I wrote a post about simple collision detection some time back, it may be useful here.

https://trederia.blogspot.com/2016/02/2d-physics-101-pong.html

12
Graphics / Re: unefficient drawing
« on: February 05, 2022, 12:38:26 pm »
You can probably alleviate the drawing a bit by rendering each point as a vertex in a vertex array, with the primitive type set to points.


    sf::VertexArray vertexArray(sf::PrimitiveType::Points);

    while(window.isOpen()){
        window.clear();
        while(window.pollEvent(event)){
            if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Enter) && (!fullscreen)) {
            fullscreen = true;
            window.create(VideoMode(1920, 1080), nameProject, (fullscreen ? Style::Fullscreen : Style::Resize|Style::Close));
         }
            else if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Escape) && (fullscreen)) {
            fullscreen = false;
            window.create(VideoMode(1920, 1080), nameProject, (fullscreen ? Style::Fullscreen : Style::Resize|Style::Close));
         }
            if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Space) && (fullscreen)) {
                pause = !pause;
         }
            if(event.type == Event::Closed){
                window.close();
            }
        }

        float dt = gameClock.getElapsedTime().asSeconds();
        gameClock.restart();

        vertexArray.clear();

        for(int i=0; i<player.size(); i++){
            if(fullscreen && !pause){
                player.x+=player.vx*dt;
                player.y+=player.vy*dt;

                if(player.x < player.r){
                    player.x += 2*(player.r-player.x);
                    player.vx *= -1;
                }
                else if(player.x > window.getSize().x-player.r){
                    player.x += 2*(window.getSize().x-player.r-player.x);
                    player.vx *= -1;
                }
                if(player.y < player.r){
                    player.y += 2*(player.r-player.y);
                    player.vy *= -1;
                }
                else if(player.y > window.getSize().y-player.r){
                    player.y += 2*(window.getSize().y-player.r-player.y);
                    player.vy *= -1;
                }
            }
            if(fullscreen){
                player.body.setPosition(player.x-player.r, player.y-player.r);
                vertexArray.append(sf::Vertex(sf::Vector2f(player.x-player.r, player.y-player.r)));
            }
        }

        window.draw(vertexArray);
       
        window.display();
        Sleep(1);
    }
 

This will batch all of your points into a single draw call.

13
I've managed to render 3D models using the SFML graphics module with some shader trickery, and by forcing normal/depth data into the colour property of sf::VertexArray - and made a couple of games with that technique:

https://fallahn.itch.io/did
and
https://fallahn.itch.io/purcitop-garden

The gist of it is to replace the model/view/projection matrices with your own in a custom vertex shader, and to store the normal vector in the vertex RGB channel, and vertex z-depth as a normalised value in the vertex alpha channel. It kinda works, although to be honest the amount of OpenGL you need to learn to understand how SFML works under the hood means it's probably not worth the effort (other than the learning exercise) and I should probably just use OpenGL directly for the performance gain  ;D

If you're curious source is available here: https://github.com/fallahn/osgc/tree/master/did and here https://github.com/fallahn/osgc/tree/master/lightmapper for a model format converter I made to go with it (yes, I even went as far as to create a specific model format...)

14
You most likely want to use getTransform() (inherited from sf::Transformable) with your RenderStates used to draw the array:

https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php#creating-an-sfml-like-entity

15
Your best bet is to add 2 uniforms for texture size and texture rect size, and set them each time you draw a sprite. This is probably also applicable if you try to build on mac (and possibly linux) as they require a core version of OpenGL and a declaration of #version 120 at the top of your shader. (Windows drivers often supply a 'compatibility' context which is why your current solution works for you) textureSize() requires #version 130 or greater, and would therefore become unavailable.

Quote
If you want to use the graphics module on OS X, you are limited to using a legacy context which implies OpenGL version 2.1.
https://www.sfml-dev.org/tutorials/2.5/window-opengl.php

https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureSize.xhtml

#version 120

uniform sampler2D source;
uniform sampler2D noiseTexture;
uniform float dissolveAmount;
uniform vec2 u_textureSize;
uniform vec2 u_rectSize;

void main()
{
        vec2 textureCoordinates = gl_TexCoord[0].xy;
       
        float edgeThickness = 0.1;
        vec4 edgeColor = vec4(255, 0, 0, 100);
        float noiseTiling = 0.8;
       
        vec2 textureScale = u_textureSize / u_rectSize;

        ...
}

 

Pages: [1] 2 3 ... 31
anything