/* texture.c */ /* Purpose: demonstrate a simple texture */ #ifdef __APPLE__ #include #else #include #endif #include /* Module constants */ /* The image for the texture */ static const GLubyte mpImage[] = { 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; /* Functions */ GLvoid display( GLvoid ) { glClear( GL_COLOR_BUFFER_BIT ); /* Note that we are still bound to texture object 0 */ glBegin( GL_QUADS ); { /* A square with texture coords */ glTexCoord2f( 0.0, 0.0 ); glVertex2f( -0.5, -0.5 ); glTexCoord2f( 1.0, 0.0 ); glVertex2f( 0.5, -0.5 ); glTexCoord2f( 1.0, 1.0 ); glVertex2f( 0.5, 0.5 ); glTexCoord2f( 0.0, 1.0 ); glVertex2f( -0.5, 0.5 ); } glEnd(); glFlush(); } void init( void ) { /* Put the image into the texture object */ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, mpImage ); /* Specify the magnification/minification method */ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); /* Replace the current polygon colours with the texture */ glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); /* Enable texturing */ glEnable( GL_TEXTURE_2D ); } int main( int argc, char *argv[] ) { glutInit( &argc, argv ); glutCreateWindow( argv[0] ); glutDisplayFunc( display ); init(); glutMainLoop(); return 0; }