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

Author Topic: Squares when drawing SFML graphics with OpenGL  (Read 1650 times)

0 Members and 1 Guest are viewing this topic.

xoxalph

  • Newbie
  • *
  • Posts: 4
    • View Profile
Squares when drawing SFML graphics with OpenGL
« 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:



Thanks.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Squares when drawing SFML graphics with OpenGL
« Reply #1 on: October 23, 2014, 04:56:13 pm »
Is there a reason why you don't use sf::RenderTexture instead of raw OpenGL FBOs?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

xoxalph

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Squares when drawing SFML graphics with OpenGL
« Reply #2 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.

xoxalph

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Squares when drawing SFML graphics with OpenGL
« Reply #3 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.
« Last Edit: October 23, 2014, 05:08:59 pm by xoxalph »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Squares when drawing SFML graphics with OpenGL
« Reply #4 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 :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything