🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lighting and Colors

Started by
3 comments, last by sam_carmichael 18 years, 4 months ago
I am a bit confused , so please someone help me. Can i use glColor , when Lighting is calculated, cause i have an impression when i am turning on the lighting, colors doesnt work. For colors to work i have to turn on COLOR_MATERIAL , but then the lighting isnt calculated. Am i doing something wrong or these are the rules?
Advertisement
Well, using both glColor and lighting at the same time doesn't make sense. You want to set the color yourself, but you also want OpenGL to calculate the color using the lighing equation?

When lighting is enabled, the primary color is calculated from the lighting equation and glColor is ignored, and the only thing you can do to affect the color is to set material and lighting properties. Enabling GL_COLOR_MATERIAL just makes OpenGL copy the glColor to some material properties, but in the end, it's just a short for calling glMaterial and you can't explicitely set the color yourself.
Actually, you can have OpenGL affect your per-vertex color with the lighting color, thereby allowing both. I'm a D3D guy though, I don't remember how :)
Thx for replies, i've got the picture:)
You can create your own little lighting too. As you're drawing your model and using glColor3f for the vertices, calculate the distance (sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)) to the "light" or object you want to be like a light, inverse that and multiply it by pi minus the angle between the normal of the vertex and the vector between the object and "light" (3.14-acos((vecdot(v1,v2))/abs(vecsize(v1)*vecsize(v2))) and then apply your own color effects in the formula and you have a cheap lighting system.

[Edited by - sam_carmichael on February 28, 2006 3:17:47 AM]

This topic is closed to new replies.

Advertisement