Results 1 to 5 of 5

Thread: Lighting problem with fog and light enabled

  1. #1
    Guest

    Lighting problem with fog and light enabled

    I wrote a nice little cube with a texture. I added lighting. I added blending, and it became transparent. When I added fog, the cube became all white. If I turn of the light, everything looks ok. What's the problem.
    Here are the lines ( I consider) important from my code :

    GLfloat LightAmbient[]={ 0.5f, 0.5f, 0.5f, 1.0f}; // Ambient Light
    GLfloat LightDiffuse[]={ 1.0f, 0.0f, 0.0f, 1.0f}; // Diffuse Light
    GLfloat LightPosition[]={ 0.0f, 0.0f, 2.0f, 1.0f }; // Posiiton Light
    GLfloat fogColor[]= { 0.5f, 0.5f, 0.5f, 1.0f}; // Fog Color

    // in InitGL() :

    glClearColor( 0.5f, 0.5f, 0.5f, 1.0f); //Clear Background Color To Gray

    glColor4f(0.5f,0.5f,0.5f,0.3f);

    glBlendFunc(GL_SRC_ALPHA,GL_ONE);

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Lighting problem with fog and light enabled

    More lines from your code would probably help more. For instance, how you setup the fog and lighting (and where.)

    Also, are you using the projection matrix for anything other than setting up an orthographic or perspective matrix? (i.e. anything that is not glFrustum/glOrtho/gluPerspective/gluOrtho2D like gluLookAt/glTranslate/etc.)
    Trying to do "camera" transformations on the projection matrix instead of the modelview matrix can screw up fog and light calculations.
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Guest

    Re: Lighting problem with fog and light enabled

    More lines of my code :
    // Global variable :
    GLuint fogMode[]= { GL_EXP, GL_EXP2, GL_LINEAR};

    // in InitGL() :

    glClearColor( 0.5f, 0.5f, 0.5f, 1.0f);
    glColor4f(0.5f,0.5f,0.5f,0.3f);

    glEnable(GL_FOG); glFogi (GL_FOG_MODE, fogMode[fogfilter]);
    glFogfv (GL_FOG_COLOR, fogColor); glFogf (GL_FOG_DENSITY, 0.35f);
    glHint (GL_FOG_HINT, GL_DONT_CARE); glFogf (GL_FOG_START, 1.0f); glFogf (GL_FOG_END, 5.0f);

    glClearDepth( 1.0);
    glDepthFunc( GL_LESS);
    glEnable( GL_DEPTH_TEST);
    glShadeModel( GL_SMOOTH);
    glMatrixMode( GL_PROJECTION);
    glLoadIdentity( );

    gluPerspective( 45.0f, (GLfloat)Width / Height, 0.1f, 100.0f);

    glMatrixMode( GL_MODELVIEW); // The Modelview Matrix

    glLightfv( GL_LIGHT1, GL_AMBIENT, LightAmbient);

    glLightfv( GL_LIGHT1, GL_DIFFUSE, LightDiffuse);

    glLightfv( GL_LIGHT1, GL_POSITION, LightPosition);

    glEnable( GL_LIGHT1);

    // In DrawGLScene() :

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity( );
    glTranslatef( 0.0f, 0.0f, z);
    glRotatef( xrot, 1.0f, 0.0f, 0.0f);
    glRotatef( yrot, 0.0f, 1.0f, 0.0f);

    glBegin( GL_QUADS);
    // A cube is drawn here with normals set and everything
    glEnd();

    Hope that's enough. If anyone wants the code, I would gladly send it if he asks so, and if he posts his email address.

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2001
    Location
    undisclosed
    Posts
    1

    Re: Lighting problem with fog and light enabled

    If you're using fog, then shouldn't your background be whitened too? If so, then your blended cube might just showing through.
    Could you send your source to theantguy@hotmail.com please?--Maybe it could help me with some problems i've been having.
    -Ant

  5. #5
    Guest

    Re: Lighting problem with fog and light enabled

    As you may see, the fog color is the same as the color I use in glClearColor, so this isn't the problem. I sent you my source, maybe you'll see what's wrong.

Similar Threads

  1. RTT using FBO shows scene as if light was enabled
    By jmfairlie in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 04-09-2010, 02:16 AM
  2. GL_LINES with lighting enabled
    By cprimenull in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-18-2009, 07:53 PM
  3. Light Enabled, object gets invisible
    By iris_raj in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-09-2006, 01:08 PM
  4. Replies: 2
    Last Post: 03-22-2004, 11:37 AM
  5. Grey polys when Lighting is enabled....
    By Khrob in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-23-2000, 10:28 AM

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