Advertisement

Silly Color / Lighting Question

Started by January 24, 2003 01:01 PM
8 comments, last by jmschust 22 years, 1 month ago
In my latest little try at opengl I''ve created a texture mapped sphere. I also have some arrows that show the normal, binormal and tangent at vertexes on the sphere. However, my arrows aren''t getting colored. I have really no idea why. I''m using glColor3f, just like I''ve always done, but I can''t ever get the color to be anything but white. I''m thinking it has something to do with my lighting. But I''m lost. (think I''ve been looking at code too long) Anyhow, some advice would be appreciated. Thanks.
glDisable(GL_TEXTURE_2D) before drawing your arrows. the sphere texture is probably getting in the way
Advertisement
Also call glDisable(GL_LIGHTING) before writing your arrows. And please don''t forget to enable it again after, if needed.
Thanks!

But I''ve already tried that (per the lighting and coloring FAQ on the opengl site). Doesn''t work...
I also draw my normals sometimes and haven''t had a problem:

glDisable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
glColor4f(0.0f,1.0f, 0.0f, 1.0f);
glBegin( GL_LINES );


I leave the lighting on....
Could you please post some code
Advertisement
Well my code is all broken up, but here is the drawNormals function. Can you not get it to work by doing those 3 commands? If you want my renderHeightMap function, which calls the drawNormals, I can post it, but its kindof long.


void drawNormals(){ //draw vertex normals
int s=DEL/2;
float mag;
int x=0, y=0, z=0;
int h1,h2,h3,h4;
glEnable(GL_COLOR_MATERIAL);
glColor4f(0.0f,1.0f, 0.0f, 1.0f);
glBegin( GL_LINES );
for ( x = 0; x < MAP_SIZE; x += DEL ){ // 256,4
for ( z = 0; z < MAP_SIZE; z += DEL ) {
if (boolRaw){
h1=terrainRaw[x/DEL][z/DEL];
h2=terrainRaw[x/DEL][z/DEL +1];
h3=terrainRaw[x/DEL +1][z/DEL +1];
h4=terrainRaw[x/DEL +1][z/DEL];
}
if (boolPerlin){
h1=terrainPerlin[x/DEL][z/DEL];
h2=terrainPerlin[x/DEL][z/DEL +1];
h3=terrainPerlin[x/DEL +1][z/DEL +1];
h4=terrainPerlin[x/DEL +1][z/DEL];
}
mag=float (sqrt( s*(h4-h1)*s*(h4-h1)+s*s*s*s+(h2-h1)*(h2-h1)*s*s ));
glNormal3f( s*(h4-h1)/mag, -s*s/mag, (h2-h1)*s/mag);
glVertex3i(x, h1,z);
glVertex3f(x+s*(h4-h1)/mag, h1-s*s/mag,z+(h2-h1)*s/mag);
}
}
glEnd();
glDisable(GL_COLOR_MATERIAL);
}
You don''t need to call glNormal if lighting is disabled.
And if lighting is enabled, I would recommend calling glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) before glEnable(GL_COLOR_MATERIAL).
If you''re using lighting, also you should try calling glEnable(GL_NORMALIZE) even if you normalize the normals yourself (since I see you''re dividing by magnitude)
Oh dear. I though you, Vincoof were the original poster asking me to clarify what I told the OP. Yes, I have lighting enabled and thank you very much for the tips! I will look into them (I am very new at opengl) But umm... I''m not the OP, sorry about that, so he still has his problems getting the normals colored (which I don''t...
lol. this code looked so good that I wasn''t sure about what was wrong. It''s much clear now !

This topic is closed to new replies.

Advertisement