3 * Trivial CVA test, good for testing driver fastpaths (especially
4 * indexed vertex buffers if they are supported).
14 # include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
16 # include <malloc.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
21 #define GL_GLEXT_LEGACY
25 GLfloat verts
[][4] = {
26 { -0.5, -0.5, -2.0, 0.0 },
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 },
32 GLubyte color
[][4] = {
33 { 0xff, 0x00, 0x00, 0x00 },
34 { 0x00, 0xff, 0x00, 0x00 },
35 { 0x00, 0x00, 0xff, 0x00 },
36 { 0xff, 0xff, 0xff, 0x00 },
39 GLuint indices
[] = { 0, 1, 2, 3 };
41 GLboolean compiled
= GL_TRUE
;
42 GLboolean doubleBuffer
= GL_TRUE
;
47 glClearColor( 0.0, 0.0, 0.0, 0.0 );
48 glShadeModel( GL_SMOOTH
);
50 glFrontFace( GL_CCW
);
51 glCullFace( GL_BACK
);
52 glEnable( GL_CULL_FACE
);
54 glEnable( GL_DEPTH_TEST
);
56 glEnableClientState( GL_VERTEX_ARRAY
);
57 glEnableClientState( GL_COLOR_ARRAY
);
59 glMatrixMode( GL_PROJECTION
);
61 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
62 glMatrixMode( GL_MODELVIEW
);
65 glVertexPointer( 3, GL_FLOAT
, sizeof(verts
[0]), verts
);
66 glColorPointer( 4, GL_UNSIGNED_BYTE
, 0, color
);
68 #ifdef GL_EXT_compiled_vertex_array
70 glLockArraysEXT( 0, 4 );
77 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
79 glDrawElements( GL_TRIANGLES
, 3, GL_UNSIGNED_INT
, indices
);
87 void keyboard( unsigned char key
, int x
, int y
)
98 GLboolean
args( int argc
, char **argv
)
102 doubleBuffer
= GL_TRUE
;
104 for ( i
= 1 ; i
< argc
; i
++ ) {
105 if ( strcmp( argv
[i
], "-sb" ) == 0 ) {
106 doubleBuffer
= GL_FALSE
;
107 } else if ( strcmp( argv
[i
], "-db" ) == 0 ) {
108 doubleBuffer
= GL_TRUE
;
110 fprintf( stderr
, "%s (Bad option).\n", argv
[i
] );
117 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 version
= atof(string
);
142 if ( version
< 1.2 ) {
143 fprintf( stderr
, "This program requires OpenGL 1.2 vertex arrays.\n" );
147 /* See if the server supports compiled vertex arrays.
149 string
= (char *) glGetString( GL_EXTENSIONS
);
151 if ( !strstr( string
, "GL_EXT_compiled_vertex_array" ) ) {
152 fprintf( stderr
, "Compiled vertex arrays not supported by this renderer.\n" );
158 glutDisplayFunc( display
);
159 glutKeyboardFunc( keyboard
);