Results 1 to 2 of 2

Thread: SpotLight

  1. #1
    Junior Member Newbie
    Join Date
    May 2004
    Posts
    5

    SpotLight

    I'm having trouble with spotlights

    I use this code to make a spotlight point in the middle of a rectangle, the problem is that the light doesn't work.
    Can anybody help me?
    Tnx
    Code :
    GLfloat diffuseLight[] = {0.8, 0.8, 0.8, 1.0};
    GLfloat specularLight[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat ambientLight[] = {0.2, 0.2, 0.2, 1.0};
    GLfloat lightPos[] = {0.0, 0.0, 5.0, 1.0};
    GLfloat specularReflection[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat spotDir[] = {0.0, 0.0, -30.0};
     
     
    glPushMatrix();
    glTranslatef(-20, -20, -30);
    glColor4f(1, 1, 1, 1);
    glBegin( GL_TRIANGLE_STRIP );
    	glTexCoord2i(0, 1);	glVertex3i(40, 0, 0);   // Top right
    	glTexCoord2i(1, 1);	glVertex3i(0, 0, 0);   // Top left
    	glTexCoord2i(0, 0);	glVertex3i(40, 40, 0);   // Bottom right
    	glTexCoord2i(1, 0);	glVertex3f(0, 40, 0);   // Bottom left
    glEnd();
    glPopMatrix();
     
     
    glEnable(GL_LIGHTING);
    	glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
    	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
    	glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
     
    	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
     
    	glMaterialfv(GL_FRONT, GL_SPECULAR, specularReflection);
    	glMateriali(GL_FRONT, GL_SHININESS, 128);
     
    	glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spotDir);
    	glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0f);
    	glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 2.0f);
     
    	glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0f);
    	glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f);
    	glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0);
     
    	glEnable(GL_LIGHT0);
     
    	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
    	glEnable(GL_COLOR_MATERIAL);
    	glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
    	glEnable(GL_NORMALIZE);

  2. #2
    Guest

    Re: SpotLight

    You are facing the common OpenGL pitfall #2

    http://www.opengl.org/resources/feat...es/oglpitfall/

Similar Threads

  1. spotLight
    By franciscoBiaso in forum OpenGL: GLSL
    Replies: 7
    Last Post: 01-20-2012, 04:09 PM
  2. Spotlight with Texture
    By matdi in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-08-2010, 06:13 AM
  3. spotlight effect
    By fallout in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 10-10-2004, 08:48 PM
  4. Spotlight Texturing
    By Andrew Jameson in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-16-2002, 02:34 PM
  5. How to create a SpotLight?
    By akira_lm in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-29-2001, 06:59 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