1 /* $Id: cva.c,v 1.7 2003/12/08 09:03:35 joukj Exp $ */
4 * Trivial CVA test, good for testing driver fastpaths (especially
5 * indexed vertex buffers if they are supported).
15 # include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
17 # include <malloc.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
22 #define GL_GLEXT_LEGACY
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 },
33 GLubyte color
[][4] = {
34 { 0xff, 0x00, 0x00, 0x00 },
35 { 0x00, 0xff, 0x00, 0x00 },
36 { 0x00, 0x00, 0xff, 0x00 },
37 { 0xff, 0xff, 0xff, 0x00 },
40 GLuint indices
[] = { 0, 1, 2, 3 };
42 GLboolean compiled
= GL_TRUE
;
43 GLboolean doubleBuffer
= GL_TRUE
;
48 glClearColor( 0.0, 0.0, 0.0, 0.0 );
49 glShadeModel( GL_SMOOTH
);
51 glFrontFace( GL_CCW
);
52 glCullFace( GL_BACK
);
53 glEnable( GL_CULL_FACE
);
55 glEnable( GL_DEPTH_TEST
);
57 glEnableClientState( GL_VERTEX_ARRAY
);
58 glEnableClientState( GL_COLOR_ARRAY
);
60 glMatrixMode( GL_PROJECTION
);
62 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
63 glMatrixMode( GL_MODELVIEW
);
66 glVertexPointer( 3, GL_FLOAT
, sizeof(verts
[0]), verts
);
67 glColorPointer( 4, GL_UNSIGNED_BYTE
, 0, color
);
69 #ifdef GL_EXT_compiled_vertex_array
71 glLockArraysEXT( 0, 4 );
78 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
80 glDrawElements( GL_TRIANGLES
, 3, GL_UNSIGNED_INT
, indices
);
88 void keyboard( unsigned char key
, int x
, int y
)
99 GLboolean
args( int argc
, char **argv
)
103 doubleBuffer
= GL_TRUE
;
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
;
111 fprintf( stderr
, "%s (Bad option).\n", argv
[i
] );
118 int main( int argc
, char **argv
)
123 glutInit( &argc
, argv
);
125 if ( args( argc
, argv
) == GL_FALSE
) {
129 type
= GLUT_RGB
| GLUT_DEPTH
;
130 type
|= ( doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
132 glutInitDisplayMode( type
);
133 glutInitWindowSize( 250, 250 );
134 glutInitWindowPosition( 100, 100 );
135 glutCreateWindow( "CVA Test" );
137 /* Make sure the server supports GL 1.2 vertex arrays.
139 string
= (char *) glGetString( GL_VERSION
);
141 if ( !strstr(string
, "1.2") &&
142 !strstr(string
, "1.3") &&
143 !strstr(string
, "1.4")) {
144 fprintf( stderr
, "This program requires OpenGL 1.2 vertex arrays.\n" );
148 /* See if the server supports compiled vertex arrays.
150 string
= (char *) glGetString( GL_EXTENSIONS
);
152 if ( !strstr( string
, "GL_EXT_compiled_vertex_array" ) ) {
153 fprintf( stderr
, "Compiled vertex arrays not supported by this renderer.\n" );
159 glutDisplayFunc( display
);
160 glutKeyboardFunc( keyboard
);