OpenGL lighting fault of texture

Hello,

I have solid lighting bug in my battleship game.
What bothers me the flickering water textures that you see in the video (second half).

http://www.youtube.com/watch?feature=player_embedded&v=xeS-RYFeGGo

Do you know why its flickering?

part of main.cpp


void init(void)
{ // Zufallszeit
srand (time(NULL));
glEnable(GL_CULL_FACE);
 
 
//Ship chris(5);
//chris.setIsEnemy(true);
//cout << chris.getIsEnemy();
 
 
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 1.0 };
 
// LICHT 1
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat light_ambient[] = {1, 1, 1, 1 }; // Farbe
// LICHT 2
GLfloat light_position2[] = { 1.0, -6.0, 10.0, 0.0 };
GLfloat light_ambient2[] = {1, 1, 1, 1 }; // Farbe
// LICHT 3
GLfloat light_position3[] = { 1.0, -16.0, 10.0, 0.0 };
GLfloat light_ambient3[] = {0.1, 0.1, 0.1, 0.1 }; // Farbe
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
 
 
 
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
// Beleuchtung
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_ambient);
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT1, GL_POSITION, light_position);
 
 
// Beleuchtung
glLightfv(GL_LIGHT3, GL_DIFFUSE, light_ambient3);
glLightfv(GL_LIGHT3, GL_AMBIENT, light_ambient3);
glLightfv(GL_LIGHT3, GL_POSITION, light_position3);
// Beleuchtung
glLightfv(GL_LIGHT2, GL_DIFFUSE, light_ambient2);
glLightfv(GL_LIGHT2, GL_POSITION, light_position2);
 
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE); // Normalisierung
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
glEnable(GL_LIGHT3);
 
/**
SCHIFFSMODELLE
**/
schiff10modell.Load("models/textured.3ds");
schiff20modell.Load("models/kreuzer.3ds");
schiff30modell.Load("models/zerstoerer.3ds");
schiff40modell.Load("models/uboot.3ds");
 
waterPlate = glmReadOBJ("models/wasser.obj");
waterTexture = gltxReadRGB("models/wassertextur.rgb");
 
// wie ist die Textur im Speicher organisiert (Zeilen)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
// opengl generiert einen Namen für die Textur und speichert sie
// in der Variablen 'texname'
glGenTextures(6, texName);
 
// Textur setzen / binden
glBindTexture(GL_TEXTURE_2D, texName[0]);
 
// textureigenschaften festlegen
 
// Textur in S = x-Richtung wiederholen
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// Textur in T = y-Richtung wiederholen
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// Interpolation für Pixelvergrößerung festlegen
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Interpolation für Pixelvergrkleinerung festlegen
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// Textur setzen
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, waterTexture->width, waterTexture->height,
0, GL_RGB, GL_UNSIGNED_BYTE, waterTexture->data);
 
schiffeGegner = gegner.placeShipsRandomly(feldGegner);
cout << "
GEGNERPOSITIONEN ZUM CHEATEN :)";
feldGegner.debugPrintField();
 
}
 [/b]
[/b]

What’s the density of your mesh? Keep in mind that with lighting in the fixed-function pipeline, the lighting equation is only evaluated on the vertices. Try using a 20x20 grid of triangles for starters.

And simplify your scenario to narrow down the problem. First, thin down your lights from 3 lights to 1 (I don’t understand why you’d want to have 3 “directional” lights anyway). And set the SPECULAR for that light to 0, so you know you’re debugging only AMBIENT and DIFFUSE. And heck, set DIFFUSE to 0 too and make sure AMBIENT works how you think it should. Then add DIFFUSE and retest.

it comes from the diffuse lights,
if i only activate ambient light its a little bit dark but it doesnt flicker.

(i use scaled cubes with deactivated lighting for the grid. for me its very important that its easy to implement :slight_smile: )

Do you know why its flickering?

The light is not flickering at all.
The lights you have setup are simply responding to the rotation of the scene. How tesselated is the water? I suspect not very much which is why much of the ocean reacts simultaneously to the light when its rotated.

The most obvious thing I can see from your code is that you set up the lights using glLightfv but you have not first setup the scene’s lights modelview matrix. Remeber glLightfv works by multiplying the current modelview matrix by the supplied light position. In your case you have not specified what modelview matrix is (I assume it’s been left as Identity).

Try setting up a proper camera class and position the camera in the scene. With only the camera in the current modelview matrix (i.e. before rendering any scene objects) set the light positions using glLightfv and see what happens. Again, though, make sure the ocean is highly tesselated for best results.