![]() |
|
[OpenGL] Lighting causes all colours to go grey |
Archon
Member #4,195
January 2004
![]() |
I've got two games using this same 'framework' which is just a shared object file that I'm putting common OpenGL functionality in. Anyway, I'm trying to set up a good lighting system here: //Gl is a namespace BTW Gl.glEnable(Gl.GL_LIGHT0); Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, new float[] { 1.0f, 1.0f, 1.0f, 1.0f }); Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, new float[] { 1.0f, 1.0f, 1.0f }); Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_AMBIENT, new float[] { 0.5f, 0.5f, 0.5f, 0.0f }); Gl.glLightModelfv(Gl.GL_LIGHT_MODEL_AMBIENT, new float[] { 0.5f, 0.5f, 0.5f, 0.0f }); Both games have virtually identical classes|objects at the start of the game (introduction and main menu, etc) but in one game, the texture and all of the glColor3f seems to be overridden because all of the colours are greyish - but the other game is fine. Firstly, is there any basic attributes that I'm misconfiguring or not configuring in the code above? Secondly, what could override all of the glColor functions to produce all-grey results? |
Mr. Big
Member #6,196
September 2005
|
Well, if I remember correctly, what overrides the 'glColor' calls is the fact that you're using lighting. |
Archon
Member #4,195
January 2004
![]() |
Quote:
Well, if I remember correctly, what overrides the 'glColor' calls is the fact that you're using lighting. Nah, light simply affects the colours but it doesn't make everything the colour of the nearest light or anything. If you project a green light on a green object, that object would look fine but if you project the same light on a purely red object, it should turn black - this is assuming that you're using diffuse lighting though. But that's the general idea. Quote: You need to set up the colors using 'glMaterial', which you are setting to gray in your code... Are you certain? If I set glMaterial to 0,0,0 , wont I get black? And if I set it to 1,1,1 wont I get white in that case? Which parameter(s) should I be configuring? What does get me the most is that it does fine with the other game, which has almost the same code up until past the main menu... |
X-G
Member #856
December 2000
![]() |
He said it right. If lighting is enabled, glColor does nothing. Instead, use glMaterial to modify the diffuse parameter. It does the same thing. -- |
Archon
Member #4,195
January 2004
![]() |
Ah yes, now I understand. slaps forehead quite hard I just realised that the texture is actually grey in colour and that the colours came from the glColor parameter - I was hoping of animating the title a little, and the menu selection is just a change in the glColor parameters. But it's good to know that glMaterial would fix this up. |
Bob
Free Market Evangelist
September 2000
![]() |
You can also enable GL_COLOR_MATERIAL, which takes the material color out of glColor. -- |
X-G
Member #856
December 2000
![]() |
But that way he won't learn anything... ;_; -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
He just did learn something. Two somethings in fact. glColor is ignored by default for lighting, and GL_COLOR_MATERIAL will enable using the regular colors again for lighting.... -- |
X-G
Member #856
December 2000
![]() |
Yes, but the right way to deal with lighting is to learn to use the material properties, not to hack around it with GL_COLOR_MATERIAL. -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
If all you want is a colored light, just use colors -- |
Archon
Member #4,195
January 2004
![]() |
Quote: He just did learn something. Yes! I are smart! |
23yrold3yrold
Member #1,134
March 2001
![]() |
I had been wondering this myself, actually. It was very annoying behavior. -- |
Tobias Dammers
Member #2,604
August 2002
![]() |
Quote: Yes, but the right way to deal with lighting is to learn to use the material properties, not to hack around it with GL_COLOR_MATERIAL.
Not necessarily. --- |
|