blob: c6292f490f5a03394a09c536fb5cdc93099a71ed [file] [log] [blame]
Gareth Hughes78539012000-11-30 03:06:56 +00001/* $Id: cva.c,v 1.3 2000/11/30 03:06:56 gareth 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>
14#define GL_GLEXT_LEGACY
15#include <GL/glut.h>
16
17
18GLfloat verts[][4] = {
Gareth Hughes5f5632c2000-11-03 00:09:31 +000019 { -0.5, -0.5, -2.0, 0.0 },
20 { 0.5, -0.5, -2.0, 0.0 },
21 { -0.5, 0.5, -2.0, 0.0 },
Gareth Hughes78539012000-11-30 03:06:56 +000022 { 0.5, 0.5, -2.0, 0.0 },
Gareth Hughes9f568e52000-11-01 03:14:12 +000023};
24
25GLubyte color[][4] = {
26 { 0xff, 0x00, 0x00, 0x00 },
27 { 0x00, 0xff, 0x00, 0x00 },
28 { 0x00, 0x00, 0xff, 0x00 },
Gareth Hughes78539012000-11-30 03:06:56 +000029 { 0xff, 0xff, 0xff, 0x00 },
Gareth Hughes9f568e52000-11-01 03:14:12 +000030};
31
Gareth Hughes78539012000-11-30 03:06:56 +000032GLuint indices[] = { 0, 1, 2, 3 };
Gareth Hughes9f568e52000-11-01 03:14:12 +000033
34GLboolean compiled = GL_TRUE;
Gareth Hughes78539012000-11-30 03:06:56 +000035GLboolean doubleBuffer = GL_TRUE;
Gareth Hughes9f568e52000-11-01 03:14:12 +000036
37
38void init( void )
39{
40 glClearColor( 0.0, 0.0, 0.0, 0.0 );
41 glShadeModel( GL_SMOOTH );
42
Gareth Hughes78539012000-11-30 03:06:56 +000043 glFrontFace( GL_CCW );
44 glCullFace( GL_BACK );
45 glEnable( GL_CULL_FACE );
46
Gareth Hughes9f568e52000-11-01 03:14:12 +000047 glEnable( GL_DEPTH_TEST );
48
49 glEnableClientState( GL_VERTEX_ARRAY );
50 glEnableClientState( GL_COLOR_ARRAY );
51
52 glMatrixMode( GL_PROJECTION );
53 glLoadIdentity();
Gareth Hughes5f5632c2000-11-03 00:09:31 +000054 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
Gareth Hughes9f568e52000-11-01 03:14:12 +000055 glMatrixMode( GL_MODELVIEW );
Gareth Hughes5f5632c2000-11-03 00:09:31 +000056 glLoadIdentity();
Gareth Hughes9f568e52000-11-01 03:14:12 +000057
58 glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );
59 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
60
61#ifdef GL_EXT_compiled_vertex_array
62 if ( compiled ) {
Gareth Hughes78539012000-11-30 03:06:56 +000063 glLockArraysEXT( 0, 4 );
Gareth Hughes9f568e52000-11-01 03:14:12 +000064 }
65#endif
66}
67
68void display( void )
69{
70 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
71
72 glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
73
74 glFlush();
Gareth Hughes78539012000-11-30 03:06:56 +000075 if ( doubleBuffer ) {
76 glutSwapBuffers();
77 }
Gareth Hughes9f568e52000-11-01 03:14:12 +000078}
79
80void keyboard( unsigned char key, int x, int y )
81{
82 switch ( key ) {
83 case 27:
84 exit( 0 );
85 break;
86 }
Gareth Hughes78539012000-11-30 03:06:56 +000087
88 glutPostRedisplay();
89}
90
91GLboolean args( int argc, char **argv )
92{
93 GLint i;
94
95 doubleBuffer = GL_TRUE;
96
97 for ( i = 1 ; i < argc ; i++ ) {
98 if ( strcmp( argv[i], "-sb" ) == 0 ) {
99 doubleBuffer = GL_FALSE;
100 } else if ( strcmp( argv[i], "-db" ) == 0 ) {
101 doubleBuffer = GL_TRUE;
102 } else {
103 fprintf( stderr, "%s (Bad option).\n", argv[i] );
104 return GL_FALSE;
105 }
106 }
107 return GL_TRUE;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000108}
109
110int main( int argc, char **argv )
111{
Gareth Hughes78539012000-11-30 03:06:56 +0000112 GLenum type;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000113 char *string;
114
115 glutInit( &argc, argv );
Gareth Hughes78539012000-11-30 03:06:56 +0000116
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 );
Gareth Hughes9f568e52000-11-01 03:14:12 +0000125 glutInitWindowSize( 250, 250 );
126 glutInitWindowPosition( 100, 100 );
127 glutCreateWindow( "CVA Test" );
128
129 /* Make sure the server supports GL 1.2 vertex arrays.
130 */
131 string = (char *) glGetString( GL_VERSION );
132
133 if ( !strstr( string, "1.2" ) ) {
134 fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" );
135 exit( -1 );
136 }
137
138 /* See if the server supports compiled vertex arrays.
139 */
140 string = (char *) glGetString( GL_EXTENSIONS );
141
142 if ( !strstr( string, "GL_EXT_compiled_vertex_array" ) ) {
143 fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" );
144 compiled = GL_FALSE;
145 }
146
147 init();
148
149 glutDisplayFunc( display );
150 glutKeyboardFunc( keyboard );
151 glutMainLoop();
152
153 return 0;
154}