/* Demo exhibiting the use of a spotlight */ #include #include #include #include // variables for spotlight. If you change the spotlight direction, you // have to change the drawing of the cone. Search for "depends on the // light vector" GLfloat lightPosition[] = {5,2,2,1}; GLfloat lightDirection [] = {0,-1,1}; // ================================================================ // Globals for callbacks //allows user to change number of squares int Resolution = 16; bool outline = false ; // whether to draw the squares bool smooth = true; // whether to use smooth shading GLfloat lightCutoff = 35; /* ===================================================================== 1*1 unit square drawn with triangle_strips. Adapted from lamppost.c This allows outlining the quads, if desired. In practice, we would probably just use twDrawUnitSquare(). */ void drawUnitSquare(int w, int h ) { int i,j; GLfloat dw = 1.0/w; GLfloat dh = 1.0/h; glNormal3f(0,1,0); for( i=0; i>1; Resolution=Resolution==0?1:Resolution; break; } glutPostRedisplay(); } void modifyCutoff (unsigned char key, int x, int y) { switch(key) { case 'w': lightCutoff++; glutPostRedisplay(); break; case 'n': lightCutoff--; glutPostRedisplay(); break; } } void modifyShading (unsigned char key, int x, int y) { switch(key) { case 's': smooth = true; glutPostRedisplay(); break; case 'f': smooth = false; glutPostRedisplay(); break; } } void keyInit() { twKeyCallback('h', modifySquare, "hides the lines of the unit square"); twKeyCallback('d', modifySquare, "draws the lines of the unit square"); twKeyCallback('+', modifySquare, "double the number of squares"); twKeyCallback('-', modifySquare, "halve the number of squares"); twKeyCallback('w', modifyCutoff, "widens the cutoff angle"); twKeyCallback('n', modifyCutoff, "narrows the cutoff angle"); twKeyCallback('s', modifyShading, "smooth shading"); twKeyCallback('f', modifyShading, "flat shading"); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(800,500); twBoundingBox(0,10,0,5,0,10); glutCreateWindow(argv[0]); glutDisplayFunc(display); twMainInit(); keyInit(); glutMainLoop(); return 0; }