2D OpenGL
How would I set OpenGL up to use 2D? I need 2D for drawing mouse cursors and user interface things. May I see some example init() code or links please on setting OpenGL up for this type of rendering?
It''s actually very simple.
First you render the 3D world as you see fit (if you even have one).
Then set the projection matrix to Ortho..
Render the UI objects.
Set it back to 3D.
Repeat...
Below is my source for toggling between the 2.
First you render the 3D world as you see fit (if you even have one).
Then set the projection matrix to Ortho..
Render the UI objects.
Set it back to 3D.
Repeat...
Below is my source for toggling between the 2.
//--------------------------------------------------// COpenGL::Set2D// Sets the OpenGL Projection Matrix to 2D void COpenGL::Set2D(int nWidth, int nHeight){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Set up the orthograhic projection: glOrtho(0.0f, (GLfloat)nWidth, 0.0f, (GLfloat)nHeight, -1.0f,1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST);}//--------------------------------------------------// COpenGL::Set3D// Sets the OpenGL Projection Matrix to 3D void COpenGL::Set3D(int nWidth, int nHeight){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)nWidth/(GLfloat)nHeight,0.1f,1000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement