void draw_shadow(int shad) { int x = 0; #ifdef GL_VERSION_1_1 if (supportsOneDotOne() && !forceExtension) { polygonOffsetVersion = ONE_DOT_ONE; glPolygonOffset(-2.0, -1.0); } else #endif { #ifdef GL_EXT_polygon_offset /* check for the polygon offset extension */ if (glutExtensionSupported("GL_EXT_polygon_offset")) { polygonOffsetVersion = EXTENSION; glPolygonOffsetEXT(-0.1, -0.002); } else #endif { polygonOffsetVersion = MISSING; //printf("\nMissing polygon offset.\n"); //printf("Expect shadow depth aliasing artifacts.\n\n"); } } findPlane(floorPlane, floorVertices[1], floorVertices[2], floorVertices[3]); redraw(shad); }
int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow("offset"); glutDisplayFunc(draw_scene); #ifdef GL_VERSION_1_1 if (supportsOneDotOne()) { glPolygonOffset(2.0, 1); version = MODE_11; } else #endif { #ifdef GL_EXT_polygon_offset /* check for the polygon offset extension */ if (glutExtensionSupported("GL_EXT_polygon_offset")) { glPolygonOffsetEXT(0.75, 0.00); version = MODE_EXT; } else #endif { error(argv[0], "Warning: running with out the polygon offset extension.\n"); version = MODE_NONE; } } /* set up viewing parameters */ glMatrixMode(GL_PROJECTION); gluPerspective(20, 1, 0.1, 20); glMatrixMode(GL_MODELVIEW); glTranslatef(0, 0, -15); /* set other relevant state information */ glEnable(GL_DEPTH_TEST); glShadeModel(GL_FLAT); glDisable(GL_DITHER); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
int main(int argc, char **argv) { int i; glutInit(&argc, argv); for (i=1; i<argc; i++) { if (!strcmp("-linear", argv[i])) { linearFiltering = 1; } else if (!strcmp("-mipmap", argv[i])) { useMipmaps = 1; } else if (!strcmp("-ext", argv[i])) { forceExtension = 1; } } glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL | GLUT_MULTISAMPLE); #if 1 /* In GLUT 4.0, you'll be able to do this an be sure to get 2 bits of stencil if the machine has it for you. */ glutInitDisplayString("samples stencil~3 rgb double depth"); #endif glutCreateWindow("OpenGL Halo Magic (hit Space)"); if (glutGet(GLUT_WINDOW_STENCIL_SIZE) < 3) { printf("halomagic: Sorry, I need at least 3 bits of stencil.\n"); exit(1); } /* Register GLUT callbacks. */ glutDisplayFunc(redraw); glutMouseFunc(mouse); glutMotionFunc(motion); glutVisibilityFunc(visible); glutKeyboardFunc(key); glutSpecialFunc(special); glutCreateMenu(controlLights); glutAddMenuEntry("Toggle halo blending", M_BLENDED_HALO); glutAddMenuEntry("Show halo", M_SHOW_HALO); glutAddMenuEntry("Switch model", M_SWITCH_MODEL); glutAddMenuEntry("Toggle motion", M_MOTION); glutAddMenuEntry("-----------------------", M_NONE); glutAddMenuEntry("Toggle light", M_LIGHT); glutAddMenuEntry("Toggle texture", M_TEXTURE); glutAddMenuEntry("Toggle shadows", M_SHADOWS); glutAddMenuEntry("Toggle reflection", M_REFLECTION); glutAddMenuEntry("Toggle object", M_DINOSAUR); glutAddMenuEntry("-----------------------", M_NONE); glutAddMenuEntry("Toggle reflection stenciling", M_STENCIL_REFLECTION); glutAddMenuEntry("Toggle shadow stenciling", M_STENCIL_SHADOW); glutAddMenuEntry("Toggle shadow offset", M_OFFSET_SHADOW); glutAddMenuEntry("----------------------", M_NONE); glutAddMenuEntry("Positional light", M_POSITIONAL); glutAddMenuEntry("Directional light", M_DIRECTIONAL); glutAddMenuEntry("-----------------------", M_NONE); glutAddMenuEntry("Toggle performance", M_PERFORMANCE); glutAttachMenu(GLUT_RIGHT_BUTTON); makeDinosaur(); #ifdef GL_VERSION_1_1 if (supportsOneDotOne() && !forceExtension) { polygonOffsetVersion = ONE_DOT_ONE; glPolygonOffset(-2.0, -1.0); } else #endif { #if defined(GL_EXT_polygon_offset) && !defined(GL_VERSION_1_1) /* check for the polygon offset extension */ if (glutExtensionSupported("GL_EXT_polygon_offset")) { polygonOffsetVersion = EXTENSION; glPolygonOffsetEXT(-0.1, -0.002); } else #endif { polygonOffsetVersion = MISSING; printf("\ndinoshine: Missing polygon offset.\n"); printf(" Expect shadow depth aliasing artifacts.\n\n"); } } glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glLineWidth(3.0); glMatrixMode(GL_PROJECTION); gluPerspective( /* field of view in degree */ 40.0, /* aspect ratio */ 1.0, /* Z near */ 20.0, /* Z far */ 100.0); glMatrixMode(GL_MODELVIEW); gluLookAt(0.0, 8.0, 60.0, /* eye is at (0,0,30) */ 0.0, 8.0, 0.0, /* center is at (0,0,0) */ 0.0, 1.0, 0.); /* up is in postivie Y direction */ glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor); glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); makeFloorTexture(); /* Setup floor plane for projected shadow calculations. */ findPlane(floorPlane, floorVertices[1], floorVertices[2], floorVertices[3]); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }