Are you guys just lazy!? There have been thousands of posts along the lines of "How do I do 2d in OpenGL" to "Duuuhde, I wunt too maek a two dee gaem in ohpun jee el; how do eye set uhp two dee???!?"
I have developed a simple, nice, pretty way for all of you to have your 2D fun.
void glEnable2D()
{
int vPort[4];
glGetIntegerv(GL_VIEWPORT, vPort);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, vPort[2], 0, vPort[3], -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
}
void glDisable2D()
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
To use these two functions, simply call glEnable2D(), draw whatever you want to have 2D''d, then call glDisable2D().
Here''s an example:
void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glEnable2D();
glBegin(GL_TRIANGLES);
glColor3ub(255, 0, 0);
glVertex2d(0, 0);
glColor3ub(0, 255, 0);
glVertex2d(100,0);
glColor3ub(0, 0, 255);
glVertex2D(50, 50);
glEnd();
glDisable2D();
}
See? Nice and small; Nice and simple.
So please friends, don''t ask how to setup OpenGL in 2D mode... Because now you know.
~Jesse Lawson