PDA

View Full Version : 2D Drawing in OpenGL


LongJumper
2003.11.21, 01:43 AM
I want to draw something that isn't 3D at all. I guess I'd like to draw something without any projection, kind of like "in the front" of the screen. So when I draw something with the coordinates -.5,.5 as left corner and 0,0 and the bottom right corner, I'd like it to cover exactly 1/4th the screen, the second quadrant. I also need to do this after I draw some projected stuff.

I'm guessing it would have to do something with setting up another camera orthographically, then pushing the matrix calling the camera render function, and drawing?

FCCovett
2003.11.21, 02:03 AM
Check this out (in Carbon/C):

http://webpages.charter.net/fccovett/MyGameSource.dmg

http://www.idevgames.com/forum/showthread.php?s=&postid=54475#post54475

johnMG
2003.11.21, 09:04 PM
Using glut, I wanted the dimensions of my drawing area to match up with the actual pixels, so I did this:

void my_reshape_func( int w, int h )
{
glViewport( 0, 0, w, h );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0, static_cast<double>( w ),
0.0, static_cast<double>( h ),
-1.0, 1.0 );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

glutPostRedisplay();
}


You'll need to pass something different than w & h to glOrtho() if you don't want (0.0, 0.0) to be the bottom left corner. Enjoy. :)