PDA

View Full Version : Lighting and the backside



dutchstud
02-16-2002, 06:10 PM
Is it possible to have the back of a quad lit as well as the front? i have a 3d mathematical formula, and part of it is lit on one side, and another part is lit on the other side. can i light both sides of both parts? thanks in advance.

chowe6685
02-16-2002, 06:22 PM
yes, I believe you just call
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
this may cause a significant performance hit

dutchstud
02-16-2002, 06:33 PM
after i look at it, it seems that both sides are shaded on one side, and neither are shaded on the other. i think the unshaded side is in the negative x, so maybe it has something to do with the crossproduct formula for normals? anyone have any idea?

dutchstud
02-16-2002, 06:55 PM
a little code for ya eh?



glBegin(GL_QUADS);

for(x=-SIZE;x<=SIZE;x+=FREQ) {
for(y=-SIZE;y<=SIZE;y+=FREQ) {

pts[0].x = x;
pts[0].y = y;
z=sin(pts[0].x)+sin(pts[0].y);
pts[0].z = z;

pts[1].x = x+FREQ;
pts[1].y = y;
z=sin(pts[1].x)+sin(pts[1].y);
pts[1].z = z;

pts[2].x = x+FREQ;
pts[2].y = y+FREQ;
z=sin(pts[2].x)+sin(pts[2].y);
pts[2].z = z;

pts[3].x = x;
pts[3].y = y+FREQ;
z=sin(pts[3].x)+sin(pts[3].y);
pts[3].z = z;


normal.x=(pts[2].y-pts[1].y)*(pts[4].z-pts[1].z)-(pts[2].z-pts[1].z)*(pts[4].y-pts[1].y);
normal.y=(pts[2].z-pts[1].z)*(pts[4].x-pts[1].x)-(pts[2].x-pts[1].x)*(pts[4].z-pts[1].z);
normal.z=(pts[2].x-pts[1].x)*(pts[4].y-pts[1].y)-(pts[2].y-pts[1].y)*(pts[4].x-pts[1].x);


glNormal3f(normal.x, normal.y, normal.z);
glVertex3f(pts[0].x, pts[0].y, pts[0].z);
glVertex3f(pts[1].x, pts[1].y, pts[1].z);
glVertex3f(pts[2].x, pts[2].y, pts[2].z);
glVertex3f(pts[3].x, pts[3].y, pts[3].z);


}

}

glEnd();