Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Trivial CVA test, good for testing driver fastpaths (especially |
| 4 | * indexed vertex buffers if they are supported). |
| 5 | * |
| 6 | * Gareth Hughes |
| 7 | * November 2000 |
| 8 | */ |
| 9 | |
| 10 | #include <stdlib.h> |
| 11 | #include <stdio.h> |
| 12 | #include <string.h> |
Eric Anholt | 9bb0d62 | 2007-09-24 10:22:31 -0700 | [diff] [blame] | 13 | #include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */ |
Karl Schultz | 40fac75 | 2002-01-16 01:03:25 +0000 | [diff] [blame] | 14 | #ifdef _WIN32 |
| 15 | #include <windows.h> |
| 16 | #endif |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 17 | #define GL_GLEXT_LEGACY |
| 18 | #include <GL/glut.h> |
Eric Anholt | 745df74 | 2008-02-03 01:04:46 -0800 | [diff] [blame] | 19 | #include <GL/glext.h> |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 20 | |
| 21 | GLfloat verts[][4] = { |
Gareth Hughes | 5f5632c | 2000-11-03 00:09:31 +0000 | [diff] [blame] | 22 | { -0.5, -0.5, -2.0, 0.0 }, |
| 23 | { 0.5, -0.5, -2.0, 0.0 }, |
| 24 | { -0.5, 0.5, -2.0, 0.0 }, |
Gareth Hughes | 7853901 | 2000-11-30 03:06:56 +0000 | [diff] [blame] | 25 | { 0.5, 0.5, -2.0, 0.0 }, |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | GLubyte color[][4] = { |
| 29 | { 0xff, 0x00, 0x00, 0x00 }, |
| 30 | { 0x00, 0xff, 0x00, 0x00 }, |
| 31 | { 0x00, 0x00, 0xff, 0x00 }, |
Gareth Hughes | 7853901 | 2000-11-30 03:06:56 +0000 | [diff] [blame] | 32 | { 0xff, 0xff, 0xff, 0x00 }, |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
Gareth Hughes | 7853901 | 2000-11-30 03:06:56 +0000 | [diff] [blame] | 35 | GLuint indices[] = { 0, 1, 2, 3 }; |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 36 | |
| 37 | GLboolean compiled = GL_TRUE; |
Gareth Hughes | 7853901 | 2000-11-30 03:06:56 +0000 | [diff] [blame] | 38 | GLboolean doubleBuffer = GL_TRUE; |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 39 | |
| 40 | |
| 41 | void init( void ) |
| 42 | { |
| 43 | glClearColor( 0.0, 0.0, 0.0, 0.0 ); |
| 44 | glShadeModel( GL_SMOOTH ); |
| 45 | |
Gareth Hughes | 7853901 | 2000-11-30 03:06:56 +0000 | [diff] [blame] | 46 | glFrontFace( GL_CCW ); |
| 47 | glCullFace( GL_BACK ); |
| 48 | glEnable( GL_CULL_FACE ); |
| 49 | |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 50 | glEnable( GL_DEPTH_TEST ); |
| 51 | |
| 52 | glEnableClientState( GL_VERTEX_ARRAY ); |
| 53 | glEnableClientState( GL_COLOR_ARRAY ); |
| 54 | |
| 55 | glMatrixMode( GL_PROJECTION ); |
| 56 | glLoadIdentity(); |
Gareth Hughes | 5f5632c | 2000-11-03 00:09:31 +0000 | [diff] [blame] | 57 | glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 ); |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 58 | glMatrixMode( GL_MODELVIEW ); |
Gareth Hughes | 5f5632c | 2000-11-03 00:09:31 +0000 | [diff] [blame] | 59 | glLoadIdentity(); |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 60 | |
| 61 | glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts ); |
| 62 | glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color ); |
| 63 | |
| 64 | #ifdef GL_EXT_compiled_vertex_array |
| 65 | if ( compiled ) { |
Gareth Hughes | 7853901 | 2000-11-30 03:06:56 +0000 | [diff] [blame] | 66 | glLockArraysEXT( 0, 4 ); |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 67 | } |
| 68 | #endif |
| 69 | } |
| 70 | |
| 71 | void display( void ) |
| 72 | { |
| 73 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
| 74 | |
| 75 | glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices ); |
| 76 | |
| 77 | glFlush(); |
Gareth Hughes | 7853901 | 2000-11-30 03:06:56 +0000 | [diff] [blame] | 78 | if ( doubleBuffer ) { |
| 79 | glutSwapBuffers(); |
| 80 | } |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void keyboard( unsigned char key, int x, int y ) |
| 84 | { |
| 85 | switch ( key ) { |
| 86 | case 27: |
| 87 | exit( 0 ); |
| 88 | break; |
| 89 | } |
Gareth Hughes | 7853901 | 2000-11-30 03:06:56 +0000 | [diff] [blame] | 90 | |
| 91 | glutPostRedisplay(); |
| 92 | } |
| 93 | |
| 94 | GLboolean args( int argc, char **argv ) |
| 95 | { |
| 96 | GLint i; |
| 97 | |
| 98 | doubleBuffer = GL_TRUE; |
| 99 | |
| 100 | for ( i = 1 ; i < argc ; i++ ) { |
| 101 | if ( strcmp( argv[i], "-sb" ) == 0 ) { |
| 102 | doubleBuffer = GL_FALSE; |
| 103 | } else if ( strcmp( argv[i], "-db" ) == 0 ) { |
| 104 | doubleBuffer = GL_TRUE; |
| 105 | } else { |
| 106 | fprintf( stderr, "%s (Bad option).\n", argv[i] ); |
| 107 | return GL_FALSE; |
| 108 | } |
| 109 | } |
| 110 | return GL_TRUE; |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | int main( int argc, char **argv ) |
| 114 | { |
Gareth Hughes | 7853901 | 2000-11-30 03:06:56 +0000 | [diff] [blame] | 115 | GLenum type; |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 116 | char *string; |
Roland Scheidegger | 22b74ff | 2006-11-22 19:37:21 +0000 | [diff] [blame] | 117 | double version; |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 118 | |
| 119 | glutInit( &argc, argv ); |
Gareth Hughes | 7853901 | 2000-11-30 03:06:56 +0000 | [diff] [blame] | 120 | |
| 121 | if ( args( argc, argv ) == GL_FALSE ) { |
| 122 | exit( 1 ); |
| 123 | } |
| 124 | |
| 125 | type = GLUT_RGB | GLUT_DEPTH; |
| 126 | type |= ( doubleBuffer ) ? GLUT_DOUBLE : GLUT_SINGLE; |
| 127 | |
| 128 | glutInitDisplayMode( type ); |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 129 | glutInitWindowSize( 250, 250 ); |
| 130 | glutInitWindowPosition( 100, 100 ); |
| 131 | glutCreateWindow( "CVA Test" ); |
| 132 | |
| 133 | /* Make sure the server supports GL 1.2 vertex arrays. |
| 134 | */ |
| 135 | string = (char *) glGetString( GL_VERSION ); |
| 136 | |
Roland Scheidegger | 22b74ff | 2006-11-22 19:37:21 +0000 | [diff] [blame] | 137 | version = atof(string); |
| 138 | if ( version < 1.2 ) { |
Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 139 | fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" ); |
| 140 | exit( -1 ); |
| 141 | } |
| 142 | |
| 143 | /* See if the server supports compiled vertex arrays. |
| 144 | */ |
| 145 | string = (char *) glGetString( GL_EXTENSIONS ); |
| 146 | |
| 147 | if ( !strstr( string, "GL_EXT_compiled_vertex_array" ) ) { |
| 148 | fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" ); |
| 149 | compiled = GL_FALSE; |
| 150 | } |
| 151 | |
| 152 | init(); |
| 153 | |
| 154 | glutDisplayFunc( display ); |
| 155 | glutKeyboardFunc( keyboard ); |
| 156 | glutMainLoop(); |
| 157 | |
| 158 | return 0; |
| 159 | } |