PDA

View Full Version : problem with 2d opengl



Julio
06-22-2001, 03:37 AM
I'm attempting to small 2d game in OpenGL just for the hell of it. my code to set up the 2d view is :
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f,640.0f,480.0f,0.0f,-1.0f,1.0f);
glMatrixMode(GL_MODELVIEW);
This is supposed to make my screen coordinates the same as my screen height and width, (640x480) But if I translate to 10,10,-2 nothing appears on the screen. Can anybody give me some direction on what to do?
Thanks,
Joe

j
06-22-2001, 05:32 AM
Do you have culling enabled? Because you are flipping the image vertically with the projection matrix, face winding is reversed. Try glCullFace(GL_FRONT) OR glFrontFace(GL_CW).

j

06-22-2001, 06:20 AM
I think your glOrtho parameters are out of order. I am doing the exact same thing as you heres my code:

glViewport(0, 0, w, h);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0, (float)w, 0.0, (float)h, 0.0f, 10.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

06-22-2001, 06:22 AM
Second last parameter in my glOrtho call should be -10.0f

Boresight
06-22-2001, 06:31 AM
Well, (10,10,-2) is out of visualization cube given by
glOrtho(0.0f,640.0f,480.0f,0.0f,-1.0f,1.0f);
so that coordenates are clipping.

Change z clipping planes to the maximun amd minimun coordenates that you need to be displayed. By example:

glOrtho(0.0f,640.0f,480.0f,0.0f,-maxZ,maxZ);

Julio
06-22-2001, 08:15 AM
j,
I don't have any culling enabled
Jackson Harper,
You're right, I just check the parameters. Will fix it when I get home. thanks.
Boresight,
I wasn't exactly sure about those parameters. thanks for clearing that up for me. that helps out a lot.
thanks for the help guys,
Joe