/* Simplest demo of reading in an image and texture-mapping it onto something; in this case, a quad. 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); twPPM_Tex2D(filename,true); } void display() { twDisplayInit(); twCamera(); glEnable(GL_TEXTURE_2D); // this is a *square*, so the aspect ratio may not match the texture's aspect-ratio glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex3f( -1, 1,0); // upper left vertex is 0,0 in texture space glTexCoord2f(0,1); glVertex3f( -1,-1,0); // lower left is 0,1 in texture space glTexCoord2f(1,1); glVertex3f( 1,-1,0); // lower right is 1,1 glTexCoord2f(1,0); glVertex3f( 1, 1,0); // upper right is 1,0 glEnd(); 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,+1,-1,+1,0,0.01); twMainInit(); texinit(); // load the texture from the file glutMainLoop(); }