Skip to main content
gamedev.net
🔒 Locked

question:color problem

Started by frankyliao 4 replies 500+ views
Original Post
frankyliao
frankyliao
I have used glColor3f() to define a kind of color when drawing a face in openGL , but the function didn't affect the face. However, I can use glMaterialfv() to affect the color. Why? Thank you first
ff8
ff8
i think because you enabled the light by using glEnable(GL_LIGHTING);
frankyliao
frankyliao
yes!
thank you very much.
But how can I draw a red line in white background if I can't use glColor3f();
ff8
ff8
you can coloring the object by using glMaterialfv() by changing the color light like this code:
   float c1[]={0.0, 0.0, 0.0, 1.0};    float c2[]={1.0, 1.0, 1.0, 1.};     glEnable(GL_COLOR_MATERIAL);    glMaterialfv(GL_FRONT, GL_AMBIENT, c1);    glMaterialfv(GL_FRONT, GL_SPECULAR, c2);    glMaterialfv(GL_FRONT, GL_EMISSION, c1);    glColorMaterial(GL_FRONT, GL_DIFFUSE);    drawobject();

Kalidor
Kalidor
Or just disable lighting when you don't need it, which is what you want if you just want to draw a red line on a white background. It will also be faster since it doesn't have to calculate all the lighting equations (although in this case it most likely won't be noticable).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.