PDA

View Full Version : Turning on lighting renders scene in greyscale!



klempie
10-18-2008, 03:27 PM
Yeh it's a bit of a weird one. I must be doing something dumb.

I started off the program by rendering my scene as a mesh using GL_LINE_STRIP in green to get a feel for the contours and it all looked great. I then switched to GL_TRIANGLE_STRIP in preparation for shading and obviously with that I get one massive green blob.

I then moved on to calculating normals and finally defining my light sources and then switching on the lights. The lights are defined as

GLfloat ambient[] = {0.5,0.5,0.5,1.0};
GLfloat diffuse[] = {0.8,0.8,0.8,1.0};
GLfloat lightpos1[] = {-40.0,100.0,-10.0,1.0};
GLfloat lightpos2[] = {40.0,100.0,80.0,1.0};
What's weird is that it the shading all works nicely and it fills all the polygons as they should be, but in greyscale! It's like my specification to draw the polygons in green is completely ignored. As soon as I turn off the lights, then it draws in green again but with no shading, which is obviously pointless! TIA for any help.

_NK47
10-18-2008, 03:33 PM
you need to specify green color in material properties.
sounds like you don't set any material attributes.

ZbuffeR
10-18-2008, 03:39 PM
or simply use glEnable(GL_COLOR_MATERIAL);

klempie
10-18-2008, 03:53 PM
Thanks for the replies guys.

OK I tried enabling COLOR_MATERIAL but now it draws in green with no shading even though lighting is on.

ZbuffeR
10-18-2008, 03:59 PM
strange. probably a bug in your code.
beware of the value of ambient light, it should be kept black.

klempie
10-18-2008, 04:08 PM
Thanks dude. You were right. It was the black. But I set it what most of the examples have had it as. Like 0.5ish across the RGBs. Anyway, set them to zero and it I can see the green now. Thanks man.

klempie
10-18-2008, 04:09 PM
How do I indicate this thread is resolved?

_NK47
10-20-2008, 01:41 AM
write how you fixed the problem and post the correct code.