Sign in to follow this  
Niall18

Kinda model/lighting problem :-)

Recommended Posts

Okay heres my problem, its a bit of a weird one. I have a pool table which is; width 6 length 10 Theres no changing y values in my program coz the table is on the z axis i.e. front z=0 and back z=10. I've just put in two spot lights and had them shining down on the table and everything looked pretty good. I then went and added the pool balls onto the table and all of a sudden both lights appear to have doubled in brightness with the back light being much brighter than the one at the front. I take them out and everything goes back to normal i.e. equal brightness etc. I can't really paste the code in coz there'd be quite a lot but i hope thats enough info for someone to maybe point out where my error may lie.

Share this post


Link to post
Share on other sites
I can't really tell, but my guess is something wrong with either matrices or materials. Make sure that,when you call glLight to set the position, the modelview matrix is the right one, and has not been affected by the "transformatons/rotations" you use for the balls. Same for the material, maybe when you draw the table you use a material that was meant for the balls.

Share this post


Link to post
Share on other sites
Its not a scaling problem, that i'm sure of. Heres the relevant code so u can see whats happening


void drawBall(int rBallNum, int colour)
{
if(colour == 1) glColor3f(1.0, 0.0f, 0.0f);

else if(colour == 6) glColor3f(1.0f, 1.0f, 1.0f);

else if(colour == 8) glColor3f(1.0f, 1.0f, 1.0f);

else if(colour == 7) glColor3f(1.0f, 1.0f, 1.0f);

else if(colour == 2) glColor3f(1.0f, 1.0f, 1.0f);

else if(colour == 5) glColor3f(1.0f, 1.0f, 1.0f);

else if(colour == 4) glColor3f(1.0f, 1.0f, 1.0f);

glPushMatrix();

GLUquadricObj * object;
object= gluNewQuadric();
gluQuadricDrawStyle(object, GLU_FILL);
gluQuadricNormals(object, GLU_SMOOTH );

glTranslatef(ball[rBallNum].x,ball[rBallNum].y,ball[rBallNum].z);

gluSphere(object, radius, 32, 32);
glPopMatrix();
}

int InitGL(GLvoid)
{
glClearColor (0.0, 0.0, 0.0, 0.0);

glEnable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);

glShadeModel(GL_SMOOTH);

GLfloat ambient[] = {0.5,0.5,0.5,1.0};
GLfloat diffuse[] = {1.0,1.0,1.0,1.0};
GLfloat specular[] = {0.0,0.0,0.0,0.0};

glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);

glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION, 1.0);
glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION, 0.0);
glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION, 0.0);
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT,7.0);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 90.0);



glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, specular);

glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION, 1.0);
glLightf(GL_LIGHT1,GL_LINEAR_ATTENUATION, 0.0);
glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION, 0.0);
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT,7.0);
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 90.0);


glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);

glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);


return TRUE;
}

void drawTable()
{
float z = 0.0;

for(z=1.0; z<=15.0; z+=0.1)
{
for(float x=-3.0; x<=3.0; x+=0.1)
{
g_vRect[1] = snooker_Vector(x,-2.0,z);
g_vRect[2] = snooker_Vector(x+0.1,-2.0,z);
g_vRect[3] = snooker_Vector(x+0.1,-2.0,z+0.1);
g_vRect[4] = snooker_Vector(x,-2.0,z+0.1);

DrawQuad_Table(1,2,3,4);
}
}

}

void RenderScene()
{
GLfloat position[] = {0.0,2.0,2.0,1.0};
GLfloat spot_direction[] = {0.0,-2.0,0.2,1.0};

GLfloat position1[] = {0.0,2.0,3.5,1.0};
GLfloat spot_direction1[] = {0.0,-2.0,3.6,1.0};


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glPushMatrix();

g_Camera.PositionCamera(0.0,1.5,0.0,
0.0,-2.0,8.6,
0.0,1.0,0.0);

g_Camera.Look();

glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,spot_direction);

glLightfv(GL_LIGHT1, GL_POSITION, position1);
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION,spot_direction1);


glPushMatrix();

drawTable();

// Draws 10 red balls
for(int b = 1; b <= 10; b++)
{
drawBall(b,1);
}

glPopMatrix();
glPopMatrix();


SwapBuffers(hDC);
}




Hope those source tags worked. Anyway when i drew the table two nice spot lights. Put in the drawball function though and i get two brighter lights, one at the back brighter than the other. Weird. I'm not calculating normals, could it have something to do with that? Or maybe the way i've set my lights and materials up?

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