• Advertisement
Sign in to follow this  

lighting affecting raster colour

This topic is 4228 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi im just a n00b programmer now but i have one quick question about why when i draw a character, and colour it using glColor3f() does that not stay permenent when i add lighting to the character. if the character is a redish color, and the light is white, then how would i create make, it so that the character does not end up only bieng greyscale?

Share this post


Link to post
Share on other sites
Advertisement
You need to specify materials and/or textures to change the color of a lit object in OpenGL...glColor won't do it (unless you use glColorMaterial, which I have never tried, but might work for you). glColor just specifies the color of a vertex, but lighting is more complicated than that. Check out the glMaterial calls.
http://www.mevis.de/opengl/glMaterial.html
Basically, you specify the diffuse material, ambient material, etc. Most OpenGL lighting examples will do this, so look for one.

Chapter 5 in the RedBook covers lighting. A free older version can be found at http://www.gamedev.net/download/redbook.pdf. You should find an example in there.

Share this post


Link to post
Share on other sites
woops, I mean, you need to specify materials (not "and/or textures")

Share this post


Link to post
Share on other sites
Thank you very much. That works very well, i used glColorMaterial() and the character's colors show. im sorry but i have one more little question, when i initialize all the lighting and materials in the main function the character does not seem to be lit properly, only one shoulder is properly lit, but when i put it in the display function all the lighting works except the same sphere on the shoulder that apears black.

screen shot with lighing in main():
http://img82.imageshack.us/img82/2371/freesnap002hl5.jpg

screen shot with light in display():
http://img291.imageshack.us/my.php?image=freesnap001mp4.jpg

Share this post


Link to post
Share on other sites
Can't think of a reason just from your description. If you post the code, I or someone else might see the issue...

Share this post


Link to post
Share on other sites
this is the function in wich the arms are drawn, i am hoping that this is the place where the error occurs when drawing the arms:





void drawArms()
{

glPushMatrix();
//move to side of the body cylinder
glTranslatef(0.0,-0.02,BODY_RAD+JOINT_RAD);
//first joint in arm
drawJoint;
//glPushAttrib(GL_CURRENT_BIT);
glPushMatrix();
// create arm and angle it using the arm angle
glRotatef(90,1.0,0.0,0.0);
glRotatef(rArmAngle,0.0,(negY==GL_TRUE?-1.0:1.0),0.0);
drawCylinder(ARM_RAD,ARM_LENGTH);
//glScalef(0.1, ARM_RAD, 0.1);
glutSolidSphere(ARM_RAD,10,10);
glPopMatrix();
glPushMatrix();
GLfloat fac=(negX==GL_TRUE?-1:1);
//find position of next joint
GLdouble xLen=(GLfloat) ARM_LENGTH*sin(DEG_TO_RAD(rArmAngle));//*(negX==GL_TRUE?-1:1);
GLdouble yLen=(GLfloat) ARM_LENGTH*cos(DEG_TO_RAD(rArmAngle));
//apply transformation to matiricy
glTranslatef(xLen,yLen*fac,0.0);
drawJoint;
glPushMatrix();
glRotatef(90,0.0,1.0,0.0);
glRotatef(rForearmAngle,1.0,0.0,0.0);
//glRotatef(lForearmAngleZ,0.0,0.0,1.0);
drawCylinder(FOREARM_RAD,FOREARM_LENGTH);
glPopMatrix();
glPopMatrix();
glPopMatrix();
//glPopAttrib();
//reapeat using left arm values
glPushMatrix();
glTranslatef(0.0,-0.02,-BODY_RAD-JOINT_RAD);
drawJoint;
glPopMatrix();
glPushMatrix();
glTranslatef(0.0,-0.02,-BODY_RAD-JOINT_RAD);
glutWireSphere(JOINT_RAD,20,20);
glPushMatrix();
glRotatef(90,1.0,0.0,0.0);
glRotatef(lArmAngle,0.0,1.0,0.0);
drawCylinder(ARM_RAD,ARM_LENGTH);
glPopMatrix();
glPushMatrix();
GLdouble xLenl=(GLfloat) ARM_LENGTH*sin(DEG_TO_RAD(lArmAngle));//*(negX==GL_TRUE?-1:1);
GLdouble yLenl=(GLfloat) ARM_LENGTH*cos(DEG_TO_RAD(lArmAngle));
glTranslatef(xLenl,-yLenl,0.0);
drawJoint;
glPushMatrix();
glRotatef(90,0.0,1.0,0.0);
glRotatef(lForearmAngle,1.0,0.0,0.0);
drawCylinder(FOREARM_RAD,FOREARM_LENGTH);
glPopMatrix();
glPopMatrix();
glPopMatrix();

Share this post


Link to post
Share on other sites
Sorry, but I don't see anything from that code. Are you setting up your normals correctly? I would try to get a simple example working and then go from there. OpenGL can be screwy in that if you mess one thing up it can cause some crazy, undefined results which are hard to track down. Are you checking for gl errors?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement