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