about the color

hi,
i have tried this function,but the problem comes. it can’t render the color ,always
be the clour like a little yellow. i habe used glColor(,) but it doesn’t work

can you tell me where r the problems?

glPushAttrib(GL_CURRENT_BIT);
glPushMatrix();

glColor4f(1,1,1,1);
glBegin(GL_TRIANGLES);

glVertex3f(-2.7009000778198242,-3.8376998901367187,40.38330078125);
glVertex3f(1.3549000024795532,-4.5664000511169434,40.221298217773438);
glVertex3f(-1.6440000534057617,-4.8530998229980469,36.528598785400391);
//face number 2
glVertex3f(1.3549000024795532,-4.5664000511169434,40.221298217773438);
glVertex3f(4.8797001838684082,-6.7066001892089844,40.185901641845703);
glVertex3f(2.4974000453948975,-6.257199764251709,36.349498748779297);
//face number 3
glVertex3f(1.3549000024795532,-4.5664000511169434,40.221298217773438);
glVertex3f(2.4974000453948975,-6.257199764251709,36.349498748779297);
glVertex3f(-1.6440000534057617,-4.8530998229980469,36.528598785400391);
//face number 4
glVertex3f(-1.6440000534057617,-4.8530998229980469,36.528598785400391);
glVertex3f(2.4974000453948975,-6.257199764251709,36.349498748779297);
glVertex3f(-0.71420001983642578,-7.2413997650146484,33.297901153564453);
//face number 5





lVertex3f(-13.012399673461914,-16.798799514770508,44.657001495361328);
glVertex3f(-13.135199546813965,-16.976600646972656,44.394401550292969);
glVertex3f(-13.088800430297852,-16.942699432373047,44.426498413085937);
glEnd();

glPopMatrix();
	      
	  
glPopAttrib();

This is how your render procedure would look if you just wanted to draw this shape:

void render(){

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

glColor(1.0f,1.0f,1.0f,1.0f);

glPushMatrix();
glBegin();



glEnd();
glPopMatrix();

}

I don’t think you need the glPushAttrib(…). Plus if you are getting a whitish color that is write. Try replacing glColor4f(1.0f,1.0f,1.0f,1.0f) with glColor4f(0.0f,0.0f,0.0f,0.0f). The second glColor4f(…) in the last statement is for you to set the color to black.

  • Halcyon

Have you enable lighting?
Have you enable color matrial?

Each can effect how the color on your object looks.

glColor4f( r, g, b, alpha); not sure at this point you need the alpha.

r = red level
g = green level
b = blue level

glColor3f( 1.0, 1.0, 1.0) = white
glColor3f( 1.0, 1.0, 0.0) = yellow
glColor3f( 1.0, 0.0, 0.0) = red

Originally posted by iux:
[b]hi,
i have tried this function,but the problem comes. it can’t render the color ,always
be the clour like a little yellow. i habe used glColor(,) but it doesn’t work

can you tell me where r the problems?

glPushAttrib(GL_CURRENT_BIT);
glPushMatrix();

glColor4f(1,1,1,1);
glBegin(GL_TRIANGLES);

glVertex3f(-2.7009000778198242,-3.8376998901367187,40.38330078125);
glVertex3f(1.3549000024795532,-4.5664000511169434,40.221298217773438);
glVertex3f(-1.6440000534057617,-4.8530998229980469,36.528598785400391);
//face number 2
glVertex3f(1.3549000024795532,-4.5664000511169434,40.221298217773438);
glVertex3f(4.8797001838684082,-6.7066001892089844,40.185901641845703);
glVertex3f(2.4974000453948975,-6.257199764251709,36.349498748779297);
//face number 3
glVertex3f(1.3549000024795532,-4.5664000511169434,40.221298217773438);
glVertex3f(2.4974000453948975,-6.257199764251709,36.349498748779297);
glVertex3f(-1.6440000534057617,-4.8530998229980469,36.528598785400391);
//face number 4
glVertex3f(-1.6440000534057617,-4.8530998229980469,36.528598785400391);
glVertex3f(2.4974000453948975,-6.257199764251709,36.349498748779297);
glVertex3f(-0.71420001983642578,-7.2413997650146484,33.297901153564453);
//face number 5




lVertex3f(-13.012399673461914,-16.798799514770508,44.657001495361328);
glVertex3f(-13.135199546813965,-16.976600646972656,44.394401550292969);
glVertex3f(-13.088800430297852,-16.942699432373047,44.426498413085937);
glEnd();

glPopMatrix();
        
    
glPopAttrib();[/b]

i have written the light :

GLfloat LightDiffuse[]= { 1.0f,1.0f, 1.0f, 0.0f };
GLfloat LightAmbient[]= { 0.1f, 0.1f, 0.1f, 0.0f };
GLfloat LightPosition[]= { 0.0f, 0.0f, 0.0f, 1.0f };
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);

but it seems it doesn’t work -_-b

and when i write glColor4f(1,1,1,1);

it’s not true white
a little yellow … :’(

how it comes true?

Also do you have blend function enabled?

Have you set the object matrial settings?

Here is an example:

// Set object color
// Note if you have enabled GL_COLOR_MATERIAL
// You must turn it off befor setting a new color
glDisable(GL_COLOR_MATERIAL);
glColor3f( 0.0, 1.0, 0.0);
glEnable(GL_COLOR_MATERIAL);

// Set object matrial attrib’s
glColorMaterial(GL_FRONT, GL_AMBIENT);
glColor4f(0.65, 0.65, 0.65, 1.0);
glColorMaterial(GL_FRONT, GL_EMISSION);
glColor4f(0.10, 0.10, 1.0, 0.0);
glColorMaterial(GL_FRONT, GL_SPECULAR);
glColor4f(0.5, 0.5, 0.5, 1.0);
glColorMaterial(GL_FRONT, GL_DIFFUSE);
glColor4f(0.85, 0.85, 0.85, 1.0);

// Draw object

Originally posted by iux:
[b]and when i write glColor4f(1,1,1,1);

it’s not true white
a little yellow … :’(

how it comes true?[/b]

[This message has been edited by nexusone (edited 02-05-2003).]

ok ,i have got it ,thx a lot

oh it does not work yet

no light is on the object
here is my cord:

void

drawgeiaugen()
{
glColorMaterial(GL_FRONT, GL_AMBIENT);
glColor4f(0.65, 0.65, 0.65, 1.0);
glColorMaterial(GL_FRONT, GL_EMISSION);
glColor4f(1, 1, 1, 0.0);
glColorMaterial(GL_FRONT, GL_SPECULAR);
glColor4f(0.5, 0.5, 0.5, 1.0);
glColorMaterial(GL_FRONT, GL_DIFFUSE);
glColor4f(0.85, 0.85, 0.85, 1.0);

glDisable(GL_COLOR_MATERIAL);
glColor3f(1,1,1);
glEnable(GL_COLOR_MATERIAL);

glBegin(GL_TRIANGLES);
//face number 1
glVertex3f(0.34689998626708984,2.5978000164031982,0.6632000207901001);
glVertex3f(0.21310000121593475,2.7172000408172607,0.62150001525878906);
glVertex3f(0.1932000070810318,2.6370000839233398,0.63919997215270996);
//face number 2
glVertex3f(0.34689998626708984,2.5978000164031982,0.6632000207901001);
glVertex3f(0.1932000070810318,2.6370000839233398,0.63919997215270996);
glVertex3f(0.2434999942779541,2.5355000495910645,0.6525999903678894);
//face number 3
glVertex3f(0.34689998626708984,2.5978000164031982,0.6632000207901001);
glVertex3f(0.2434999942779541,2.5355000495910645,0.6525999903678894);
glVertex3f(0.340200006

glEnd();
}

main()
{



//glClearColor(.3, .4, .9, 0);
glDisable(GL_LIGHT1);
glClearColor(.5, .5, 1, 1);
GLfloat LightDiffuse[]= { 1.0f,1.0f, 1.0f, 0.0f };
GLfloat LightAmbient[]= { 0.1f, 0.1f, 0.1f, 0.0f };
GLfloat LightPosition[]= { 0.0f, 0.0f, 0.0f, 1.0f };
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);



glPushAttrib(GL_CURRENT_BIT);
glEnable(GL_NORMALIZE);
glPushMatrix();
glScalef(.35,.35,.35);
glTranslatef(0,0,0);

	  drawgeiaugen();
	 
	  glPopMatrix();
	  glPopAttrib();


}

From your code it appears that you have not enabled GL_LIGHTING prior to enabling GL_LIGHT0. Add :

glEnable(GL_LIGHTING);

before

glEnable(GL_LIGHT1);

[This message has been edited by shinpaughp (edited 02-05-2003).]

oh, effect is horrible
all is now the color a littlle yellow ~~~~~

where is the problem :expressionless:

I don’t know why it took so long for me to see… but I just noticed that I don’t see any normals for the vertex in your program, lighting will not be correct without them.

You can go to nehe.gamedev.net and look at the lighting tutor and how to setup your normals.

Originally posted by iux:
[b]oh, effect is horrible
all is now the color a littlle yellow ~~~~~

where is the problem :expressionless:

[/b]

have solved the problem.

its lack of glDisable(GL_TEXTURE_2D)
and after glEnd() a glEnable(GL_TEXTURE_2D)

thx for all your imformation