fix the gl version test
[mesa.git] / progs / tests / cva.c
1 /* $Id: cva.c,v 1.8 2006/11/22 19:37:21 sroland 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 #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
19 #ifdef _WIN32
20 #include <windows.h>
21 #endif
22 #define GL_GLEXT_LEGACY
23 #include <GL/glut.h>
24
25
26 GLfloat verts[][4] = {
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 },
30 { 0.5, 0.5, -2.0, 0.0 },
31 };
32
33 GLubyte color[][4] = {
34 { 0xff, 0x00, 0x00, 0x00 },
35 { 0x00, 0xff, 0x00, 0x00 },
36 { 0x00, 0x00, 0xff, 0x00 },
37 { 0xff, 0xff, 0xff, 0x00 },
38 };
39
40 GLuint indices[] = { 0, 1, 2, 3 };
41
42 GLboolean compiled = GL_TRUE;
43 GLboolean doubleBuffer = GL_TRUE;
44
45
46 void init( void )
47 {
48 glClearColor( 0.0, 0.0, 0.0, 0.0 );
49 glShadeModel( GL_SMOOTH );
50
51 glFrontFace( GL_CCW );
52 glCullFace( GL_BACK );
53 glEnable( GL_CULL_FACE );
54
55 glEnable( GL_DEPTH_TEST );
56
57 glEnableClientState( GL_VERTEX_ARRAY );
58 glEnableClientState( GL_COLOR_ARRAY );
59
60 glMatrixMode( GL_PROJECTION );
61 glLoadIdentity();
62 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
63 glMatrixMode( GL_MODELVIEW );
64 glLoadIdentity();
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 ) {
71 glLockArraysEXT( 0, 4 );
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();
83 if ( doubleBuffer ) {
84 glutSwapBuffers();
85 }
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 }
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;
116 }
117
118 int main( int argc, char **argv )
119 {
120 GLenum type;
121 char *string;
122 double version;
123
124 glutInit( &argc, argv );
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 );
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
142 version = atof(string);
143 if ( version < 1.2 ) {
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 }