Results 1 to 4 of 4

Thread: OpenGL lighting fault of texture

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2013

    OpenGL lighting fault of texture


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

    Do you know why its flickering?

    part of main.cpp

    Code :
    void init(void)
    { // Zufallszeit
    srand (time(NULL));
    //Ship chris(5);
    //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);
    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_NORMALIZE); // Normalisierung
    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
    // Textur in T = y-Richtung wiederholen
    // Interpolation für Pixelvergrößerung festlegen
    // Interpolation für Pixelvergrkleinerung festlegen
    // 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);

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004

    Re: OpenGL lighting fault of texture

    Quote Originally Posted by Furtano
    I have solid lighting bug in my battleship game.
    What bothers me the flickering water textures that you see in the video (second half).
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2013

    Re: OpenGL lighting fault of texture

    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 )

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    UK, London

    Re: OpenGL lighting fault of texture

    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.

Similar Threads

  1. Segmentation fault when loading texture using SOIL
    By Donnie in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-01-2015, 06:52 AM
  2. Render to Texture, Segmentation Fault ...
    By abominable in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-14-2010, 10:38 AM
  3. Segmentation fault (creating texture)
    By ei05tbe in forum OpenGL: Basic Coding
    Replies: 19
    Last Post: 07-04-2010, 03:20 PM
  4. Fault with Compressed PBO texture loader
    By DWilson in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-27-2009, 06:38 PM
  5. Opengl Fault on 8800Ultra. HELP!
    By Palomita in forum OpenGL: User Software
    Replies: 1
    Last Post: 05-15-2008, 04:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean