Basic Lighting for CAD

Hi,

I apologize if this question has been ask before, but I haven’t had much luck googling around. I’m building a little solid modeller and am looking for a basic lighting configuration to provide a reasonable view of surface features. I don’t want to do anything fancy; I just want to be able change an object’s color and get decent shading.

When I follow the guidelines from “How lighting works”, I’m left with a scene that is mostly black and white (the sphere in the picture should be blue):

Here are the lighting commands I call during program init. I’m using Haskell with its opengl binding. The syntax may look weird, but hopefully the underlying opengl calls can be recognised:

position (Light 0) = Vertex4 1 1 0 1 ambient (Light 1) = Color4 0 0 0 1
diffuse (Light 1) = Color4 1 1 1 1 specular (Light 1) = Color4 1 1 1 1
lightModelAmbient = Color4 0.2 0.2 0.2 1 lighting = Enabled
light (Light 0) = Enabled colorMaterial = Just (FrontAndBack, AmbientAndDiffuse)
materialSpecular FrontAndBack = Color4 1 1 1 1 materialEmission FrontAndBack = Color4 0 0 0 1

Any idea what I’m doing wrong? Also, should I be calling any lighting specific stuff during frame redraws, or just at initialization? And what happens if a disable and re-enable lighting? Do I need to reset all the lighting parameters?

Thanks for any help!

-Tom

A minor typo. The ambient, diffuse, and specular settings should read:

ambient (Light 0) $= Color4 0 0 0 1
diffuse (Light 0) $= Color4 1 1 1 1
specular (Light 0) $= Color4 1 1 1 1

BTW, the image should look rather blocky. It’s a ball made from legos.

I’ve never seen that language before, but I had the same problem in C. Adding this line solved the problem: glEnable(GL_COLOR_MATERIAL);

I would guess that you need to add this line:
colorMaterial $= Enabled

Check your normals. Watch out for scaling, or try the glEnable(GL_NORMALIZE); (from memory).

Thanks. glEnable(GL_NORMALIZE) helped a little. What helped more was setting specular to all 0s. Is this expected?

Depends on your material GL_SHININESS parameter, default is problably very low (rough), should be at least 30 or 80 to “look shiny”. best seen on curved surfaces, or at least in movement for flat shading like yours.