/* Simplest demo of reading in an image and texture-mapping it onto the teapot, which defines texture coordinates for each Bezier patch. Scott D. Anderson Fall 2005 */ #include #include // for printf #include // for exit #include char* filename = "USflag.ppm"; void texinit() { glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); twPPM_Tex2D(filename,true); } void display() { twDisplayInit(); twCamera(); glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_TEXTURE_2D); glutSolidTeapot(1); // the radius of the teapot body is 1 glPopAttrib(); glFlush(); glutSwapBuffers(); } int main(int argc, char **argv) { if(argc >= 2) { filename=argv[1]; } glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500, 500); glutCreateWindow(argv[0]); glutDisplayFunc(display); twBoundingBox(-1.5,+1.7,-0.7,+0.8,-1,+1); // still not perfect, but pretty close twMainInit(); texinit(); // load the texture from the file glutMainLoop(); }