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