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

Author Topic: Using pure openGL is super slow?  (Read 2656 times)

0 Members and 1 Guest are viewing this topic.

hipsterdufus

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Using pure openGL is super slow?
« 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?

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Using pure openGL is super slow?
« Reply #1 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.

hipsterdufus

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Using pure openGL is super slow?
« Reply #2 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?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Using pure openGL is super slow?
« Reply #3 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.

KraHen

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Using pure openGL is super slow?
« Reply #4 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.
« Last Edit: August 06, 2013, 07:00:19 pm by KraHen »

 

anything