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 ... 3 4 [5] 6 7 ... 33
61
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.

62
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

https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php#loading-a-texture

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

https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php#ok-can-i-have-my-sprite-now

63
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

64
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.

65
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.

66
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 :)

67
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:

https://devblogs.microsoft.com/cppblog/the-performance-benefits-of-final-classes/

68
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.

69
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;

rt.create(w,h);
rw.create(w,h);

while(rw.isOpen())
{
    rt.clear();
    //draw stuff
    rt.display();

    rw.clear();
    //draw other stuff
    rw.display();
}

 

70
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.

71
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:

https://www.packtpub.com/product/sfml-game-development/9781849696845


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

is a float

shader->setUniform("frag_LightAttenuation",100);

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

You probably want
shader->setUniform("frag_LightAttenuation",100.f);

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.  ;)

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

74
Graphics / Re: Shader in SFML
« on: January 02, 2021, 12:07:53 pm »
Some thoughts:

You should include a version directive: https://www.khronos.org/opengl/wiki/Core_Language_(GLSL)#Version

SFML uses GLSL 1.2 so you'd need
#version 120

GLSL 1.2 doesn't support smoothstep() https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/smoothstep.xhtml
This is easy to implement it yourself, the link even gives an example.

GLSL 1.2 provides gl_TexCoord so you can do this with SFML:
vec2 st = gl_TexCoord[0].xy;

although this is removed in GLSL 1.3 and higher.

75
Graphics / Re: Texture loadFromFile every frame.
« on: December 07, 2020, 03:08:18 pm »
An sf::Image has its data stored in RAM already, so when you do loadFromImage() the graphics data is copied from RAM to video memory which, as you've noticed, is reasonably fast - fast enough for your use case at least. Loading an image from a file is slower because it has to read from storage rather than RAM (although SSDs appear to be rapidly closing that gap), be decoded if it's a compressed format such as png or jpg, then finally get copied into a section of RAM ready to be uploaded to the GPU.

I probably wouldn't recommend trying to load from file every frame, but as a more general rule I tend to not worry about these things too much until they present a measurable problem, in which case I'll investigate more and look for ways to improve performance.

Pages: 1 ... 3 4 [5] 6 7 ... 33