Gareth Hughes | 9f568e5 | 2000-11-01 03:14:12 +0000 | [diff] [blame] | 1 | /* $Id: cva.c,v 1.1 2000/11/01 03:14:12 gareth Exp $ */ |
| 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] = { |
| 19 | { 0.25, 0.25, 0.0, 0.0 }, |
| 20 | { 0.75, 0.25, 0.0, 0.0 }, |
| 21 | { 0.25, 0.75, 0.0, 0.0 }, |
| 22 | }; |
| 23 | |
| 24 | GLubyte color[][4] = { |
| 25 | { 0xff, 0x00, 0x00, 0x00 }, |
| 26 | { 0x00, 0xff, 0x00, 0x00 }, |
| 27 | { 0x00, 0x00, 0xff, 0x00 }, |
| 28 | }; |
| 29 | |
| 30 | GLuint indices[] = { 0, 1, 2 }; |
| 31 | |
| 32 | GLboolean compiled = GL_TRUE; |
| 33 | |
| 34 | |
| 35 | void init( void ) |
| 36 | { |
| 37 | glClearColor( 0.0, 0.0, 0.0, 0.0 ); |
| 38 | glShadeModel( GL_SMOOTH ); |
| 39 | |
| 40 | glEnable( GL_DEPTH_TEST ); |
| 41 | |
| 42 | glEnableClientState( GL_VERTEX_ARRAY ); |
| 43 | glEnableClientState( GL_COLOR_ARRAY ); |
| 44 | |
| 45 | glMatrixMode( GL_PROJECTION ); |
| 46 | glLoadIdentity(); |
| 47 | glOrtho( 0.0, 1.0, 0.0, 1.0, -1.0, 1.0 ); |
| 48 | glMatrixMode( GL_MODELVIEW ); |
| 49 | |
| 50 | glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts ); |
| 51 | glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color ); |
| 52 | |
| 53 | #ifdef GL_EXT_compiled_vertex_array |
| 54 | if ( compiled ) { |
| 55 | glLockArraysEXT( 0, 3 ); |
| 56 | } |
| 57 | #endif |
| 58 | } |
| 59 | |
| 60 | void display( void ) |
| 61 | { |
| 62 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
| 63 | |
| 64 | glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices ); |
| 65 | |
| 66 | glFlush(); |
| 67 | } |
| 68 | |
| 69 | void keyboard( unsigned char key, int x, int y ) |
| 70 | { |
| 71 | switch ( key ) { |
| 72 | case 27: |
| 73 | exit( 0 ); |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | int main( int argc, char **argv ) |
| 79 | { |
| 80 | char *string; |
| 81 | |
| 82 | glutInit( &argc, argv ); |
| 83 | glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH ); |
| 84 | glutInitWindowSize( 250, 250 ); |
| 85 | glutInitWindowPosition( 100, 100 ); |
| 86 | glutCreateWindow( "CVA Test" ); |
| 87 | |
| 88 | /* Make sure the server supports GL 1.2 vertex arrays. |
| 89 | */ |
| 90 | string = (char *) glGetString( GL_VERSION ); |
| 91 | |
| 92 | if ( !strstr( string, "1.2" ) ) { |
| 93 | fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" ); |
| 94 | exit( -1 ); |
| 95 | } |
| 96 | |
| 97 | /* See if the server supports compiled vertex arrays. |
| 98 | */ |
| 99 | string = (char *) glGetString( GL_EXTENSIONS ); |
| 100 | |
| 101 | if ( !strstr( string, "GL_EXT_compiled_vertex_array" ) ) { |
| 102 | fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" ); |
| 103 | compiled = GL_FALSE; |
| 104 | } |
| 105 | |
| 106 | init(); |
| 107 | |
| 108 | glutDisplayFunc( display ); |
| 109 | glutKeyboardFunc( keyboard ); |
| 110 | glutMainLoop(); |
| 111 | |
| 112 | return 0; |
| 113 | } |