Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Textured quad not receiving light

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2013

    Textured quad not receiving light

    Hello again. I am creating a spotlight centered in the viewport where 2 texture quads are rendered. As the image shows, only the red cursor is getting the light. I have no idea why the checkerboard isn't receiving the light. They are both rendered the same way.

    Click image for larger version. 

Name:	nolight.jpg 
Views:	244 
Size:	19.4 KB 
ID:	989

    Here is the code I use to setup the light (I am still experimenting so please correct me if I'm doing something wrong):

    Code :
    		GLfloat position[] = { ViewWidth / 2.0f, ViewHeight / 2.0f, 100.0, 1.0f };
    		GLfloat direction[] = { 0.0, 0.0, -1.0f };
    		GLfloat color[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    		glLightfv(GL_LIGHT0, GL_POSITION, position);
    		glLightfv(GL_LIGHT0, GL_AMBIENT, color);
    		glLightfv(GL_LIGHT0, GL_DIFFUSE, color);
    		glLightfv(GL_LIGHT0, GL_SPECULAR, color);
    		glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction);
    		glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 60.0f);
    		glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 12.0f);

    The viewport is orthographic if it matters. So any ideas what's going wrong here?
    Last edited by Kind_9; 02-28-2013 at 04:25 PM.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Make sure the normals for the 2 quads are both pointing in the same direction.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2013
    I use the same code the render both quads:

    Code :
    			glNormal3f(0.0, 0.0, 1.0f);
    			glTexCoord2f(0.0, 1.0f);
    			glVertex2f((float)x, (float)y + (float)Height);
    			glTexCoord2f(0.0, 0.0);
    			glVertex2f((float)x, (float)y);
    			glTexCoord2f(1.0f, 0.0f);
    			glVertex2f((float)x + (float)Width, (float)y);
    			glTexCoord2f(1.0f, 1.0);
    			glVertex2f(x + (float)Width, y + (float)Height);

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2008
    If you are using lighting with fixed function, the amount of light contributing to the scene will be calculated per-vertex + will be interpolated between the vertices. This means if you have a large plane with the light in the middle of it, each vertex will be far from the light so the lighting calculation at those vertices will be calculated as appearing poorly lit. Since the entire plane will be interpolating between these equally dark values far from the light, the middle will also appear dark.

    To solve it, you could:

    a) Continue using per-vertex lighting, but add more vertices/triangles, eg. Making the board from 8x8x2 triangles instead of 2 triangles will mean interpolation will be closer to what you expected, as there will be vertices close to the light if the light is in the middle of the board

    b) Use per-pixel lighting via shaders instead of per-vertex lighting

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2013
    I see. Thanks very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts