Jump to content

  • Log In with Google      Sign In   
  • Create Account

Lighting on OpenGL polygon


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 andfol   Members   -  Reputation: 103

Like
0Likes
Like

Posted 23 April 2012 - 02:18 PM

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.

Sponsor:

#2 SimonForsman   Crossbones+   -  Reputation: 6122

Like
0Likes
Like

Posted 23 April 2012 - 02:43 PM

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

#3 WiredCat   Members   -  Reputation: 325

Like
0Likes
Like

Posted 25 April 2012 - 07:15 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS