glRotate and glTranslate are messing up my lighting?!?
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...
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)
Any ideas? I'm stumped.
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.
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...
After reading through various chapters, I can't find it, do you have an idea of what chapter to look in?
Chapter 5 "Lighting"; "Controlling a Light's Position and Direction"; page 191 in my copy...
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!
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
OpenGL: glRotate and some 3D questions. | mikey | 1 | 5,202 |
May 19, 2009 05:11 PM Last Post: ThemsAllTook |
|
Frame buffer objects seem to be messing with my computer | Jar445 | 2 | 5,300 |
Feb 24, 2009 08:59 AM Last Post: Jar445 |
|
Messing with HID | LWStrike | 2 | 3,752 |
Mar 30, 2006 12:35 AM Last Post: LWStrike |
|
To glTranslate, or not to glTranslate | Nick | 11 | 7,724 |
Mar 25, 2005 08:56 AM Last Post: tigakub |
|
glRotate,glTranslate problems | PowerMacX | 4 | 5,150 |
Jan 19, 2004 12:03 AM Last Post: kelvin |