Jump to content
  • Advertisement

Archived

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

Densun

OpenGL 2D graphics with OpenGL

This topic is 6225 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

Is it possible to do 2D graphics programming with OpenGL like it is with DirectDraw? Or is it more similar to the new Direct3D?

Share this post


Link to post
Share on other sites
Advertisement
OpenGL was innitially a 2D graphics library, with 3D being added later. It''s very possible (and quite easy) to do 2D graphics with it. Look up glVertex2f and glOrtho.

For switching to a 2D perspective for drawing, I use the following function. Not sayings it''s the best, but it does the job.

void GL_Set2D ()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, 100, 0, 100, -99999, 99999);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity ();
glDisable(GL_DEPTH_TEST);
}

That will set OpenGL to draw in 2D. When drawing to the screen, you pass the location of where you want it drawn as a percentage of the screen size, so that glVertex2f(50,50); would place a vertice on the centre of the screen, no matter what your screen resolution is at.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!