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

Author Topic: Is this considered a bug? (SFML 2.0)  (Read 2267 times)

0 Members and 1 Guest are viewing this topic.

sfml_fan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Is this considered a bug? (SFML 2.0)
« on: May 17, 2012, 09:34:21 am »
Calling window.pushGLStates and then popGLStates doesn't set the glMatrixMode properly.  Well, I an OpenGL newbie so I'm not sure if this is expected or not.  Basically, writing text to the window requires me to use push/pop, but pop doesn't return me to my previously expected state!

g++ main.cpp -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-graphics -lsfml-system  -lglut -lGLU -lGL -lm -o run

#include <GL/gl.h>
#include <GL/glu.h>

int main() {
    sf::RenderWindow window(sf::VideoMode(800, 800), "SFML window");
 
    sf::Font font;
    if (!font.loadFromFile("tahoma.ttf"))
      return EXIT_FAILURE;
    sf::Text text("Hello SFML", font, 50);
 
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, 2.f, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
 
    int i = 0;
    while (window.isOpen()) {
      i++;
 
      window.setActive();
      if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
        window.close();
      }
      window.clear();
 
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
      glLoadIdentity();
      glTranslatef(0.f,0.0f,-1.0f * i);
 
      glBegin(GL_TRIANGLES);                      // Drawing Using Triangles
      glVertex3f( 0.0f, 1.0f, 0.0f);              // Top
      glVertex3f(-1.0f,-1.0f, 0.0f);              // Bottom Left
      glVertex3f( 1.0f,-1.0f, 0.0f);              // Bottom Right
      glEnd();
 
      window.pushGLStates();
      window.draw(text);
      window.popGLStates();

      //  Why is this required?
      glMatrixMode(GL_MODELVIEW);

      window.display();
    }
    return EXIT_SUCCESS;
  }

 

At the end of main, I have to call

glMatrixMode(GL_MODELVIEW);

in order to get "movement" working.  If you comment out the line, you will see a static screen.  If you uncomment the line, you will see the triangle fade into the distance.
« Last Edit: May 17, 2012, 09:49:28 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Is this considered a bug? (SFML 2.0)
« Reply #1 on: May 17, 2012, 09:53:52 am »
It looks like a bug, but it's strange because SFML pushes and restores all states.
Laurent Gomila - SFML developer

 

anything