Jump to content
  • Advertisement
Sign in to follow this  

Lighting on OpenGL polygon

This topic is 2279 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


I am trying to implement some lighting on an eight sided polygon drawn with OpenGL. I have declared the type of light and how the surfaces react and position in my constructor:

ambientLight[4] = 0.3f, 0.5f, 0.8f, 1.0f;
diffuseLight[4] = 0.25f, 0.25f, 0.25f, 1.0f;

spotLightPosition[4] = -25.0f, 0.0f, -230.0f, 1.0f;

matAmbient[4] = 1.0f, 1.0f, 1.0f, 1.0f;
matDiff[4] = 1.0f, 1.0f, 1.0f, 1.0f;

Next I have an initialise function for the above:

void CNutObsticle::initialize()

glClearColor(1.0f, 0.0f, 0.0f, 0.0f);


glMaterialfv(GL_FRONT, GL_AMBIENT, matAmbient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff);

glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, ambientLight);
glLightfv(GL_LIGHT0, GL_POSITION, spotLightPosition);




If anyone has any ideas I would be grateful the code does compile but there is no lighting effect.


Share this post

Link to post
Share on other sites
Well, you're not even rendering anything in the posted code so it is quite difficult to guess, also, remember that OpenGL is a state machine, initialisating OpenGL in a game objects constructor is a bad idea (as the OpenGL state you set in that constructor will apply to anything you do after that object is constructed)

Share this post

Link to post
Share on other sites
you disable gllighting after initialization, glDisable(GL_LIGHTING); remove this line newxt thing that i cant use lightning when vars are just static i use this instead
float *diff;
float *amb;
float *pos; then diff = new float[4]; and some addontial things

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);
glColorMaterial( GL_BACK, GL_AMBIENT);
glColorMaterial( GL_FRONT, GL_DIFFUSE); and the way you do things initialize light set positions enable gl_lightiung and gl_light then render polygon and disable gl_light and then gl_lighting

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!