PDA

View Full Version : changing light settings



lara
11-15-2002, 08:48 AM
Hi,
If we are to press keys on the board and change certain things in the display, we use glutPostRedisplay(),
similarly how are we to control changes in the light and color settings in the init() function..
They are'nt recomputed by
glutPostRedisplay()..so how can we control that?

Thanks

bodros
11-15-2002, 09:58 AM
You put the code that you want to change elsewhere. Init() is just meant to initialize the stuff you'll want to keep that way or initialize with some values that you change later. Maybe make your light settings global and change the settings in display().

redisplay causes display() to be called, eventually. Or you could change the light settings from where you call the redisplay.

lara
11-15-2002, 10:14 AM
It's not my day today http://www.opengl.org/discussion_boards/ubb/frown.gif

I try to but then it gives me a syntax error:
All i wanna do is change the spot light direction:
So in my keyboard function i have code like:
case 'u':
angle = 35;
spot_direction[] = { 1.3, 0.4, -10.0};
glutPostRedisplay();
break;
But it gives my as syntax error for spot direction...I dont see anything wrong with the syntax though...

Deiussum
11-15-2002, 10:26 AM
You can only initialize an array like that when you are first defining it.

float spot_direction[] = { 1.3, 0.4, -10.0};

is valid but

spot_direction[] = { 1.3, 0.4, -10.0};

is not.

After you've got the array defined as in the above line, you need to set each element of the array individually like so

spot_direction[0] = 1.3;
spot_direction[1] = 0.4;
spot_direction[2] = -10.0;

nexusone
11-15-2002, 10:44 AM
The init() is used to set everything into a known state.

If you set the light state inside of init() it will not change until you call light function somewhere else.

You could put them in your display routine
example:

void display()
{

glLightfv(GL_LIGHT1 ,GL_POSITION, LightPosition); // when ever LightPosition variable is changed so it the light position.


then in your keyboard:

case: 'L' // light on
glEnable(GL_LIGHT1
break;
case: 'P' // Set light position
LightPosition[0] = x;
LightPosition[1] = y;
LightPosition[2] = z;
break;


Originally posted by lara:
Hi,
If we are to press keys on the board and change certain things in the display, we use glutPostRedisplay(),
similarly how are we to control changes in the light and color settings in the init() function..
They are'nt recomputed by
glutPostRedisplay()..so how can we control that?

Thanks



[This message has been edited by nexusone (edited 11-15-2002).]