# Unexpected results for projection on to plane [closed]

I want to use this projection matrix:

``````GLfloat shadow[] = {
-1,0,0,0,
1,0,-1,1,
0,0,-1,0,
0,0,0,-1 };
``````

It should cast object shadows onto the y = 0 plane from a point light at 1,1,-1.

I create a rectangle in the x = 0.5 plane

``````    glBegin( GL_QUADS );
glVertex3f( 0.5,0.2,-0.5);
glVertex3f( 0.5,0.2,-1.5);
glVertex3f( 0.5,0.5,-1.5);
glVertex3f( 0.5,0.5,-0.5);
glEnd();
``````

Now if I manually multiply these vertices with the matrix, I get.

``````    glBegin( GL_QUADS );
glVertex3f( 0.375,0,-0.375);
glVertex3f( 0.375,0,-1.625);
glVertex3f( 0,0,-2);
glVertex3f( 0,0,0);
glEnd();
``````

Which produces a reasonable display ( camera at 0,5,0 looking down y axis )

So rather than do the calculation manually, I should be able to use the opengl model transormation. I write this code:

``````    glMatrixMode (GL_MODELVIEW);
GLfloat shadow[] = {
-1,0,0,0,
1,0,-1,1,
0,0,-1,0,
0,0,0,-1 };
glVertex3f( 0.5,0.2,-0.5);
glVertex3f( 0.5,0.2,-1.5);
glVertex3f( 0.5,0.5,-1.5);
glVertex3f( 0.5,0.5,-0.5);
glEnd();
``````

But this produces a blank screen!

What am I doing wrong?

Is there some debug mode where I can print out the transformed vertices, so I can see where they are ending up?

Note: People have suggested that using glMultMatrixf() might make a difference. It doesn't. Replacing

``````glLoadMatrixf( shadow );
``````

with

``````     glLoadIdentity();
``````

gives the identical result ( of course! )

-
You are using deprecated OpenGL functionality. Try switching to an updated pipeline. Better sooner than later... – Eric B Nov 27 '12 at 19:26
I suspect the problem is with your projection matrix then. What is it at the time that this code is executed? – Eric B Nov 27 '12 at 20:17
Also you are drawing the shape clockwise, which probably means you are looking at the back face, although you obviously are not culling it in your first example. – Eric B Nov 27 '12 at 20:19
I tried specifying the vertices in the opposite order: same result. – ravenspoint Nov 27 '12 at 20:39
-1 for being a "debug my code for me" question. This question will never be relevant to another user, so archiving it forever provides no benefit to the internet. This is really the sort of question that should be raised in chat, on a forum, or some other transient communications medium, rather than in this permanent Q&A archive. – Trevor Powell Nov 28 '12 at 8:55
show 2 more comments

## closed as too localized by Trevor Powell, Byte56, Josh Petrie, bummzack, Sean MiddleditchDec 28 '12 at 7:04

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

`glLoadMatrix` replaces the current matrix, so it is not equivalent to your manual multiplication if the current modelview matrix was not the identity. If that may be the problem, try `glMultMatrix` instead (and a surrounding push/pop if needed).