blob: eff35048f3c04b89d71e3020d96289535dc9d510 [file] [log] [blame]
Brian Paul35d03a62003-01-28 15:31:35 +00001/* $Id: cva.c,v 1.5 2003/01/28 15:31:35 brianp Exp $ */
Gareth Hughes9f568e52000-11-01 03:14:12 +00002
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>
Karl Schultz40fac752002-01-16 01:03:25 +000014#ifdef _WIN32
15#include <windows.h>
16#endif
Gareth Hughes9f568e52000-11-01 03:14:12 +000017#define GL_GLEXT_LEGACY
18#include <GL/glut.h>
19
20
21GLfloat verts[][4] = {
Gareth Hughes5f5632c2000-11-03 00:09:31 +000022 { -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 },
Gareth Hughes78539012000-11-30 03:06:56 +000025 { 0.5, 0.5, -2.0, 0.0 },
Gareth Hughes9f568e52000-11-01 03:14:12 +000026};
27
28GLubyte color[][4] = {
29 { 0xff, 0x00, 0x00, 0x00 },
30 { 0x00, 0xff, 0x00, 0x00 },
31 { 0x00, 0x00, 0xff, 0x00 },
Gareth Hughes78539012000-11-30 03:06:56 +000032 { 0xff, 0xff, 0xff, 0x00 },
Gareth Hughes9f568e52000-11-01 03:14:12 +000033};
34
Gareth Hughes78539012000-11-30 03:06:56 +000035GLuint indices[] = { 0, 1, 2, 3 };
Gareth Hughes9f568e52000-11-01 03:14:12 +000036
37GLboolean compiled = GL_TRUE;
Gareth Hughes78539012000-11-30 03:06:56 +000038GLboolean doubleBuffer = GL_TRUE;
Gareth Hughes9f568e52000-11-01 03:14:12 +000039
40
41void init( void )
42{
43 glClearColor( 0.0, 0.0, 0.0, 0.0 );
44 glShadeModel( GL_SMOOTH );
45
Gareth Hughes78539012000-11-30 03:06:56 +000046 glFrontFace( GL_CCW );
47 glCullFace( GL_BACK );
48 glEnable( GL_CULL_FACE );
49
Gareth Hughes9f568e52000-11-01 03:14:12 +000050 glEnable( GL_DEPTH_TEST );
51
52 glEnableClientState( GL_VERTEX_ARRAY );
53 glEnableClientState( GL_COLOR_ARRAY );
54
55 glMatrixMode( GL_PROJECTION );
56 glLoadIdentity();
Gareth Hughes5f5632c2000-11-03 00:09:31 +000057 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
Gareth Hughes9f568e52000-11-01 03:14:12 +000058 glMatrixMode( GL_MODELVIEW );
Gareth Hughes5f5632c2000-11-03 00:09:31 +000059 glLoadIdentity();
Gareth Hughes9f568e52000-11-01 03:14:12 +000060
61 glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );
62 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
63
64#ifdef GL_EXT_compiled_vertex_array
65 if ( compiled ) {
Gareth Hughes78539012000-11-30 03:06:56 +000066 glLockArraysEXT( 0, 4 );
Gareth Hughes9f568e52000-11-01 03:14:12 +000067 }
68#endif
69}
70
71void display( void )
72{
73 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
74
75 glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
76
77 glFlush();
Gareth Hughes78539012000-11-30 03:06:56 +000078 if ( doubleBuffer ) {
79 glutSwapBuffers();
80 }
Gareth Hughes9f568e52000-11-01 03:14:12 +000081}
82
83void keyboard( unsigned char key, int x, int y )
84{
85 switch ( key ) {
86 case 27:
87 exit( 0 );
88 break;
89 }
Gareth Hughes78539012000-11-30 03:06:56 +000090
91 glutPostRedisplay();
92}
93
94GLboolean args( int argc, char **argv )
95{
96 GLint i;
97
98 doubleBuffer = GL_TRUE;
99
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;
105 } else {
106 fprintf( stderr, "%s (Bad option).\n", argv[i] );
107 return GL_FALSE;
108 }
109 }
110 return GL_TRUE;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000111}
112
113int main( int argc, char **argv )
114{
Gareth Hughes78539012000-11-30 03:06:56 +0000115 GLenum type;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000116 char *string;
117
118 glutInit( &argc, argv );
Gareth Hughes78539012000-11-30 03:06:56 +0000119
120 if ( args( argc, argv ) == GL_FALSE ) {
121 exit( 1 );
122 }
123
124 type = GLUT_RGB | GLUT_DEPTH;
125 type |= ( doubleBuffer ) ? GLUT_DOUBLE : GLUT_SINGLE;
126
127 glutInitDisplayMode( type );
Gareth Hughes9f568e52000-11-01 03:14:12 +0000128 glutInitWindowSize( 250, 250 );
129 glutInitWindowPosition( 100, 100 );
130 glutCreateWindow( "CVA Test" );
131
132 /* Make sure the server supports GL 1.2 vertex arrays.
133 */
134 string = (char *) glGetString( GL_VERSION );
135
Brian Paul35d03a62003-01-28 15:31:35 +0000136 if ( !strstr(string, "1.2") &&
137 !strstr(string, "1.3") &&
138 !strstr(string, "1.4")) {
Gareth Hughes9f568e52000-11-01 03:14:12 +0000139 fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" );
140 exit( -1 );
141 }
142
143 /* See if the server supports compiled vertex arrays.
144 */
145 string = (char *) glGetString( GL_EXTENSIONS );
146
147 if ( !strstr( string, "GL_EXT_compiled_vertex_array" ) ) {
148 fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" );
149 compiled = GL_FALSE;
150 }
151
152 init();
153
154 glutDisplayFunc( display );
155 glutKeyboardFunc( keyboard );
156 glutMainLoop();
157
158 return 0;
159}