Jump to content


Please Help


2 replies to this topic

#1 rob1980

    New Member

  • Members
  • Pip
  • 1 posts

Posted 18 August 2003 - 04:21 PM

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

Robert

#2 anubis

    Senior Member

  • Members
  • PipPipPipPip
  • 2225 posts

Posted 18 August 2003 - 06:33 PM

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
If Prolog is the answer, what is the question ?

#3 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 19 August 2003 - 07:06 PM

try enabling GL_COLOR_MATERIAL.
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users