2D OpenGL

Started by
3 comments, last by sakky 21 years, 2 months ago
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?
Take back the internet with the most awsome browser around, FireFox
Advertisement
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.

  //--------------------------------------------------// 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();    }  
------------------------------------------------------------I wrote the best video game ever, then I woke up...
This works with (0,0) at the top left hand corner right?
Take back the internet with the most awsome browser around, FireFox
yup

My Homepage
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Ok, its not working at all! I use glVertex2d() and I''m not getting anything on the screen.
Take back the internet with the most awsome browser around, FireFox

This topic is closed to new replies.

Advertisement