Archived

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

LeLe

Open GL for 2D Drawing

Recommended Posts

LeLe    122
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???

Share this post


Link to post
Share on other sites
OrangyTang    1298
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..

Share this post


Link to post
Share on other sites
LeLe    122
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.

Share this post


Link to post
Share on other sites
zedzeek    529
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

Share this post


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

Share this post


Link to post
Share on other sites