/* Lab exercise on texture mapping Scott D. Anderson Fall 2004 */ #include #include #include /* ================================================================ */ GLfloat texWidth=1, texHeight=1; void texinit() { glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); twError(); twPPM_Tex2D("buffy.ppm",true,texWidth,texHeight); twError(); printf("%f x %f\n",texWidth,texHeight); } void display() { twDisplayInit(); twCamera(); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); // front glTexCoord2f(0,0); glVertex3f( 0,1,1); glTexCoord2f(0,texHeight); glVertex3f( 0,0,1); glTexCoord2f(texWidth,texHeight); glVertex3f( 1,0,1); glTexCoord2f(texWidth,0); glVertex3f( 1,1,1); // top glTexCoord2f(0,0); glVertex3f( 0,1,1); glTexCoord2f(0,1); glVertex3f( 1,1,1); glTexCoord2f(1,1); glVertex3f( 1,1,0); glTexCoord2f(1,0); glVertex3f( 0,1,0); // left glTexCoord2f(0,0); glVertex3f( 0,1,1); glTexCoord2f(0,1); glVertex3f( 0,1,0); glTexCoord2f(1,1); glVertex3f( 0,0,0); glTexCoord2f(1,0); glVertex3f( 0,0,1); glEnd(); glFlush(); glutSwapBuffers(); } /* ================================================================ */ int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500, 500); glutCreateWindow(argv[0]); glutDisplayFunc(display); twBoundingBox(0,1,0,1,0,1); twMainInit(); texinit(); glutMainLoop(); }