I have a frustrating problem. I want to light up the sphere, like when the sun lights up the moon.
It works with this code:
public void display(GLAutoDrawable drawable) {
gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel (GL.GL_SMOOTH);
float light_position[] = { -5.0f, 7.0f, sunrise, 0.0f }; // Works if this line is inside the display() method
gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, FloatBuffer.wrap(light0_ambient));
gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, FloatBuffer.wrap(mat_specular));
gl.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, FloatBuffer.wrap(mat_shininess));
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, FloatBuffer.wrap(light_position));
...
sunrise += 0.02f;
...
If I place the line:
float light_position[] = { -5.0f, 7.0f, sunrise, 0.0f };
outside the display() method so it becomes a class member, then the animation doesn´t work and the sun seems to be still. How come?