SFML community forums
Help => Graphics => Topic started by: cwkx on March 16, 2012, 02:25:15 pm
-
Hi,
I'm porting some work to SFML - I need to apply fullscreen shaders to the entire window render area, instead of just a texture rectangle. I see you can draw shaders by specifying vertices, but after trying:
const SF::Vertex vertices[] = { SF::Vertex(SF::Vector2f(-1.0f, 1.0f)), SF::Vertex(SF::Vector2f(1.0f, 1.0f)), SF::Vertex(SF::Vector2f(1.0f, -1.0f)), SF::Vertex(SF::Vector2f(-1.0f, -1.0f)) };
target.draw(&vertices[0], 4, SF::PrimitiveType::Quads, states);
1. I found it doesn't use normalized coords - how can I therefore draw to the entire window render area efficiently (do I really have to recreate 4 vertices from the app size each frame)?
2. I need to use "uniform mat4" for several of my shaders. Do I just do it manually with glUniformMatrix4fv(..., 1, GL_FALSE, &viewMatrix[0][0]); ?
3. I was looking at the code, I noticed setParameter is called in the update loop, which implicitly does: GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str()); - isn't this slow when you have quite a lot of parameters? What about providing a int getFastParamID(...) to call in init, then instead of having strings force users who don't care about optimizations to do setParameter(getID("name"), ...) - but this allows users who do care about performance to just send the private GLint from the init - do you think this'll make much difference? (I don't know much about the framework/principles/conventions in SFML yet though so may have missed something)
4. (Offtopic) Is there an easy way to use subpixel font rendering/expose it from freetype? - I haven't looked into this yet.
- P.S. Thanks so much for keeping SFML lightweight! :wink: I was very happy to see the output size, with static linking, so small.
-
1. I found it doesn't use normalized coords - how can I therefore draw to the entire window render area efficiently (do I really have to recreate 4 vertices from the app size each frame)?
Yes. Why is it a problem?
2. I need to use "uniform mat4" for several of my shaders. Do I just do it manually with glUniformMatrix4fv(..., 1, GL_FALSE, &viewMatrix[0][0]); ?
SFML provides support for SFML types. Therefore you can send a sf::Transform (as a mat4), but not a raw matrix. I guess doing it manually would work, although it is not the recommended usage.
3. I was looking at the code, I noticed setParameter is called in the update loop, which implicitly does: GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str()); - isn't this slow when you have quite a lot of parameters?
Try, and come back with results ;)
My philosophy for SFML is to make it simple, and then only optimize where it is really necessary.
But my guess is that it wouldn't make a big difference.
4. (Offtopic) Is there an easy way to use subpixel font rendering/expose it from freetype? - I haven't looked into this yet.
Easy way, most likely, but "public"/"official", no :)
-
Thanks for the quick reply!
1. Sorry, there's no problem with this at all - I just thought their may have been "GetScreenVertices()" or something - but setting vertices each frame works well:
const SF::Vertex vertices[] = { SF::Vertex(SF::Vector2f(0.0f, app.getSize().y)), SF::Vertex(SF::Vector2f(app.getSize().x, app.getSize().y)), SF::Vertex(SF::Vector2f(app.getSize().x, 0.0f)), SF::Vertex(SF::Vector2f(0.0f, 0.0f)) };
Simple is good for this library and its intentions :)
Thanks.
-
Do you actually rename namespace sf to SF in your code? :shock: :lol:
-
Haha yeah ;) namespace SF = sf; to be consistent with the previous work - thankfully that's the only major change in style though now that your using lowercase camelCase :)