Jump to content
  • Advertisement
Sign in to follow this  
Schmiid

OpenGL lights and colors

This topic is 4815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
You can't call glMaterial inside a glBegin/glEnd block; move it to right before glBegin(GL_QUADS).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!