Jump to content
  • Advertisement

Archived

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

LeLe

Open GL for 2D Drawing

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

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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!