PDA

View Full Version : OpenGL problem



08-18-2003, 06:51 AM
Could someone please help me with the following problem I have with my OpenGL code.

I've drawn a object in 3D space. 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

Robert

jcabeleira
08-18-2003, 07:12 AM
if you just want to change your object's color then you should use glColor3b.

08-18-2003, 07:52 AM
Thanks for replying. But I can't use glColor3b when I use a lightsource in my program. Is there someway I could assign a color to an object using RGB values when I have a lightsource in the scene?

cfmdobbie
08-18-2003, 08:10 AM
Take a look at glColorMaterial - it may do the trick for you.

yaro_dup1
08-18-2003, 08:56 AM
glEnable( GL_COLOR_MATERIAL );