SFML community forums
Help => Graphics => Topic started 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?
-
Hello,
You don't call target.Display() after all the OpenGL calls to render the frame buffer. This can be the problem.
-
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?
-
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.
-
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.