summaryrefslogtreecommitdiffstats
path: root/progs/demos/cubemap.c
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2004-05-05 20:17:19 +0000
committerIan Romanick <[email protected]>2004-05-05 20:17:19 +0000
commitcd6ca58c3f50dd8647c5b48b1350bbd87e27219b (patch)
tree7c8e8739fee91386176dac8dc6ac8e665a9baa94 /progs/demos/cubemap.c
parent95a0bd6762737bb25bdf5c4147da9d1372f6aac3 (diff)
Modified to use vertex arrays. Vertex arrays and immediate mode calls
are toggled with the 't' key.
Diffstat (limited to 'progs/demos/cubemap.c')
-rw-r--r--progs/demos/cubemap.c124
1 files changed, 94 insertions, 30 deletions
diff --git a/progs/demos/cubemap.c b/progs/demos/cubemap.c
index 4b97efbbd22..53605cdfa4f 100644
--- a/progs/demos/cubemap.c
+++ b/progs/demos/cubemap.c
@@ -45,52 +45,111 @@
static GLfloat Xrot = 0, Yrot = 0;
static GLfloat EyeDist = 10;
+static GLboolean use_vertex_arrays = GL_FALSE;
+#define eps1 0.99
+#define br 20.0 /* box radius */
-static void draw_skybox( void )
-{
- const GLfloat eps1 = 0.99;
- const GLfloat br = 20.0; /* box radius */
+static const GLfloat tex_coords[] = {
+ /* +X side */
+ 1.0, -eps1, -eps1,
+ 1.0, -eps1, eps1,
+ 1.0, eps1, eps1,
+ 1.0, eps1, -eps1,
+
+ /* -X side */
+ -1.0, eps1, -eps1,
+ -1.0, eps1, eps1,
+ -1.0, -eps1, eps1,
+ -1.0, -eps1, -eps1,
+
+ /* +Y side */
+ -eps1, 1.0, -eps1,
+ -eps1, 1.0, eps1,
+ eps1, 1.0, eps1,
+ eps1, 1.0, -eps1,
+
+ /* -Y side */
+ -eps1, -1.0, -eps1,
+ -eps1, -1.0, eps1,
+ eps1, -1.0, eps1,
+ eps1, -1.0, -eps1,
- glBegin(GL_QUADS);
+ /* +Z side */
+ eps1, -eps1, 1.0,
+ -eps1, -eps1, 1.0,
+ -eps1, eps1, 1.0,
+ eps1, eps1, 1.0,
+
+ /* -Z side */
+ eps1, eps1, -1.0,
+ -eps1, eps1, -1.0,
+ -eps1, -eps1, -1.0,
+ eps1, -eps1, -1.0,
+};
+static const GLfloat vtx_coords[] = {
/* +X side */
- glTexCoord3f(1.0, -eps1, -eps1); glVertex3f(br, -br, -br);
- glTexCoord3f(1.0, -eps1, eps1); glVertex3f(br, -br, br);
- glTexCoord3f(1.0, eps1, eps1); glVertex3f(br, br, br);
- glTexCoord3f(1.0, eps1, -eps1); glVertex3f(br, br, -br);
+ br, -br, -br,
+ br, -br, br,
+ br, br, br,
+ br, br, -br,
/* -X side */
- glTexCoord3f(-1.0, eps1, -eps1); glVertex3f(-br, br, -br);
- glTexCoord3f(-1.0, eps1, eps1); glVertex3f(-br, br, br);
- glTexCoord3f(-1.0, -eps1, eps1); glVertex3f(-br, -br, br);
- glTexCoord3f(-1.0, -eps1, -eps1); glVertex3f(-br, -br, -br);
+ -br, br, -br,
+ -br, br, br,
+ -br, -br, br,
+ -br, -br, -br,
/* +Y side */
- glTexCoord3f(-eps1, 1.0, -eps1); glVertex3f(-br, br, -br);
- glTexCoord3f(-eps1, 1.0, eps1); glVertex3f(-br, br, br);
- glTexCoord3f( eps1, 1.0, eps1); glVertex3f( br, br, br);
- glTexCoord3f( eps1, 1.0, -eps1); glVertex3f( br, br, -br);
+ -br, br, -br,
+ -br, br, br,
+ br, br, br,
+ br, br, -br,
/* -Y side */
- glTexCoord3f(-eps1, -1.0, -eps1); glVertex3f(-br, -br, -br);
- glTexCoord3f(-eps1, -1.0, eps1); glVertex3f(-br, -br, br);
- glTexCoord3f( eps1, -1.0, eps1); glVertex3f( br, -br, br);
- glTexCoord3f( eps1, -1.0, -eps1); glVertex3f( br, -br, -br);
+ -br, -br, -br,
+ -br, -br, br,
+ br, -br, br,
+ br, -br, -br,
/* +Z side */
- glTexCoord3f( eps1, -eps1, 1.0); glVertex3f( br, -br, br);
- glTexCoord3f(-eps1, -eps1, 1.0); glVertex3f(-br, -br, br);
- glTexCoord3f(-eps1, eps1, 1.0); glVertex3f(-br, br, br);
- glTexCoord3f( eps1, eps1, 1.0); glVertex3f( br, br, br);
+ br, -br, br,
+ -br, -br, br,
+ -br, br, br,
+ br, br, br,
/* -Z side */
- glTexCoord3f( eps1, eps1, -1.0); glVertex3f( br, br, -br);
- glTexCoord3f(-eps1, eps1, -1.0); glVertex3f(-br, br, -br);
- glTexCoord3f(-eps1, -eps1, -1.0); glVertex3f(-br, -br, -br);
- glTexCoord3f( eps1, -eps1, -1.0); glVertex3f( br, -br, -br);
+ br, br, -br,
+ -br, br, -br,
+ -br, -br, -br,
+ br, -br, -br,
+};
- glEnd();
+static void draw_skybox( void )
+{
+ if ( use_vertex_arrays ) {
+ glTexCoordPointer( 3, GL_FLOAT, 0, tex_coords );
+ glVertexPointer( 3, GL_FLOAT, 0, vtx_coords );
+
+ glEnableClientState( GL_TEXTURE_COORD_ARRAY );
+ glEnableClientState( GL_VERTEX_ARRAY );
+
+ glDrawArrays( GL_QUADS, 0, 24 );
+
+ glDisableClientState( GL_TEXTURE_COORD_ARRAY );
+ glDisableClientState( GL_VERTEX_ARRAY );
+ }
+ else {
+ unsigned i;
+
+ glBegin(GL_QUADS);
+ for ( i = 0 ; i < 24 ; i++ ) {
+ glTexCoord3fv( & tex_coords[ i * 3 ] );
+ glVertex3fv ( & vtx_coords[ i * 3 ] );
+ }
+ glEnd();
+ }
}
@@ -176,6 +235,11 @@ static void key(unsigned char k, int x, int y)
mode = !mode;
set_mode(mode);
break;
+ case 'v':
+ use_vertex_arrays = ! use_vertex_arrays;
+ printf( "Vertex arrays are %sabled\n",
+ (use_vertex_arrays) ? "en" : "dis" );
+ break;
case 'z':
EyeDist -= 0.5;
if (EyeDist < 6.0)