PDA

View Full Version : simple shading/diffuse/specular



true_atlantis
10-17-2005, 03:56 PM
to me, this code should draw 2 cubse next to each other, being different colors, and you shouldnt be able to see the backs/insides of the cubse. can someone explain to me what i am doing wrong? thanks


#include <GL/glut.h>
void myinit(){
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
glLightfv(GL_LIGHT0, GL_AMBIENT, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60,1,0,100);
glMatrixMode(GL_MODELVIEW);
}

void display(){
glLoadIdentity();
gluLookAt(100,100,100,0,0,0,0,1,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
GLfloat mat_specular[]={1.0, 1.0, 1.0, 1.0};
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glutSolidCube(10);
glTranslatef(10,0,0);
GLfloat grey_specular[]={100, 100, 100, 1.0};
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glutSolidCube(10);
glPopMatrix();
glFlush();
}
int main(int argc, char** argv){
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("test");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}

10-18-2005, 02:54 AM
Originally posted by true_atlantis:

gluPerspective(60,1,0,100);zNear must be positive (read as greater then zero), setting zNear to zero will kill the zBuffer.