Please Help

rob1980 101 Aug 18, 2003 at 16:21

Could someone please help me with the following problem:

I’ve drawn a object in 3D space(OpenGL). The object are flat(lies in the Z=0 plane) and I use a distant lightsource ({0.0,0.0,1.0,0.0}).

What I want is to assign a color to the object with RGB values(For instance I want the object to be blue like RGB values 0,94,173). I use the following code to specify the color of the object. (RED, GREEN and BLUE are variables that contains my preferred RGB code)

float diffuse[]={RED/(float)255 ,GREEN/(float)255, BLUE/(float)255, 1.0};
float ambient[]={RED/(float)255 ,GREEN/(float)255, BLUE/(float)255, 1.0};
float specular[]={0.3 ,0.3, 0.3, 1.0};

glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);

But when I execute the program the object does not have the color that I have specified through my RGB values. Moreover, when I scale the object the object changes color. What have I done wrong? And what do I have to do, to be able to specify the color of an object (in 3D space) through its RGB values?

I would greatly appreciate any help


2 Replies

Please log in or register to post a reply.

anubis 101 Aug 18, 2003 at 18:33

what color does it have ???
did you enable GL_LIGHTING ???
to make lighting work you must also supply the normals of the object for each vertex
did you also set the color of the light ??? the material color only specifys the reflectance of the object ?
google for the opengl red book… it should serve you as a reference for all opengl core related stuff
in general you should maybe post a little more code if you have a question because it’s hard to help you if you just say… “here i set the material’s color and it doesn’t work…” if you checked that you got the material function right obviously the problem is somewhere else

baldurk 101 Aug 19, 2003 at 19:06

try enabling GL_COLOR_MATERIAL.