Results 1 to 4 of 4

Thread: OpenGL lighting fault of texture

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2013
    Posts
    6

    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...;v=xeS-RYFeGGo

    Do you know why its flickering?

    part of main.cpp

    Code :
    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 << "\nGEGNERPOSITIONEN ZUM CHEATEN :)";
    feldGegner.debugPrintField();
     
    }
     [/B]
    [/B]

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,654

    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
    Posts
    6

    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
    Location
    UK, London
    Posts
    1,161

    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