Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 )

enter image description here

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 };
    glLoadMatrixf( shadow );
    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();

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();
     glMultMatrixf( shadow );

gives the identical result ( of course! )

share|improve this question
3  
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  
-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 Middleditch Dec 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.

1 Answer

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).

share|improve this answer
You are the second person to suggest this. It makes no difference. I will edit my question to cover this issue. – ravenspoint Nov 27 '12 at 20:56
1  
@ravenspoint You should leave out the glLoadIdentity(). – msell Nov 28 '12 at 6:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.