Sign in to follow this  
tungmeister

spotlights help

Recommended Posts

hi guys, i'm having some problems getting lighting to work in a game i'm making, i'm trying to create 3 spotlights spaced out above a game table using the code as follows: // Create light components float ambientLight[] = { 0.2, 0.2, 0.2, 1 }; float diffuseLight[] = { 0.8f, 0.8f, 0.8f, 1 }; float specularLight[] = { 0.5f, 0.5f, 0.5f, 1}; float spotlight1Pos[] = {650, 1300, 625 , 0}; //bottom end of table float spotlight2Pos[] = {650, 1300, 1250 , 0}; float spotlight3Pos[] = {650, 1300, 1875 , 0}; float spotlightDirection[] = {0, -1, 0}; //straight down void lighting() { glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); //ambient element glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); //diffuse element glLightfv(GL_LIGHT0, GL_POSITION, spotlight1Pos); //light position glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight); //spotlight properties glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 20); //40 degree-wide cone glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 30); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spotlightDirection); glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight); //ambient element glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight); //diffuse element glLightfv(GL_LIGHT1, GL_POSITION, spotlight2Pos); //light position glLightfv(GL_LIGHT1, GL_SPECULAR, specularLight); //spotlight properties glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 20); //40 degree-wide cone glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 30); glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spotlightDirection); glLightfv(GL_LIGHT2, GL_AMBIENT, ambientLight); //ambient element glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuseLight); //diffuse element glLightfv(GL_LIGHT2, GL_POSITION, spotlight3Pos); //light position glLightfv(GL_LIGHT2, GL_SPECULAR, specularLight); //spotlight properties glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 20); //40 degree-wide cone glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, 30); glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, spotlightDirection); } but nstead of seeing 3 spotlights and shading the scene looks asthough its being lit by one source you can see what i meen here: http://i191.photobucket.com/albums/z189/tungmeister/lighting.jpg can anyone tell me where i'm going wrong? thanks

Share this post


Link to post
Share on other sites
Because the lighting is done per-vertex your mesh has to be highly tessellated. A way around this is to use per-pixel lighting via a fragment shader. Here's a good place to start with shaders:

http://www.ozone3d.net/tutorials/glsl_lighting_phong.php

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this