iDevGames Forums
glRotate and glTranslate are messing up my lighting?!? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: glRotate and glTranslate are messing up my lighting?!? (/thread-6684.html)



glRotate and glTranslate are messing up my lighting?!? - Jake - Oct 14, 2003 04:43 PM

I am trying to add a nice little scoreboard with your club info and hole to my game, so I decided to first blend a quad (90% opaque, just enough so you can see the terrain behind it), and the write some text. It turns out because I am blending, I need to draw the frame before I add the quad, so, what I am trying to do is just reverse my translate and rotate statements , so I can position the quad in front of all the polygons. Now everything is working just fine, the quad is in the correct part of the screen, with the correct texture, BUT the lighting is all screwed up (when I look out, its REALLY dark, when I look down its 100% bright). I am really confused, I pinpointed it to these lines...

Code:
glTranslatef( -cx, -cy, -cz );
   glRotatef(-yrot,0.0f,1.0f,0.0f);
   glRotatef(-xrot,1.0f,0.0f,0.0f);


If I comment those out, it works, if I leave them in, it screws up. Heres the rest of the relevant code in my drawRect method ( I deleted my own game code, and just left the drawling code)

Code:
- (void) drawRect:(NSRect)rect
{
    glClear( GL_DEPTH_BUFFER_BIT );
   glLoadIdentity();   // Reset the current modelview matrix
  
   glTranslatef(0.0f,0.0f,-4.0f);
   glBindTexture( GL_TEXTURE_2D, 0);
   glColor3f( 1.0f,0.2f,0.1f );
   glDisable( GL_LIGHTING );
   glRasterPos2f( 0 , 0 );
//   buffer = [clubs[currentClub].name cString];
   [ self glPrint:@"Active OpenGL Text With NeHe - "];
   glEnable( GL_LIGHTING );
  
   glRotatef(xrot,1.0f,0.0f,0.0f);
   glRotatef(yrot,0.0f,1.0f,0.0f);
   glTranslatef( cx, cy, cz );
  
        [golfer render: -time3 x: -clubx-3 y: -(cluby+0.18) z: -clubz xr: 0.0 yr: -yrot zr: zrot ];
        
   [currentLevel renderLevel];
      
   glTranslatef( -cx, -cy, -cz );
   glRotatef(-yrot,0.0f,1.0f,0.0f);
   glRotatef(-xrot,1.0f,0.0f,0.0f);

   [ [ self openGLContext ] flushBuffer ];

}


Any ideas? I'm stumped.


glRotate and glTranslate are messing up my lighting?!? - OneSadCookie - Oct 14, 2003 04:58 PM

Read the red book... it has a good little section on what order you need to do lighting and transformation calls in to get the expected result...


glRotate and glTranslate are messing up my lighting?!? - Jake - Oct 15, 2003 06:01 PM

After reading through various chapters, I can't find it, do you have an idea of what chapter to look in?


glRotate and glTranslate are messing up my lighting?!? - OneSadCookie - Oct 15, 2003 06:58 PM

Chapter 5 "Lighting"; "Controlling a Light's Position and Direction"; page 191 in my copy...


glRotate and glTranslate are messing up my lighting?!? - Jake - Oct 16, 2003 03:45 PM

Ok, I see, I thought lights were constant, but it turns out they rotate with other polygons. MY light was out of position. Thanks for the help!


glRotate and glTranslate are messing up my lighting?!? - MacFiend - Oct 17, 2003 01:08 PM

glPushAttrib() and glPopAttrib() is your friend.