lights and colors

Started by
2 comments, last by Schmiid 18 years, 10 months ago
Hello, I have a problem with light and colors in openGl. I just want to experiment with some material attributes. So I do not want to define Colors with glColor3f, but I want to use the reflexion of the material and the color of the light for coloring my objects. my Code looks like this: first I programm a diffuse/ambient light glLightf(GL_LIGHT0,GL_AMBIENT,(1.0f , 1.0f , 1.0f , 1.0f )); glLightf(GL_LIGHT0,GL_DIFFUSE,(0.8f , 0.8f , 0.8f , 1.0f )); glEnable( GL_LIGHT0); glEnable( GL_LIGHTING); then I draw a Quad with material attributes glBegin(GL_QUADS); glMaterialf(GL_FRONT,GL_AMBIENT_AND_DIFF USE,(1.0f ,0.0f ,0.0f )); glNormal3f(0.0f,0.0f,1.0f); glVertex3f(-4.0f, 4.0f, 1.0f); glVertex3f(4.0f, 4.0f, 1.0f); glVertex3f(4.0f, -4.0f, 1.0f); glVertex3f(-4.0f, -4.0f, 1.0f); glEnd(); Now OpenGl draws my Quad in white (gray)! I thought the glMaterial command would reflekt red light from the quad so that it looks red in white light. What am I doing wrong? I don’t want to use the command glEnable(Color)! thanks Schmiid
Advertisement
You can't call glMaterial inside a glBegin/glEnd block; move it to right before glBegin(GL_QUADS).
there is no effect if I use glMaterialf before glBegin or not!
Is this all Code what I need or do I have to enable something more?

Schmiid
got it!

just have to to it like this:

static float ambient_mat[] = {1.0f, 0.0f, 0.0f, 1.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT_AND DIFFUSE,ambient_mat);

and it works

Greets

Schmiid

This topic is closed to new replies.

Advertisement