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