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] 4 5 ... 31
Feature requests / Re: Adding VertexArray[i].setTexture
« on: April 30, 2021, 10:45:04 pm »
I can think of a few solutions:

Maintain a vertex array for each different texture. Even if there are 10-20 different textures then drawing this many arrays is negligible. If a province needs to change texture, rebuild the array it was in, and the array it needs to be in, moving the province vertices from one to the other, and thus changing the texture.

Use some shader magic. This wiki page explains how multiple tiles can be drawn using a texture to look up tile indices:
With some work, as long as you don't mind losing the ability to colour your vertices, it could be modified so that the vertex colour is used to select the correct tile, rather than using a lookup texture. Then at runtime changing the colour of the vertex would select the desired tile.

Use some shader and OpenGL magic. Probably over-engineering, but expanding on the previous suggestion you could use a texture array. Then, using the vertex colour property again, you could select the appropriate texture by indexing it via the colour value.

General / Re: Get the Screen Location of a VertexArray
« on: April 30, 2021, 06:23:28 pm »
Rather than use sf::Transform directly you might want to try inheriting sf::Transformable, which is what sf::Shape and other drawables do. It provides the getPosition() etc functions:


General / Re: The way to construct 2D scene?
« on: April 21, 2021, 10:57:33 am »
A common approach is to use a scene graph. There's a topic in the SFML tutorials which touches on implementation, and it is covered in detail in the SFML Game Development book.

General / Re: getting pixels of a texture
« on: April 17, 2021, 10:31:05 am »
sf::Texture::loadFromFile() also allows you to supply an sf::IntRect which defines a smaller part of the texture you want to load


You can also use sf::Sprite::setTextureRect() to display only part of a texture


General / Re: SFML and Compute Shaders
« on: April 05, 2021, 10:16:51 am »
You'll need to create a gl loader with something like https://glad.dav1d.de/ and include the resulting files in your project. Note that these may or may not mix well with sfml's graphic module, so you may need to omit that and use the window module directly with opengl. I believe there's an example in the tutorial section  ;D

General / Re: Stutter Occurs In Application
« on: March 18, 2021, 10:54:37 am »
To narrow down the cause you could try some code known to work, such as the source of the SFML game development book: https://github.com/SFML/SFML-Game-Development-Book or, if you're desperate ( ;) ), one of my projects: https://github.com/fallahn/xygine . There are of course others in the SFML projects sub-forum which you can check out.

If these run smoothly for you (although experience tells me you will need nvidia's threaded optimisation disabled) then the root cause is likely your code, and you can use the example source as a launching point for creating your own project.

If they don't then there's possibly a problem with your driver/hardware/OS combination. It may or may not also help to enable/disable v-sync. If you have access to another computer then try running your own and the sample code on there, to see if there's a difference.

General / Re: Stutter Occurs In Application
« on: March 13, 2021, 12:49:20 pm »
Do you have an nvidia gpu? If so disabling 'threaded optimization' in the nvidia control panel can help.

General / Re: 3D Model Projection in SFML
« on: March 08, 2021, 02:49:43 pm »
Broadly speaking it is possible to fudge 3D models with a sfml vertex array, some custom vertex shaders and the glm maths library - there's a proof of concept I came up with here: https://github.com/fallahn/osgc/tree/master/fist/src and a tool for converting models into vertex arrays here: https://github.com/fallahn/osgc/tree/master/lightmapper

If you're interested in how it works I don't mind explaining the concepts - but to be perfectly honest for the amount of work it takes you're better off just using OpenGL directly :)

SFML development / Re: C++ standards
« on: March 04, 2021, 01:52:47 pm »
final Can also help with devirtualization and offers performance increases in certain cases:


Graphics / Re: Camera Shake
« on: February 17, 2021, 10:52:10 am »
Take a look at views: https://www.sfml-dev.org/tutorials/2.5/graphics-view.php these are basically your in-game camera. Adding some movement to the position will create something akin to camera shake.

SFML projects / Re: Selba Ward
« on: February 16, 2021, 05:37:08 pm »
You need to treat your render texture like a window - that is, create it only once, then call renderTexture.clear() before you draw on it, followed by renderTexture.display() when you've finished drawing.

sf::RenderTexture rt;
sf::RenderWindow rw;


    //draw stuff

    //draw other stuff


My personal recommendation is, as eXpl0it3r said, SFML Game Development (not 'by example'). It concisely runs through a game project from beginning to end, and is written by authors who are on the SFML development team or closely associated with it, so, in my opinion, have a better understanding of SFML's design goals and how it is intented to be used.

sf::Text::setColor() has indeed been deprecated in favour of setFillColor() and setOutlineColor(). The deprecation notice should only be a warning (setColor() still exists for compatibility), however Visual Studio treats deprecation warnings as errors. To change the behaviour you can disable the warning.

Graphics / Re: Shaders
« on: January 25, 2021, 05:19:03 pm »
Try turning off the smoothing on the render texture, it may be causing it to get sampled outside the texture's area, which would create artifacts.

My personal favourite for learning not just shaders, but almost all aspects of SFML, was SFML Game Development:


Graphics / Re: Shaders
« on: January 23, 2021, 11:59:35 am »
uniform float frag_LightAttenuation;

is a float


is attempting to set an int. (You can tell from the error by looking up glUniform1i())

You probably want

It pays to be specific with your constants, instead of relying on implicit conversion. In this case it's not being converted because an overload for setUniform() is available for integers.

Also as a side note: there's no reason to 'new' your shader, especially as you don't even delete it. Place it on the stack with your other resources and it'll be fine.  ;)

General / Re: Unresolved external symbol error
« on: January 02, 2021, 12:09:50 pm »
Did you define SFML_STATIC ?

Pages: 1 2 [3] 4 5 ... 31