132001f49Smrg 232001f49Smrg/* 332001f49Smrg * Trivial CVA test, good for testing driver fastpaths (especially 432001f49Smrg * indexed vertex buffers if they are supported). 532001f49Smrg * 632001f49Smrg * Gareth Hughes 732001f49Smrg * November 2000 832001f49Smrg */ 932001f49Smrg 1032001f49Smrg#include <stdlib.h> 1132001f49Smrg#include <stdio.h> 1232001f49Smrg#include <string.h> 1332001f49Smrg#include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */ 1432001f49Smrg#ifdef _WIN32 1532001f49Smrg#include <windows.h> 1632001f49Smrg#endif 1732001f49Smrg#define GL_GLEXT_LEGACY 1832001f49Smrg#include <GL/glew.h> 1932001f49Smrg#include "glut_wrap.h" 2032001f49Smrg 2132001f49SmrgGLfloat verts[][4] = { 2232001f49Smrg { -0.5, -0.5, -2.0, 0.0 }, 2332001f49Smrg { 0.5, -0.5, -2.0, 0.0 }, 2432001f49Smrg { -0.5, 0.5, -2.0, 0.0 }, 2532001f49Smrg { 0.5, 0.5, -2.0, 0.0 }, 2632001f49Smrg}; 2732001f49Smrg 2832001f49SmrgGLubyte color[][4] = { 2932001f49Smrg { 0xff, 0x00, 0x00, 0x00 }, 3032001f49Smrg { 0x00, 0xff, 0x00, 0x00 }, 3132001f49Smrg { 0x00, 0x00, 0xff, 0x00 }, 3232001f49Smrg { 0xff, 0xff, 0xff, 0x00 }, 3332001f49Smrg}; 3432001f49Smrg 3532001f49SmrgGLuint indices[] = { 0, 1, 2, 3 }; 3632001f49Smrg 3732001f49SmrgGLboolean compiled = GL_TRUE; 3832001f49SmrgGLboolean doubleBuffer = GL_TRUE; 3932001f49Smrg 4032001f49Smrg 4132001f49Smrgstatic void init( void ) 4232001f49Smrg{ 4332001f49Smrg glClearColor( 0.0, 0.0, 0.0, 0.0 ); 4432001f49Smrg glShadeModel( GL_SMOOTH ); 4532001f49Smrg 4632001f49Smrg glFrontFace( GL_CCW ); 4732001f49Smrg glCullFace( GL_BACK ); 4832001f49Smrg glEnable( GL_CULL_FACE ); 4932001f49Smrg 5032001f49Smrg glEnable( GL_DEPTH_TEST ); 5132001f49Smrg 5232001f49Smrg glEnableClientState( GL_VERTEX_ARRAY ); 5332001f49Smrg glEnableClientState( GL_COLOR_ARRAY ); 5432001f49Smrg 5532001f49Smrg glMatrixMode( GL_PROJECTION ); 5632001f49Smrg glLoadIdentity(); 5732001f49Smrg glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 ); 5832001f49Smrg glMatrixMode( GL_MODELVIEW ); 5932001f49Smrg glLoadIdentity(); 6032001f49Smrg 6132001f49Smrg glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts ); 6232001f49Smrg glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color ); 6332001f49Smrg 6432001f49Smrg if ( GLEW_EXT_compiled_vertex_array ) { 6532001f49Smrg glLockArraysEXT( 0, 4 ); 6632001f49Smrg } 6732001f49Smrg} 6832001f49Smrg 6932001f49Smrgstatic void display( void ) 7032001f49Smrg{ 7132001f49Smrg glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 7232001f49Smrg 7332001f49Smrg glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices ); 7432001f49Smrg 7532001f49Smrg glFlush(); 7632001f49Smrg if ( doubleBuffer ) { 7732001f49Smrg glutSwapBuffers(); 7832001f49Smrg } 7932001f49Smrg} 8032001f49Smrg 8132001f49Smrgstatic void keyboard( unsigned char key, int x, int y ) 8232001f49Smrg{ 8332001f49Smrg switch ( key ) { 8432001f49Smrg case 27: 8532001f49Smrg exit( 0 ); 8632001f49Smrg break; 8732001f49Smrg } 8832001f49Smrg 8932001f49Smrg glutPostRedisplay(); 9032001f49Smrg} 9132001f49Smrg 9232001f49Smrgstatic GLboolean args( int argc, char **argv ) 9332001f49Smrg{ 9432001f49Smrg GLint i; 9532001f49Smrg 9632001f49Smrg doubleBuffer = GL_TRUE; 9732001f49Smrg 9832001f49Smrg for ( i = 1 ; i < argc ; i++ ) { 9932001f49Smrg if ( strcmp( argv[i], "-sb" ) == 0 ) { 10032001f49Smrg doubleBuffer = GL_FALSE; 10132001f49Smrg } else if ( strcmp( argv[i], "-db" ) == 0 ) { 10232001f49Smrg doubleBuffer = GL_TRUE; 10332001f49Smrg } else { 10432001f49Smrg fprintf( stderr, "%s (Bad option).\n", argv[i] ); 10532001f49Smrg return GL_FALSE; 10632001f49Smrg } 10732001f49Smrg } 10832001f49Smrg return GL_TRUE; 10932001f49Smrg} 11032001f49Smrg 11132001f49Smrgint main( int argc, char **argv ) 11232001f49Smrg{ 11332001f49Smrg GLenum type; 11432001f49Smrg 11532001f49Smrg glutInit( &argc, argv ); 11632001f49Smrg 11732001f49Smrg if ( args( argc, argv ) == GL_FALSE ) { 11832001f49Smrg exit( 1 ); 11932001f49Smrg } 12032001f49Smrg 12132001f49Smrg type = GLUT_RGB | GLUT_DEPTH; 12232001f49Smrg type |= ( doubleBuffer ) ? GLUT_DOUBLE : GLUT_SINGLE; 12332001f49Smrg 12432001f49Smrg glutInitDisplayMode( type ); 12532001f49Smrg glutInitWindowSize( 250, 250 ); 12632001f49Smrg glutInitWindowPosition( 100, 100 ); 12732001f49Smrg glutCreateWindow( "CVA Test" ); 12832001f49Smrg glewInit(); 12932001f49Smrg 13032001f49Smrg /* Make sure the server supports GL 1.2 vertex arrays. 13132001f49Smrg */ 13232001f49Smrg if ( !GLEW_VERSION_1_2 ) { 13332001f49Smrg fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" ); 13432001f49Smrg exit( -1 ); 13532001f49Smrg } 13632001f49Smrg 13732001f49Smrg /* See if the server supports compiled vertex arrays. 13832001f49Smrg */ 13932001f49Smrg if ( !GLEW_EXT_compiled_vertex_array ) { 14032001f49Smrg fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" ); 14132001f49Smrg } 14232001f49Smrg 14332001f49Smrg init(); 14432001f49Smrg 14532001f49Smrg glutDisplayFunc( display ); 14632001f49Smrg glutKeyboardFunc( keyboard ); 14732001f49Smrg glutMainLoop(); 14832001f49Smrg 14932001f49Smrg return 0; 15032001f49Smrg} 151