SFML community forums

Help => Graphics => Topic started by: xoxalph on October 23, 2014, 04:54:37 pm

Title: Squares when drawing SFML graphics with OpenGL
Post by: xoxalph on October 23, 2014, 04:54:37 pm
I'm trying to draw a texture and a string after rendering the OpenGL stuff. It worked fine before and then it suddenly started glitching at one point. I use FBOs for post-processing, so the final step is just rendering an FBO texture on screen. I don't see what the problem could be here, any lingering OpenGL states that aren't pushed?

This is the code I'm testing with:

sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT, 32),
              "Game", sf::Style::Titlebar | sf::Style::Close, sf::ContextSettings(32)
               );

...

glUseProgram(0);
glBindVertexArray(0);
glActiveTexture(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);

window.pushGLStates();

sf::Sprite spr;
spr.setPosition(sf::Vector2f(10.f, 10.f));
spr.setScale(sf::Vector2f(2.f, 2.f));
spr.setTexture(TEX[3]);
text.setString("test string 1");
text.setPosition(sf::Vector2f(10.f, 10.f));
window.draw(spr);
window.draw(text);

window.popGLStates();
window.display();
 

And this is what I get:

(http://i.imgur.com/cyK95ff.png)

Thanks.
Title: Re: Squares when drawing SFML graphics with OpenGL
Post by: Nexus on October 23, 2014, 04:56:13 pm
Is there a reason why you don't use sf::RenderTexture instead of raw OpenGL FBOs?
Title: Re: Squares when drawing SFML graphics with OpenGL
Post by: xoxalph on October 23, 2014, 05:02:01 pm
I'm more comfortable using OpenGL for most purposes. I used two FBOs before, and it worked just fine. Now I'm using three, though it started glitching before that.
Title: Re: Squares when drawing SFML graphics with OpenGL
Post by: xoxalph on October 23, 2014, 05:05:10 pm
Sorry, but I manged to fix it. My texture states were a bit jumbled up, so changing it to
glActiveTexture(GL_TEXTURE0);
made it work fine.

Thanks anyway. No need to keep this thread open.
Title: Re: Squares when drawing SFML graphics with OpenGL
Post by: Nexus on October 23, 2014, 05:14:58 pm
I'm more comfortable using OpenGL for most purposes.
Looking at this bug, apparently not :P

More seriously, I think your code could be simpler and faster to develop/maintain/debug if you used SFML in the places where you could (after all, there's probably a reason why you use it for many other parts). There are of course arguments to use raw OpenGL, but I'm not sure if it's worth the additional time only because of "more comfortable", especially since it takes very shortly to learn the SFML counterparts. This just as a tip, it's of course your decision :)