Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

sakky

OpenGL 2D OpenGL

This topic is 5763 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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();

}

Share this post


Link to post
Share on other sites
Ok, its not working at all! I use glVertex2d() and I''m not getting anything on the screen.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!