/* Displays a texture loaded using the netpbm library and put on a unit square. Scott D. Anderson Fall 2006 */ #include #include #include #include /* The following come from the texture file, and are also used as the unit in world space for the size of the quad. */ GLfloat textureHeight; GLfloat textureWidth; void display(void) { twDisplayInit(); twCamera(); glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex2f(0,1); // upper left glTexCoord2f(0,1); glVertex2f(0,0); // lower left glTexCoord2f(1,1); glVertex2f(1,0); // lower right glTexCoord2f(1,0); glVertex2f(1,1); // upper right glEnd(); glPopAttrib(); glFlush(); glutSwapBuffers(); } int main(int argc, char* argv[]) { char buf[256]; char* filename; if( argc <= 1 ) { printf("What texture file to load? "); scanf(buf,sizeof(buf),stdin); filename = buf; } else { filename = argv[1]; } /* Ready to start doing OpenGL */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(500,500); glutCreateWindow(argv[0]); glutDisplayFunc(display); /* load the texture file */ int fail=twPPM_Tex2D(filename, true, textureWidth, textureHeight); if( fail ) { exit(1); } printf("%f %f\n",textureWidth,textureHeight); twBoundingBox(0,1,0,1,0,0.01); // essentially flat twMainInit(); glutMainLoop(); return (0); }