I am currently making my first game in OpenGL (c++). I am able to make some 2D stuff and 3D stuff. But not together. I mean, having a 3D game with 2D elements glued to the screen (HUD/GUI).
Somehow, only one of them (2D or 3D) works at a given time.
I'll show you my drawing function:
Code: Select all
Window::clear();
// 3D
glPushMatrix();
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
camera.updateCamera();
for(unsigned int i = 0; i < cubes.size(); i++) {
cubes.at(i)->draw();
}
for(unsigned int i = 0; i < floor.size(); i++) {
floor.at(i)->draw();
}
player->draw();
glPopMatrix();
// 2D
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, Window::getWidth(), Window::getHeight(), 0.0f, -1.0f, 1.0f);
glDisable(GL_DEPTH_TEST);
//glMatrixMode(GL_PROJECTION); // <---- Removing this line = 3D, un-comment this line = 2D
Menu::draw();
glPopMatrix();
Window::flipScreen();
Do you need to see more code to be able to help me out here?
(Yeah, I guess I don't need those glPopMatrix and glPushMatrix functions, and some other stuff, but I am not really sure when to use them, as I am not that into OpenGL yet)