3 * Trivial CVA test, good for testing driver fastpaths (especially
4 * indexed vertex buffers if they are supported).
13 #include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
17 #define GL_GLEXT_LEGACY
21 GLfloat verts
[][4] = {
22 { -0.5, -0.5, -2.0, 0.0 },
23 { 0.5, -0.5, -2.0, 0.0 },
24 { -0.5, 0.5, -2.0, 0.0 },
25 { 0.5, 0.5, -2.0, 0.0 },
28 GLubyte color
[][4] = {
29 { 0xff, 0x00, 0x00, 0x00 },
30 { 0x00, 0xff, 0x00, 0x00 },
31 { 0x00, 0x00, 0xff, 0x00 },
32 { 0xff, 0xff, 0xff, 0x00 },
35 GLuint indices
[] = { 0, 1, 2, 3 };
37 GLboolean compiled
= GL_TRUE
;
38 GLboolean doubleBuffer
= GL_TRUE
;
43 glClearColor( 0.0, 0.0, 0.0, 0.0 );
44 glShadeModel( GL_SMOOTH
);
46 glFrontFace( GL_CCW
);
47 glCullFace( GL_BACK
);
48 glEnable( GL_CULL_FACE
);
50 glEnable( GL_DEPTH_TEST
);
52 glEnableClientState( GL_VERTEX_ARRAY
);
53 glEnableClientState( GL_COLOR_ARRAY
);
55 glMatrixMode( GL_PROJECTION
);
57 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
58 glMatrixMode( GL_MODELVIEW
);
61 glVertexPointer( 3, GL_FLOAT
, sizeof(verts
[0]), verts
);
62 glColorPointer( 4, GL_UNSIGNED_BYTE
, 0, color
);
64 #ifdef GL_EXT_compiled_vertex_array
66 glLockArraysEXT( 0, 4 );
73 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
75 glDrawElements( GL_TRIANGLES
, 3, GL_UNSIGNED_INT
, indices
);
83 void keyboard( unsigned char key
, int x
, int y
)
94 GLboolean
args( int argc
, char **argv
)
98 doubleBuffer
= GL_TRUE
;
100 for ( i
= 1 ; i
< argc
; i
++ ) {
101 if ( strcmp( argv
[i
], "-sb" ) == 0 ) {
102 doubleBuffer
= GL_FALSE
;
103 } else if ( strcmp( argv
[i
], "-db" ) == 0 ) {
104 doubleBuffer
= GL_TRUE
;
106 fprintf( stderr
, "%s (Bad option).\n", argv
[i
] );
113 int main( int argc
, char **argv
)
119 glutInit( &argc
, argv
);
121 if ( args( argc
, argv
) == GL_FALSE
) {
125 type
= GLUT_RGB
| GLUT_DEPTH
;
126 type
|= ( doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
128 glutInitDisplayMode( type
);
129 glutInitWindowSize( 250, 250 );
130 glutInitWindowPosition( 100, 100 );
131 glutCreateWindow( "CVA Test" );
133 /* Make sure the server supports GL 1.2 vertex arrays.
135 string
= (char *) glGetString( GL_VERSION
);
137 version
= atof(string
);
138 if ( version
< 1.2 ) {
139 fprintf( stderr
, "This program requires OpenGL 1.2 vertex arrays.\n" );
143 /* See if the server supports compiled vertex arrays.
145 string
= (char *) glGetString( GL_EXTENSIONS
);
147 if ( !strstr( string
, "GL_EXT_compiled_vertex_array" ) ) {
148 fprintf( stderr
, "Compiled vertex arrays not supported by this renderer.\n" );
154 glutDisplayFunc( display
);
155 glutKeyboardFunc( keyboard
);