blob: c7677990bffef4ee187f016feca65fed584e6568 [file] [log] [blame]
Roland Scheidegger22b74ff2006-11-22 19:37:21 +00001/* $Id: cva.c,v 1.8 2006/11/22 19:37:21 sroland 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>
Jouk Jansen58f88a22003-12-08 09:03:35 +000014#ifdef __VMS
15# include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
16#else
17# include <malloc.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
18#endif
Karl Schultz40fac752002-01-16 01:03:25 +000019#ifdef _WIN32
20#include <windows.h>
21#endif
Gareth Hughes9f568e52000-11-01 03:14:12 +000022#define GL_GLEXT_LEGACY
23#include <GL/glut.h>
24
25
26GLfloat verts[][4] = {
Gareth Hughes5f5632c2000-11-03 00:09:31 +000027 { -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 },
Gareth Hughes78539012000-11-30 03:06:56 +000030 { 0.5, 0.5, -2.0, 0.0 },
Gareth Hughes9f568e52000-11-01 03:14:12 +000031};
32
33GLubyte color[][4] = {
34 { 0xff, 0x00, 0x00, 0x00 },
35 { 0x00, 0xff, 0x00, 0x00 },
36 { 0x00, 0x00, 0xff, 0x00 },
Gareth Hughes78539012000-11-30 03:06:56 +000037 { 0xff, 0xff, 0xff, 0x00 },
Gareth Hughes9f568e52000-11-01 03:14:12 +000038};
39
Gareth Hughes78539012000-11-30 03:06:56 +000040GLuint indices[] = { 0, 1, 2, 3 };
Gareth Hughes9f568e52000-11-01 03:14:12 +000041
42GLboolean compiled = GL_TRUE;
Gareth Hughes78539012000-11-30 03:06:56 +000043GLboolean doubleBuffer = GL_TRUE;
Gareth Hughes9f568e52000-11-01 03:14:12 +000044
45
46void init( void )
47{
48 glClearColor( 0.0, 0.0, 0.0, 0.0 );
49 glShadeModel( GL_SMOOTH );
50
Gareth Hughes78539012000-11-30 03:06:56 +000051 glFrontFace( GL_CCW );
52 glCullFace( GL_BACK );
53 glEnable( GL_CULL_FACE );
54
Gareth Hughes9f568e52000-11-01 03:14:12 +000055 glEnable( GL_DEPTH_TEST );
56
57 glEnableClientState( GL_VERTEX_ARRAY );
58 glEnableClientState( GL_COLOR_ARRAY );
59
60 glMatrixMode( GL_PROJECTION );
61 glLoadIdentity();
Gareth Hughes5f5632c2000-11-03 00:09:31 +000062 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
Gareth Hughes9f568e52000-11-01 03:14:12 +000063 glMatrixMode( GL_MODELVIEW );
Gareth Hughes5f5632c2000-11-03 00:09:31 +000064 glLoadIdentity();
Gareth Hughes9f568e52000-11-01 03:14:12 +000065
66 glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );
67 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
68
69#ifdef GL_EXT_compiled_vertex_array
70 if ( compiled ) {
Gareth Hughes78539012000-11-30 03:06:56 +000071 glLockArraysEXT( 0, 4 );
Gareth Hughes9f568e52000-11-01 03:14:12 +000072 }
73#endif
74}
75
76void display( void )
77{
78 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
79
80 glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
81
82 glFlush();
Gareth Hughes78539012000-11-30 03:06:56 +000083 if ( doubleBuffer ) {
84 glutSwapBuffers();
85 }
Gareth Hughes9f568e52000-11-01 03:14:12 +000086}
87
88void keyboard( unsigned char key, int x, int y )
89{
90 switch ( key ) {
91 case 27:
92 exit( 0 );
93 break;
94 }
Gareth Hughes78539012000-11-30 03:06:56 +000095
96 glutPostRedisplay();
97}
98
99GLboolean args( int argc, char **argv )
100{
101 GLint i;
102
103 doubleBuffer = GL_TRUE;
104
105 for ( i = 1 ; i < argc ; i++ ) {
106 if ( strcmp( argv[i], "-sb" ) == 0 ) {
107 doubleBuffer = GL_FALSE;
108 } else if ( strcmp( argv[i], "-db" ) == 0 ) {
109 doubleBuffer = GL_TRUE;
110 } else {
111 fprintf( stderr, "%s (Bad option).\n", argv[i] );
112 return GL_FALSE;
113 }
114 }
115 return GL_TRUE;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000116}
117
118int main( int argc, char **argv )
119{
Gareth Hughes78539012000-11-30 03:06:56 +0000120 GLenum type;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000121 char *string;
Roland Scheidegger22b74ff2006-11-22 19:37:21 +0000122 double version;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000123
124 glutInit( &argc, argv );
Gareth Hughes78539012000-11-30 03:06:56 +0000125
126 if ( args( argc, argv ) == GL_FALSE ) {
127 exit( 1 );
128 }
129
130 type = GLUT_RGB | GLUT_DEPTH;
131 type |= ( doubleBuffer ) ? GLUT_DOUBLE : GLUT_SINGLE;
132
133 glutInitDisplayMode( type );
Gareth Hughes9f568e52000-11-01 03:14:12 +0000134 glutInitWindowSize( 250, 250 );
135 glutInitWindowPosition( 100, 100 );
136 glutCreateWindow( "CVA Test" );
137
138 /* Make sure the server supports GL 1.2 vertex arrays.
139 */
140 string = (char *) glGetString( GL_VERSION );
141
Roland Scheidegger22b74ff2006-11-22 19:37:21 +0000142 version = atof(string);
143 if ( version < 1.2 ) {
Gareth Hughes9f568e52000-11-01 03:14:12 +0000144 fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" );
145 exit( -1 );
146 }
147
148 /* See if the server supports compiled vertex arrays.
149 */
150 string = (char *) glGetString( GL_EXTENSIONS );
151
152 if ( !strstr( string, "GL_EXT_compiled_vertex_array" ) ) {
153 fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" );
154 compiled = GL_FALSE;
155 }
156
157 init();
158
159 glutDisplayFunc( display );
160 glutKeyboardFunc( keyboard );
161 glutMainLoop();
162
163 return 0;
164}