1
2/*
3 * Trivial CVA test, good for testing driver fastpaths (especially
4 * indexed vertex buffers if they are supported).
5 *
6 * Gareth Hughes
7 * November 2000
8 */
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <string.h>
13#include <stddef.h>	/* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
14#ifdef _WIN32
15#include <windows.h>
16#endif
17#define GL_GLEXT_LEGACY
18#include <GL/glew.h>
19#include "glut_wrap.h"
20
21GLfloat 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 },
26};
27
28GLubyte color[][4] = {
29   { 0xff, 0x00, 0x00, 0x00 },
30   { 0x00, 0xff, 0x00, 0x00 },
31   { 0x00, 0x00, 0xff, 0x00 },
32   { 0xff, 0xff, 0xff, 0x00 },
33};
34
35GLuint indices[] = { 0, 1, 2, 3 };
36
37GLboolean compiled = GL_TRUE;
38GLboolean doubleBuffer = GL_TRUE;
39
40
41static void init( void )
42{
43   glClearColor( 0.0, 0.0, 0.0, 0.0 );
44   glShadeModel( GL_SMOOTH );
45
46   glFrontFace( GL_CCW );
47   glCullFace( GL_BACK );
48   glEnable( GL_CULL_FACE );
49
50   glEnable( GL_DEPTH_TEST );
51
52   glEnableClientState( GL_VERTEX_ARRAY );
53   glEnableClientState( GL_COLOR_ARRAY );
54
55   glMatrixMode( GL_PROJECTION );
56   glLoadIdentity();
57   glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
58   glMatrixMode( GL_MODELVIEW );
59   glLoadIdentity();
60
61   glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );
62   glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
63
64   if ( GLEW_EXT_compiled_vertex_array ) {
65      glLockArraysEXT( 0, 4 );
66   }
67}
68
69static void display( void )
70{
71   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
72
73   glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
74
75   glFlush();
76   if ( doubleBuffer ) {
77      glutSwapBuffers();
78   }
79}
80
81static void keyboard( unsigned char key, int x, int y )
82{
83   switch ( key ) {
84      case 27:
85         exit( 0 );
86         break;
87   }
88
89   glutPostRedisplay();
90}
91
92static GLboolean args( int argc, char **argv )
93{
94    GLint i;
95
96    doubleBuffer = GL_TRUE;
97
98    for ( i = 1 ; i < argc ; i++ ) {
99	if ( strcmp( argv[i], "-sb" ) == 0 ) {
100	    doubleBuffer = GL_FALSE;
101	} else if ( strcmp( argv[i], "-db" ) == 0 ) {
102	    doubleBuffer = GL_TRUE;
103	} else {
104	    fprintf( stderr, "%s (Bad option).\n", argv[i] );
105	    return GL_FALSE;
106	}
107    }
108    return GL_TRUE;
109}
110
111int main( int argc, char **argv )
112{
113   GLenum type;
114
115   glutInit( &argc, argv );
116
117   if ( args( argc, argv ) == GL_FALSE ) {
118      exit( 1 );
119   }
120
121   type = GLUT_RGB | GLUT_DEPTH;
122   type |= ( doubleBuffer ) ? GLUT_DOUBLE : GLUT_SINGLE;
123
124   glutInitDisplayMode( type );
125   glutInitWindowSize( 250, 250 );
126   glutInitWindowPosition( 100, 100 );
127   glutCreateWindow( "CVA Test" );
128   glewInit();
129
130   /* Make sure the server supports GL 1.2 vertex arrays.
131    */
132   if ( !GLEW_VERSION_1_2 ) {
133      fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" );
134      exit( -1 );
135   }
136
137   /* See if the server supports compiled vertex arrays.
138    */
139   if ( !GLEW_EXT_compiled_vertex_array ) {
140      fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" );
141   }
142
143   init();
144
145   glutDisplayFunc( display );
146   glutKeyboardFunc( keyboard );
147   glutMainLoop();
148
149   return 0;
150}
151