blob: ed965e748a5ca6d68ee9e933c4ead82e86f0aea7 [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>
Eric Anholt9bb0d622007-09-24 10:22:31 -070014#include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
Karl Schultz40fac752002-01-16 01:03:25 +000015#ifdef _WIN32
16#include <windows.h>
17#endif
Gareth Hughes9f568e52000-11-01 03:14:12 +000018#define GL_GLEXT_LEGACY
19#include <GL/glut.h>
20
21
22GLfloat verts[][4] = {
Gareth Hughes5f5632c2000-11-03 00:09:31 +000023 { -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 },
Gareth Hughes78539012000-11-30 03:06:56 +000026 { 0.5, 0.5, -2.0, 0.0 },
Gareth Hughes9f568e52000-11-01 03:14:12 +000027};
28
29GLubyte color[][4] = {
30 { 0xff, 0x00, 0x00, 0x00 },
31 { 0x00, 0xff, 0x00, 0x00 },
32 { 0x00, 0x00, 0xff, 0x00 },
Gareth Hughes78539012000-11-30 03:06:56 +000033 { 0xff, 0xff, 0xff, 0x00 },
Gareth Hughes9f568e52000-11-01 03:14:12 +000034};
35
Gareth Hughes78539012000-11-30 03:06:56 +000036GLuint indices[] = { 0, 1, 2, 3 };
Gareth Hughes9f568e52000-11-01 03:14:12 +000037
38GLboolean compiled = GL_TRUE;
Gareth Hughes78539012000-11-30 03:06:56 +000039GLboolean doubleBuffer = GL_TRUE;
Gareth Hughes9f568e52000-11-01 03:14:12 +000040
41
42void init( void )
43{
44 glClearColor( 0.0, 0.0, 0.0, 0.0 );
45 glShadeModel( GL_SMOOTH );
46
Gareth Hughes78539012000-11-30 03:06:56 +000047 glFrontFace( GL_CCW );
48 glCullFace( GL_BACK );
49 glEnable( GL_CULL_FACE );
50
Gareth Hughes9f568e52000-11-01 03:14:12 +000051 glEnable( GL_DEPTH_TEST );
52
53 glEnableClientState( GL_VERTEX_ARRAY );
54 glEnableClientState( GL_COLOR_ARRAY );
55
56 glMatrixMode( GL_PROJECTION );
57 glLoadIdentity();
Gareth Hughes5f5632c2000-11-03 00:09:31 +000058 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
Gareth Hughes9f568e52000-11-01 03:14:12 +000059 glMatrixMode( GL_MODELVIEW );
Gareth Hughes5f5632c2000-11-03 00:09:31 +000060 glLoadIdentity();
Gareth Hughes9f568e52000-11-01 03:14:12 +000061
62 glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );
63 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
64
65#ifdef GL_EXT_compiled_vertex_array
66 if ( compiled ) {
Gareth Hughes78539012000-11-30 03:06:56 +000067 glLockArraysEXT( 0, 4 );
Gareth Hughes9f568e52000-11-01 03:14:12 +000068 }
69#endif
70}
71
72void display( void )
73{
74 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
75
76 glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
77
78 glFlush();
Gareth Hughes78539012000-11-30 03:06:56 +000079 if ( doubleBuffer ) {
80 glutSwapBuffers();
81 }
Gareth Hughes9f568e52000-11-01 03:14:12 +000082}
83
84void keyboard( unsigned char key, int x, int y )
85{
86 switch ( key ) {
87 case 27:
88 exit( 0 );
89 break;
90 }
Gareth Hughes78539012000-11-30 03:06:56 +000091
92 glutPostRedisplay();
93}
94
95GLboolean args( int argc, char **argv )
96{
97 GLint i;
98
99 doubleBuffer = GL_TRUE;
100
101 for ( i = 1 ; i < argc ; i++ ) {
102 if ( strcmp( argv[i], "-sb" ) == 0 ) {
103 doubleBuffer = GL_FALSE;
104 } else if ( strcmp( argv[i], "-db" ) == 0 ) {
105 doubleBuffer = GL_TRUE;
106 } else {
107 fprintf( stderr, "%s (Bad option).\n", argv[i] );
108 return GL_FALSE;
109 }
110 }
111 return GL_TRUE;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000112}
113
114int main( int argc, char **argv )
115{
Gareth Hughes78539012000-11-30 03:06:56 +0000116 GLenum type;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000117 char *string;
Roland Scheidegger22b74ff2006-11-22 19:37:21 +0000118 double version;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000119
120 glutInit( &argc, argv );
Gareth Hughes78539012000-11-30 03:06:56 +0000121
122 if ( args( argc, argv ) == GL_FALSE ) {
123 exit( 1 );
124 }
125
126 type = GLUT_RGB | GLUT_DEPTH;
127 type |= ( doubleBuffer ) ? GLUT_DOUBLE : GLUT_SINGLE;
128
129 glutInitDisplayMode( type );
Gareth Hughes9f568e52000-11-01 03:14:12 +0000130 glutInitWindowSize( 250, 250 );
131 glutInitWindowPosition( 100, 100 );
132 glutCreateWindow( "CVA Test" );
133
134 /* Make sure the server supports GL 1.2 vertex arrays.
135 */
136 string = (char *) glGetString( GL_VERSION );
137
Roland Scheidegger22b74ff2006-11-22 19:37:21 +0000138 version = atof(string);
139 if ( version < 1.2 ) {
Gareth Hughes9f568e52000-11-01 03:14:12 +0000140 fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" );
141 exit( -1 );
142 }
143
144 /* See if the server supports compiled vertex arrays.
145 */
146 string = (char *) glGetString( GL_EXTENSIONS );
147
148 if ( !strstr( string, "GL_EXT_compiled_vertex_array" ) ) {
149 fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" );
150 compiled = GL_FALSE;
151 }
152
153 init();
154
155 glutDisplayFunc( display );
156 glutKeyboardFunc( keyboard );
157 glutMainLoop();
158
159 return 0;
160}