/* * Simple GLUT program to measure triangle strip rendering speed. * Brian Paul February 15, 1997 This file is in the public domain. */ #include #include #include #include #include static float Width = 400.0; static float Height = 400.0; static int Size = 50; #define TEXTURE_SIZE 16 static void Display( void ) { glClearColor( 1.0, 1.0, 1.0, 1.0 ); glClear( GL_COLOR_BUFFER_BIT ); glBegin(GL_QUADS); glTexCoord2f(- TEXTURE_SIZE, - TEXTURE_SIZE); glVertex2f(0, 0); glTexCoord2f(2 * TEXTURE_SIZE, - TEXTURE_SIZE); glVertex2f(Width, 0); glTexCoord2f(2 * TEXTURE_SIZE, 2 * TEXTURE_SIZE); glVertex2f(Width, Height); glTexCoord2f(- TEXTURE_SIZE, 2 * TEXTURE_SIZE); glVertex2f(0, Height); glEnd(); glFinish(); glutSwapBuffers(); } static void Reshape( int width, int height ) { Width = width; Height = height; glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho(0.0, width, 0.0, height, -1.0, 1.0); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); } static void Key( unsigned char key, int x, int y ) { (void) x; (void) y; switch (key) { case 27: exit(0); break; } glutPostRedisplay(); } static void LoadTex(int comp, int filter) { GLubyte *pixels; GLfloat border_color[4] = { 0.0, 0.0, 0.3, 0.3 }; int x, y; pixels = (GLubyte *) malloc(4*TEXTURE_SIZE*TEXTURE_SIZE); for (y = 0; y < TEXTURE_SIZE; ++y) for (x = 0; x < TEXTURE_SIZE; ++x) { if ((x / 4 + y / 4) % 2 == 0) { pixels[(y*TEXTURE_SIZE+x)*4+0] = 0; pixels[(y*TEXTURE_SIZE+x)*4+1] = 255; pixels[(y*TEXTURE_SIZE+x)*4+2] = 0; pixels[(y*TEXTURE_SIZE+x)*4+3] = 255; } else { pixels[(y*TEXTURE_SIZE+x)*4+0] = 255; pixels[(y*TEXTURE_SIZE+x)*4+1] = 255; pixels[(y*TEXTURE_SIZE+x)*4+2] = 255; pixels[(y*TEXTURE_SIZE+x)*4+3] = 255; } } glEnable(GL_TEXTURE_RECTANGLE_ARB); glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, comp, TEXTURE_SIZE, TEXTURE_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, filter); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameterfv(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_BORDER_COLOR, border_color); printf("Texture: %d comps, %s\n", comp, filter == GL_NEAREST ? "GL_NEAREST" : "GL_LINEAR"); } static void Init( int argc, char *argv[] ) { GLint rBits, gBits, bBits; int filter = GL_NEAREST, comp = 3; int i; for (i=1; i