Movable lights...
Hey all.
This is what im trying to do now: I want the stars in my game to be the light sources and so I need to be able to keep the light source at the center of the star no matter where it moves. I'm not sure how to do this though. I've been reading in the red OGL book about how to make movable lights but I guess I just don't quite understand it yet.
Any help?
Thank you in advance.
Quote:Original post by ahlywogHow many stars are there in your game? Be aware that most graphics hardware is limited to 8 lights.
This is what im trying to do now: I want the stars in my game to be the light sources and so I need to be able to keep the light source at the center of the star no matter where it moves.
Quote:I'm not sure how to do this though. I've been reading in the red OGL book about how to make movable lights but I guess I just don't quite understand it yet.
def set_light_pos(light, x, y, z): pos = [x, y, z, 1.0] glLightfv(GL_LIGHT0 + light, GL_POSITION, pos)
Per map there will probably be a couple stars. Only the nearest star will have a light source and the stars will be spaced enough for this not to be an issue.
I understand the setting of the GL_POSITION part. That's easy. It's the setting the light position before applying a view matrix that I don't quite understand.
I understand the setting of the GL_POSITION part. That's easy. It's the setting the light position before applying a view matrix that I don't quite understand.
Quote:Original post by ahlywogActually, I think I just messed you up there - specifying in eye space seems to mean that you do need to have a view matrix setup. Perhaps someone less confused than me should weigh in here...
I understand the setting of the GL_POSITION part. That's easy. It's the setting the light position before applying a view matrix that I don't quite understand.
Presumably, you call glLoadIdentity() right after you clear the color/depth buffer, and then at some time later you setup a view matrix (either with gluLookAt, or you own matrix math). If this is the case, you should be able set your light positions right after setting the view matrix (before doing any other matrix operations to render objects).
The other (perhaps simpler) method is to setup your view matrix as normal, glTranlatef() to the light position, and set the light position to [0,0,0,1].
Light positions are specified in object space just like for vertices. They are multiplied by the modelview matrix, just like vertices.
Whatever transform you have applied to your object will apply to the light as well but you must call glLight.
glTranslatef(x, y, z);
glLightfv(GL_LIGHT0, GL_POSITION, pos);
DrawMyObject1();
glRotatef(x, y, z);
glLightfv(GL_LIGHT1, GL_POSITION, pos);
DrawMyObject2();
//and now render all other objects that will receive the lighting
glEnable(GL_LIGHTING);
DrawOther();
glDisable(GL_LIGHTING);
Whatever transform you have applied to your object will apply to the light as well but you must call glLight.
glTranslatef(x, y, z);
glLightfv(GL_LIGHT0, GL_POSITION, pos);
DrawMyObject1();
glRotatef(x, y, z);
glLightfv(GL_LIGHT1, GL_POSITION, pos);
DrawMyObject2();
//and now render all other objects that will receive the lighting
glEnable(GL_LIGHTING);
DrawOther();
glDisable(GL_LIGHTING);
See that's what I've been trying to do. Unless I'm doing it wrong. I set the X,Y,Z of the light to that of the star.
http://s298.photobucket.com/albums/mm265/ahlywog/?action=view¤t=lighting.png
As I said before the light is set to the X/Y/Z of the star (the big yellow thing.) But, clearly, it's not working properly as the light is showing up from a source below the objects.
http://s298.photobucket.com/albums/mm265/ahlywog/?action=view¤t=lighting.png
As I said before the light is set to the X/Y/Z of the star (the big yellow thing.) But, clearly, it's not working properly as the light is showing up from a source below the objects.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement