SFML community forums

Help => Graphics => Topic started by: hipsterdufus on August 04, 2013, 10:30:50 pm

Title: Using pure openGL is super slow?
Post by: hipsterdufus on August 04, 2013, 10:30:50 pm
Hi all, I am stumped by the following problem. I created a class that will represent my game's menu screen. There's really nothing in this class other than it inherits public sf::Drawable and I'm overriding the draw function as follows:

void ScreenMenu::draw(sf::RenderTarget& target, sf::RenderStates states) const {

   target.clear(sf::Color::Black);
   glBegin(GL_QUADS);
   glVertex3f( 0.0f, 0.0f, 0.f);             
    glVertex3f( 5.0f, 0.0f, 0.f);             
    glVertex3f( 5.0f, 5.0f, 0.f);
   glVertex3f( 0.0f, 5.0f, 0.f);
   glEnd();

}



This gets called here from my main class:

   while (mWindow.isOpen()){
      // check all the window's events that were triggered since the last iteration of the loop
      sf::Event event;
      while (mWindow.pollEvent(event)){
         // "close requested" event: we close the window
         if (event.type == sf::Event::Closed)
            mWindow.close();
      }

      mWindow.draw(screenMenu);
   }



There must be something stupid I'm not initializing correctly...the screen comes up all white and its laggy as hell. I can close the window (after some serious lag) or if I don't my graphics card driver crashes and restarts. Is there something I'm forgetting to do here?
Title: Re: Using pure openGL is super slow?
Post by: victorlevasseur on August 04, 2013, 10:47:38 pm
Hello,

You don't call target.Display() after all the OpenGL calls to render the frame buffer. This can be the problem.
Title: Re: Using pure openGL is super slow?
Post by: hipsterdufus on August 05, 2013, 01:24:41 am
Thanks, you are correct that was the problem. One more question: why does this draw a quad in the entire top right quarter of the screen?

glBegin(GL_QUADS);
glVertex2f( 0.0f, 0.0f);             
glVertex2f( 1.0f, 0.0f);             
glVertex2f( 1.0f, 1.0f);
glVertex2f( 0.0f, 1.0f);
glEnd();

I thought the numbers are supposed to represent pixels on the window? Not sure why it's the entire top right quarter of the screen?
Title: Re: Using pure openGL is super slow?
Post by: G. on August 05, 2013, 02:28:32 am
OpenGL coordinates aren't in pixels, they are in "units". How "big" is 1 unit depends on how you set your model / view / projection matrices.
Title: Re: Using pure openGL is super slow?
Post by: KraHen on August 06, 2013, 06:40:30 pm
Those coordinates are simple cartesian coordinates ranging from -1 to 1, and such are the quarters distributed (so ++ is the first quarter, +- is the second, -- is the third and -+ is the fourth). You are filling the first quarter here with your quad, that`s why the entire top right quarter of the screen is filled.

Of course once you set up a MVP matrix enviroment this changes, and your camera code handles these transformations from world space to view space.