Sign in to follow this  
andfol

Lighting on OpenGL polygon

Recommended Posts

Hi,

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);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);

glEnable(GL_LIGHTING);

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);

glEnable(GL_LIGHT0);

glDisable(GL_LIGHTING);

}

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

Thanks.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this