# Projection matrix problems?

This topic is 4168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've finally moved past the initialization/main-menu portion of my game code, but I'm having some odd problems with the projection matrix. Specifically, nothing shows up on screen. Ortho rendering works fine with the exact same rendering code. I'm fairly certain the problem lies with my initialization, but I'm not sure where. Here's the pertinent section of my set-up code:
Gl.glViewport(0, 0, this.ClientSize.Width, this.ClientSize.Height);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Glu.gluPerspective(60, this.ClientSize.Width / (double)this.ClientSize.Height, 1.0f, 1000.0f);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glDisable(Gl.GL_TEXTURE_2D);
Gl.glDisable(Gl.GL_LIGHTING);
Gl.glDisable(Gl.GL_BLEND);


In case you hadn't noticed, this is in C# (using the Tao framework), but I'm sure the concept is the same. Here's my rendering code:
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glTranslatef(0.0f, 0.0f, -7.0f);
Gl.glColor3f(1.0f, 0.0f, 0.0f);
Gl.glBegin(Gl.GL_TRIANGLES);
Gl.glVertex3f(0.0f, 1.0f, 0.0f);
Gl.glVertex3f(1.0f, -1.0f, 0.0f);
Gl.glVertex3f(-1.0f, -1.0f, 0.0f);
Gl.glEnd();


Like I said, this gives me a nice triangle if I push my matrices and use glOrtho(). Any ideas on what I'm doing wrong here?

##### Share on other sites
Sorry for asking the obvious, but are you sure you’re swapping the buffers with this routine?

I don’t know anything about ‘Tao’, but I’ve had similar problems in the past. All were due to my silly errors with lighting, setting the perspective, or forgetting to swap buffers (especially when not using windows API).

Just sharing my opinion, not that i think it will help you :)

##### Share on other sites
Thanks for the reply. Yeah, I'm definitely swapping buffers correctly :)

I'm pretty sure the problem lies directly with my projection matrix due to everything working with a orthographic projection matrix.

Tao, for those who are curious, is basically a set of bindings for Opengl functionality. It's nearly identical to your "normal" Opengl windows API, even to the point of window creation.

##### Share on other sites
Do you have culling enabled (glEnable(GL_CULL_FACE))?

If you do, I think the problem is that you are defining the vertices of your triangle in clockwise order. OpenGL, by default, defines front facing polygons as counter-clockwise. From the camera's viewpoint, you would be seeing the back of the triangle, and with default culling enabled, OpenGL would not render it.

If you flip the last two vertices, like so:

Gl.glVertex3f(0.0f, 1.0f, 0.0f);Gl.glVertex3f(-1.0f, -1.0f, 0.0f);Gl.glVertex3f(1.0f, -1.0f, 0.0f);

I think it will work.

##### Share on other sites
Yup, you're definitely right about my vertex order. I'm curious though, does backface culling not occur in ortho mode?

Strangely enough, I still get nothing after changing the order. I've been experimenting with my code, and I've got it working by calling gluPerspective on the projection matrix every frame. I suppose I have some rogue piece of code screwing that matrix up somewhere...

Edit:
Turns out my menu code wasn't returning after it tries to enter "game" rendering mode, which was apparently messing up my projection matrix (not quite sure how, but I don't really care). So yes, the problem is solved. Thank you for your help everyone, it looks like once again the problem was simply my own careless mistake!

1. 1
2. 2
JoeJ
20
3. 3
frob
16
4. 4
5. 5

• 10
• 10
• 11
• 13
• 9
• ### Forum Statistics

• Total Topics
632196
• Total Posts
3004718

×