-
problem with 2d opengl
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
-
Member
Regular Contributor
Re: problem with 2d opengl
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
-
Re: problem with 2d opengl
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();
-
Re: problem with 2d opengl
Second last parameter in my glOrtho call should be -10.0f
-
Re: problem with 2d opengl
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);
-
Re: problem with 2d opengl
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules