OpenGL Ambient Light grays out my models

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
superLED
Chaos Rift Junior
Chaos Rift Junior
Posts: 303
Joined: Sun Nov 21, 2010 10:56 am
Current Project: Engine
Favorite Gaming Platforms: N64
Programming Language of Choice: C++, PHP
Location: Norway

OpenGL Ambient Light grays out my models

Post by superLED »

Hello again.

I've tried to move forward to 3D programming, and I kinda understand the basic of OpenGL. But I seem to have problem with the lightning...
In my project, there is a 'object loader' function, which loads up a .obj file that I can render to my scene. It looks nice and all, but the parts where there is no light, there is completely black.
I have set the ambient light to 0.3, 0.3, 0.3 (and I've tried different numbers), but when I do this, the black just turn gray.
(When I load in the object, I don't read in the ambient light from the .obj/.mtl file)

What I want, is that the colors is still visible - just darker - when there is no light.

Is this the default way OpenGL handles ambient light, or do I do something wrong?
And is there a way I can make it 'not gray out' with ambient light?

Let me know if you need some code to read.

1: No light reaches this side of the face
2: Light on the object, but with amibent light as well, so it still somewhat grayed out.
3: With ambient light turned Off.
Image
User avatar
szdarkhack
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 61
Joined: Fri May 08, 2009 2:31 am

Re: OpenGL Ambient Light grays out my models

Post by szdarkhack »

Check this link and see if you do everything it says, especially setting the material color correctly: http://www.sjbaker.org/steve/omniv/opengl_lighting.html

If you cannot figure it out still, post some of the light setup and the rendering code. By the way, the old built in opengl lighting is horrible, you should consider writing a simple shader instead. Don't worry, opengl 2.0 is 8 years old, nobody will have compatibility issues ;)

EDIT: Here, i fixed it :)
Last edited by szdarkhack on Sat Feb 04, 2012 7:12 am, edited 1 time in total.
User avatar
Nokurn
Chaos Rift Regular
Chaos Rift Regular
Posts: 164
Joined: Mon Jan 31, 2011 12:08 pm
Favorite Gaming Platforms: PC, SNES, Dreamcast, PS2, N64
Programming Language of Choice: Proper C++
Location: Southern California
Contact:

Re: OpenGL Ambient Light grays out my models

Post by Nokurn »

szdarkhack wrote:Check this link and see if you do everything it says, especially setting the material color correctly: http://www.sjbaker.org/steve/omniv/opengl_lighting.html

If you cannot figure it out still, post some of the light setup and the rendering code. By the way, the old built in opengl lighting is horrible, you should consider writing a simple shader instead. Don't worry, opengl 2.0 is 15 years old, nobody will have compatibility issues ;)
Actually, OpenGL 2.0 is only 8 years old. Though I agree; unless you're specifically trying to maintain compatibility with ancient systems, go with shaders. It is possible to make a good looking game without the use of shaders (see Torchlight), but it's usually not worth the hassle, especially nowadays.
User avatar
superLED
Chaos Rift Junior
Chaos Rift Junior
Posts: 303
Joined: Sun Nov 21, 2010 10:56 am
Current Project: Engine
Favorite Gaming Platforms: N64
Programming Language of Choice: C++, PHP
Location: Norway

Re: OpenGL Ambient Light grays out my models

Post by superLED »

Thanks for the replies!
I have been reading a little bit about shaders, and I find it quite interesting. Tried to look through some tutorials, but I didn't understand much x) It may be that I didn't find the right tutorials
Do any of you have some links to tutorials/guides that are easy to follow for a starter?

In the meantime, I will check the link to see if I've done something wrong.
If that won't help, I may just put a dim light source at the cameras position, so the light will always hit whatever i'm looking at.
Post Reply