Archived

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

Densun

OpenGL 2D graphics with OpenGL

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
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