Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lighting on OpenGL polygon

Started by andfol Apr 23, 2012 at 8:18 PM 1 replies 2.1k views
Original Post
andfol
andfol
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.
SimonForsman
SimonForsman
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)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
_WeirdCat_
_WeirdCat_
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

Topic Locked

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

Sign in to reply to this topic.