Open GL for 2D Drawing

Started by
3 comments, last by LeLe 21 years, 6 months ago
within glBegin scope, we can draw basic 3D primitives. But is there special for 2D drawing like D3D8''s transformed vertex that doesn''t go through the modelview and projection and whose coordinates are based on screen. I know there is extension of WindowPos in OpenGL which can assign current raster position to window coordinate system. It is convenient to draw image to window but I still want draw lines and texts above the image, then to specify the coordinates where I want to draw is a little annoying. How do you draw 2D things such as 2D lines to window???
Advertisement
Use gluOrtho2D() (or glOrtho for more control) and define the coordinate min/max you want to use, and use the model view matrix for x/y translations/rotations if you want, or just set it to the identity and calculate the positions yourself..
will opengl 2.0 implement transformed and lited vertex format?
I think it is very convenient to draw 2D primitives and some time 3D primitives needn''t to be transformed. Hope this feature will be added since there is WindowPos extension already.
check the faq (www.opengl.org)
set it to orthomode with loadidentity its the fastest way

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
Push all the matrices and set Orthographic mode before any 2D drawing then restore the matrices when you have finished.

then use glVertex2i(int X, int Y) to specify 2D coordinates in pixels.

Example:

void Begin2D()
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,WindowWidth,0,WindowHeight,1,-1);
}

void End2D()
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}

void DrawFrame()
{
//3d stuff
Begin2D();
// 2d stuff
End2D();
// more 3d stuff
Begin2D();
//more 2d stuff
End2D();
}

This topic is closed to new replies.

Advertisement