Results 1 to 3 of 3

Thread: Lighting problems

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    12

    Lighting problems

    Hi,

    I'v load a object from an object file,
    I used to work on wire frame mode and now I want it to have smooth shading.
    But, I can't manage to do it.My object now still looks like its having flat shading.Do not know where the problem lies.
    Heres a portion the code.
    Code :
    // Set smooth shading mode for drawing the object
          gl.glPolygonMode (gl.GL_FRONT, gl.GL_SMOOTH);
     
          // lighting settings
          float mat_specular[]={1.0f, 1.0f, 1.0f, 1.0f};
          float mat_shininess[]={50.0f};
          float light_position[]={-2.0f, -3.0f, 4.0f, 0.0f};
          float white_light[]={1.0f, 1.0f, 1.0f, 1.0f};
          float lmodel_ambient[]={0.1f, 0.1f, 0.1f, 1.0f};
          gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
          gl.glShadeModel(gl.GL_SMOOTH);
          gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, mat_specular,0);
          gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS,mat_shininess,0);
     
          gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light_position, 0);
          gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, white_light, 1);
          gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, white_light, 1);
          gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient,2);
     
          gl.glEnable(gl.GL_LIGHTING);
          gl.glEnable(gl.GL_LIGHT0);
          gl.glEnable(gl.GL_DEPTH_TEST);
          gl.glEnable(gl.GL_COLOR_MATERIAL);
     
          //import the model
          model=new OBJModel(modelname,2.0f,gl,true);
    I then draw the model is the display() method.
    Code :
    //draw the model 
    drawModel(gl,drawable,gl.GL_RENDER);
    Thanks for the help.

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2009
    Posts
    14

    Re: Lighting problems

    I think light_position vector last value( w) should be 1.0, otherwise your light is positional and that could make shading look flat

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,653

    Re: Lighting problems

    Quote Originally Posted by manati
    I think light_position vector last value( w) should be 1.0, otherwise your light is positional and that could make shading look flat
    I think you just misspoke, but POSITION.w == 0.0 implies directional light. Otherwise it is positional, though typically you'd just use POSITION.w == 1.0 for positional lights.

Similar Threads

  1. Lighting Problems
    By TheRealSmolt in forum OpenGL: GLSL
    Replies: 3
    Last Post: 01-23-2019, 01:57 PM
  2. Lighting problems
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-20-2003, 03:26 AM
  3. Lighting Problems
    By wpcmmx in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 08-03-2001, 11:34 AM
  4. Two Problems with Lighting
    By B. Jacob in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-10-2001, 03:29 AM
  5. Problems with lighting
    By mcbastian in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-19-2001, 03:50 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