texgenmix.c revision 32001f49
132001f49Smrg
232001f49Smrg/*
332001f49Smrg * Demonstrates mixed texgen/non-texgen texture coordinates.
432001f49Smrg */
532001f49Smrg
632001f49Smrg#include <stdio.h>
732001f49Smrg#include <stdlib.h>
832001f49Smrg#include <string.h>
932001f49Smrg#include <GL/glew.h>
1032001f49Smrg#include "glut_wrap.h"
1132001f49Smrg
1232001f49Smrg#undef max
1332001f49Smrg#undef min
1432001f49Smrg#define max( a, b )	((a) >= (b) ? (a) : (b))
1532001f49Smrg#define min( a, b )	((a) <= (b) ? (a) : (b))
1632001f49Smrg
1732001f49SmrgGLfloat labelColor0[4] = { 1.0, 1.0, 1.0, 1.0 };
1832001f49SmrgGLfloat labelColor1[4] = { 1.0, 1.0, 0.4, 1.0 };
1932001f49SmrgGLfloat *labelInfoColor = labelColor0;
2032001f49Smrg
2132001f49SmrgGLboolean doubleBuffered = GL_TRUE;
2232001f49SmrgGLboolean drawTextured = GL_TRUE;
2332001f49Smrg
2432001f49Smrgint textureWidth = 64;
2532001f49Smrgint textureHeight = 64;
2632001f49Smrg
2732001f49Smrgint winWidth = 580, winHeight = 720;
2832001f49Smrg
2932001f49Smrgconst GLfloat texmat_swap_rq[16] = { 1.0, 0.0, 0.0, 0.0,
3032001f49Smrg                                     0.0, 1.0, 0.0, 0.0,
3132001f49Smrg                                     0.0, 0.0, 0.0, 1.0,
3232001f49Smrg                                     0.0, 0.0, 1.0, 0.0};
3332001f49Smrg
3432001f49Smrgconst GLfloat nullPlane[4] = { 0.0, 0.0, 0.0, 0.0 };
3532001f49Smrgconst GLfloat ObjPlaneS1[4] = { 1.0, 0.0, 1.0, 0.0 };
3632001f49Smrgconst GLfloat ObjPlaneS2[4] = { 0.5, 0.0, 0.0, 0.0 };
3732001f49Smrgconst GLfloat ObjPlaneS3[4] = { 1.0, 0.0, 0.0, 0.0 };
3832001f49Smrgconst GLfloat ObjPlaneT[4] = { 0.0, 1.0, 0.0, 0.0 };
3932001f49Smrgconst GLfloat ObjPlaneT2[4] = { 0.0, 0.5, 0.0, 0.0 };
4032001f49Smrgconst GLfloat ObjPlaneT3[4] = { 0.0, 1.0, 0.0, 0.0 };
4132001f49Smrgconst GLfloat ObjPlaneR[4] = { 0.0, 0.0, 1.0, 0.0 };
4232001f49Smrgconst GLfloat ObjPlaneQ[4] = { 0.0, 0.0, 0.0, 0.5 };
4332001f49Smrg
4432001f49Smrg
4532001f49Smrgstatic void checkErrors( void )
4632001f49Smrg{
4732001f49Smrg   GLenum error;
4832001f49Smrg
4932001f49Smrg   while ( (error = glGetError()) != GL_NO_ERROR ) {
5032001f49Smrg      fprintf( stderr, "Error: %s\n", (char *) gluErrorString( error ) );
5132001f49Smrg   }
5232001f49Smrg}
5332001f49Smrg
5432001f49Smrgstatic void drawString( const char *string, GLfloat x, GLfloat y,
5532001f49Smrg                        const GLfloat color[4] )
5632001f49Smrg{
5732001f49Smrg   glColor4fv( color );
5832001f49Smrg   glRasterPos2f( x, y );
5932001f49Smrg
6032001f49Smrg   while ( *string ) {
6132001f49Smrg      glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_10, *string );
6232001f49Smrg      string++;
6332001f49Smrg   }
6432001f49Smrg}
6532001f49Smrg
6632001f49Smrgstatic void begin2D( int width, int height )
6732001f49Smrg{
6832001f49Smrg   glMatrixMode( GL_PROJECTION );
6932001f49Smrg
7032001f49Smrg   glPushMatrix();
7132001f49Smrg   glLoadIdentity();
7232001f49Smrg
7332001f49Smrg   glOrtho( 0, width, 0, height, -1, 1 );
7432001f49Smrg   glMatrixMode( GL_MODELVIEW );
7532001f49Smrg
7632001f49Smrg   glPushMatrix();
7732001f49Smrg   glLoadIdentity();
7832001f49Smrg}
7932001f49Smrg
8032001f49Smrgstatic void end2D( void )
8132001f49Smrg{
8232001f49Smrg   glMatrixMode( GL_PROJECTION );
8332001f49Smrg   glPopMatrix();
8432001f49Smrg   glMatrixMode( GL_MODELVIEW );
8532001f49Smrg   glPopMatrix();
8632001f49Smrg}
8732001f49Smrg
8832001f49Smrgstatic void initialize( void )
8932001f49Smrg{
9032001f49Smrg   glMatrixMode( GL_PROJECTION );
9132001f49Smrg   glLoadIdentity();
9232001f49Smrg
9332001f49Smrg   glOrtho( -1.5, 1.5, -1.5, 1.5, -1.5, 1.5 );
9432001f49Smrg
9532001f49Smrg   glMatrixMode(GL_MODELVIEW);
9632001f49Smrg   glLoadIdentity();
9732001f49Smrg
9832001f49Smrg   glShadeModel( GL_FLAT );
9932001f49Smrg}
10032001f49Smrg
10132001f49Smrg/* ARGSUSED1 */
10232001f49Smrgstatic void keyboard( unsigned char c, int x, int y )
10332001f49Smrg{
10432001f49Smrg   switch ( c ) {
10532001f49Smrg   case 't':
10632001f49Smrg      drawTextured = !drawTextured;
10732001f49Smrg      break;
10832001f49Smrg   case 27:             /* Escape key should force exit. */
10932001f49Smrg      exit(0);
11032001f49Smrg      break;
11132001f49Smrg   default:
11232001f49Smrg      break;
11332001f49Smrg   }
11432001f49Smrg   glutPostRedisplay();
11532001f49Smrg}
11632001f49Smrg
11732001f49Smrg/* ARGSUSED1 */
11832001f49Smrgstatic void special( int key, int x, int y )
11932001f49Smrg{
12032001f49Smrg   switch ( key ) {
12132001f49Smrg   case GLUT_KEY_DOWN:
12232001f49Smrg      break;
12332001f49Smrg   case GLUT_KEY_UP:
12432001f49Smrg      break;
12532001f49Smrg   case GLUT_KEY_LEFT:
12632001f49Smrg      break;
12732001f49Smrg   case GLUT_KEY_RIGHT:
12832001f49Smrg      break;
12932001f49Smrg   default:
13032001f49Smrg      break;
13132001f49Smrg   }
13232001f49Smrg   glutPostRedisplay();
13332001f49Smrg}
13432001f49Smrg
13532001f49Smrgstatic void
13632001f49Smrgreshape( int w, int h )
13732001f49Smrg{
13832001f49Smrg   winWidth = w;
13932001f49Smrg   winHeight = h;
14032001f49Smrg   /* No need to call glViewPort here since "draw" calls it! */
14132001f49Smrg}
14232001f49Smrg
14332001f49Smrgstatic void loadTexture( int width, int height )
14432001f49Smrg{
14532001f49Smrg   int		alphaSize = 1;
14632001f49Smrg   int		rgbSize = 3;
14732001f49Smrg   GLubyte	*texImage, *p;
14832001f49Smrg   int		elementsPerGroup, elementSize, groupSize, rowSize;
14932001f49Smrg   int		i, j;
15032001f49Smrg
15132001f49Smrg
15232001f49Smrg   elementsPerGroup = alphaSize + rgbSize;
15332001f49Smrg   elementSize = sizeof(GLubyte);
15432001f49Smrg   groupSize = elementsPerGroup * elementSize;
15532001f49Smrg   rowSize = width * groupSize;
15632001f49Smrg
15732001f49Smrg   if ( (texImage = (GLubyte *) malloc( height * rowSize ) ) == NULL ) {
15832001f49Smrg      fprintf( stderr, "texture malloc failed\n" );
15932001f49Smrg      return;
16032001f49Smrg   }
16132001f49Smrg
16232001f49Smrg   for ( i = 0 ; i < height ; i++ )
16332001f49Smrg   {
16432001f49Smrg      p = texImage + i * rowSize;
16532001f49Smrg
16632001f49Smrg      for ( j = 0 ; j < width ; j++ )
16732001f49Smrg      {
16832001f49Smrg	 if ( rgbSize > 0 )
16932001f49Smrg	 {
17032001f49Smrg	    /**
17132001f49Smrg	     ** +-----+-----+
17232001f49Smrg	     ** |     |     |
17332001f49Smrg	     ** |  R  |  G  |
17432001f49Smrg	     ** |     |     |
17532001f49Smrg	     ** +-----+-----+
17632001f49Smrg	     ** |     |     |
17732001f49Smrg	     ** |  Y  |  B  |
17832001f49Smrg	     ** |     |     |
17932001f49Smrg	     ** +-----+-----+
18032001f49Smrg	     **/
18132001f49Smrg	    if ( i > height / 2 ) {
18232001f49Smrg	       if ( j < width / 2 ) {
18332001f49Smrg		  p[0] = 0xff;
18432001f49Smrg		  p[1] = 0x00;
18532001f49Smrg		  p[2] = 0x00;
18632001f49Smrg	       } else {
18732001f49Smrg		  p[0] = 0x00;
18832001f49Smrg		  p[1] = 0xff;
18932001f49Smrg		  p[2] = 0x00;
19032001f49Smrg	       }
19132001f49Smrg	    } else {
19232001f49Smrg	       if ( j < width / 2 ) {
19332001f49Smrg		  p[0] = 0xff;
19432001f49Smrg		  p[1] = 0xff;
19532001f49Smrg		  p[2] = 0x00;
19632001f49Smrg	       } else {
19732001f49Smrg		  p[0] = 0x00;
19832001f49Smrg		  p[1] = 0x00;
19932001f49Smrg		  p[2] = 0xff;
20032001f49Smrg	       }
20132001f49Smrg	    }
20232001f49Smrg	    p += 3 * elementSize;
20332001f49Smrg	 }
20432001f49Smrg
20532001f49Smrg	 if ( alphaSize > 0 )
20632001f49Smrg	 {
20732001f49Smrg	    /**
20832001f49Smrg	     ** +-----------+
20932001f49Smrg	     ** |     W     |
21032001f49Smrg	     ** |  +-----+  |
21132001f49Smrg	     ** |  |     |  |
21232001f49Smrg	     ** |  |  B  |  |
21332001f49Smrg	     ** |  |     |  |
21432001f49Smrg	     ** |  +-----+  |
21532001f49Smrg	     ** |           |
21632001f49Smrg	     ** +-----------+
21732001f49Smrg	     **/
21832001f49Smrg	    int i2 = i - height / 2;
21932001f49Smrg	    int j2 = j - width / 2;
22032001f49Smrg	    int h8 = height / 8;
22132001f49Smrg	    int w8 = width / 8;
22232001f49Smrg	    if ( -h8 <= i2 && i2 <= h8 && -w8 <= j2 && j2 <= w8 ) {
22332001f49Smrg	       p[0] = 0x00;
22432001f49Smrg	    } else if ( -2 * h8 <= i2 && i2 <= 2 * h8 && -2 * w8 <= j2 && j2 <= 2 * w8 ) {
22532001f49Smrg	       p[0] = 0x55;
22632001f49Smrg	    } else if ( -3 * h8 <= i2 && i2 <= 3 * h8 && -3 * w8 <= j2 && j2 <= 3 * w8 ) {
22732001f49Smrg	       p[0] = 0xaa;
22832001f49Smrg	    } else {
22932001f49Smrg	       p[0] = 0xff;
23032001f49Smrg	    }
23132001f49Smrg	    p += elementSize;
23232001f49Smrg	 }
23332001f49Smrg      }
23432001f49Smrg   }
23532001f49Smrg
23632001f49Smrg   glTexImage2D( GL_TEXTURE_2D, 0,
23732001f49Smrg		 GL_RGBA, width, height, 0,
23832001f49Smrg		 GL_RGBA, GL_UNSIGNED_BYTE, texImage );
23932001f49Smrg
24032001f49Smrg   free( texImage );
24132001f49Smrg}
24232001f49Smrg
24332001f49Smrg
24432001f49Smrgstatic void drawSample( int x, int y, int w, int h,
24532001f49Smrg                        int texgenenabled, int coordnr )
24632001f49Smrg{
24732001f49Smrg   char buf[255];
24832001f49Smrg
24932001f49Smrg   glViewport( x, y, w, h );
25032001f49Smrg   glScissor( x, y, w, h );
25132001f49Smrg
25232001f49Smrg   glClearColor( 0.1, 0.1, 0.1, 1.0 );
25332001f49Smrg   glClear( GL_COLOR_BUFFER_BIT );
25432001f49Smrg
25532001f49Smrg   begin2D( w, h );
25632001f49Smrg   if (texgenenabled == 2) {
25732001f49Smrg      sprintf( buf, "TexCoord%df", coordnr);
25832001f49Smrg      drawString( buf, 10, h - 15, labelInfoColor );
25932001f49Smrg      sprintf( buf, "texgen enabled for %s coordinate(s)", coordnr == 2 ? "S" : "S/T");
26032001f49Smrg      drawString( buf, 10, 5, labelInfoColor );
26132001f49Smrg   }
26232001f49Smrg   else if (texgenenabled == 0) {
26332001f49Smrg      sprintf( buf, "TexCoord%df", coordnr);
26432001f49Smrg      drawString( buf, 10, h - 15, labelInfoColor );
26532001f49Smrg      drawString( "no texgen", 10, 5, labelInfoColor );
26632001f49Smrg   }
26732001f49Smrg   else if (texgenenabled == 1) {
26832001f49Smrg      drawString( "no TexCoord", 10, h - 15, labelInfoColor );
26932001f49Smrg      sprintf( buf, "texgen enabled for %s coordinate(s)",
27032001f49Smrg         coordnr == 2 ? "S/T" : (coordnr == 3 ? "S/T/R" : "S/T/R/Q"));
27132001f49Smrg      drawString( buf, 10, 5, labelInfoColor );
27232001f49Smrg   }
27332001f49Smrg
27432001f49Smrg   end2D();
27532001f49Smrg
27632001f49Smrg   glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
27732001f49Smrg
27832001f49Smrg   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
27932001f49Smrg   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
28032001f49Smrg
28132001f49Smrg   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
28232001f49Smrg   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
28332001f49Smrg
28432001f49Smrg   loadTexture( textureWidth, textureHeight );
28532001f49Smrg
28632001f49Smrg   if ( drawTextured ) {
28732001f49Smrg      glEnable( GL_TEXTURE_2D );
28832001f49Smrg   }
28932001f49Smrg
29032001f49Smrg   glDisable( GL_TEXTURE_GEN_S );
29132001f49Smrg   glDisable( GL_TEXTURE_GEN_T );
29232001f49Smrg   glDisable( GL_TEXTURE_GEN_R );
29332001f49Smrg   glDisable( GL_TEXTURE_GEN_Q );
29432001f49Smrg
29532001f49Smrg   glMatrixMode( GL_TEXTURE );
29632001f49Smrg   glLoadIdentity();
29732001f49Smrg   glMatrixMode( GL_MODELVIEW );
29832001f49Smrg   glPushMatrix();
29932001f49Smrg
30032001f49Smrg   switch (coordnr) {
30132001f49Smrg   case 2:
30232001f49Smrg      switch (texgenenabled) {
30332001f49Smrg      case 0:
30432001f49Smrg         glBegin( GL_QUADS );
30532001f49Smrg         glTexCoord2f( 0.0, 0.0 );
30632001f49Smrg         glVertex2f( -0.8, -0.8 );
30732001f49Smrg
30832001f49Smrg         glTexCoord2f( 1.0, 0.0 );
30932001f49Smrg         glVertex2f( 0.8, -0.8 );
31032001f49Smrg
31132001f49Smrg         glTexCoord2f( 1.0, 1.0 );
31232001f49Smrg         glVertex2f( 0.8, 0.8 );
31332001f49Smrg
31432001f49Smrg         glTexCoord2f( 0.0, 1.0 );
31532001f49Smrg         glVertex2f( -0.8, 0.8 );
31632001f49Smrg         glEnd();
31732001f49Smrg         break;
31832001f49Smrg      case 1:
31932001f49Smrg         glTranslatef( -0.8, -0.8, 0.0 );
32032001f49Smrg         glScalef( 1.6, 1.6, 1.0 );
32132001f49Smrg         glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
32232001f49Smrg         glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
32332001f49Smrg         glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
32432001f49Smrg         glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
32532001f49Smrg         glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS3);
32632001f49Smrg         glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT3);
32732001f49Smrg         glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane);
32832001f49Smrg         glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane);
32932001f49Smrg
33032001f49Smrg         glEnable( GL_TEXTURE_GEN_S );
33132001f49Smrg         glEnable( GL_TEXTURE_GEN_T );
33232001f49Smrg
33332001f49Smrg         /* Issue a texcoord here to be sure Q isn't left over from a
33432001f49Smrg          * previous sample.
33532001f49Smrg          */
33632001f49Smrg         glTexCoord1f( 0.0 );
33732001f49Smrg         glBegin( GL_QUADS );
33832001f49Smrg         glVertex2f( 0.0, 0.0 );
33932001f49Smrg         glVertex2f( 1.0, 0.0 );
34032001f49Smrg         glVertex2f( 1.0, 1.0 );
34132001f49Smrg         glVertex2f( 0.0, 1.0 );
34232001f49Smrg         glEnd();
34332001f49Smrg         break;
34432001f49Smrg      case 2:
34532001f49Smrg         /* make sure that texgen T and non-texgen S coordinate are wrong */
34632001f49Smrg         glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
34732001f49Smrg         glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
34832001f49Smrg         glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
34932001f49Smrg         glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
35032001f49Smrg         glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS1);
35132001f49Smrg         glTexGenfv(GL_T, GL_OBJECT_PLANE, nullPlane);
35232001f49Smrg         glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane);
35332001f49Smrg         glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane);
35432001f49Smrg
35532001f49Smrg         glEnable( GL_TEXTURE_GEN_S );
35632001f49Smrg
35732001f49Smrg         glBegin( GL_QUADS );
35832001f49Smrg         /* use z coordinate to get correct texgen values... */
35932001f49Smrg         glTexCoord2f( 0.0, 0.0 );
36032001f49Smrg         glVertex3f( -0.8, -0.8, 0.8 );
36132001f49Smrg
36232001f49Smrg         glTexCoord2f( 0.0, 0.0 );
36332001f49Smrg         glVertex3f( 0.8, -0.8, 0.2 );
36432001f49Smrg
36532001f49Smrg         glTexCoord2f( 0.0, 1.0 );
36632001f49Smrg         glVertex3f( 0.8, 0.8, 0.2 );
36732001f49Smrg
36832001f49Smrg         glTexCoord2f( 0.0, 1.0 );
36932001f49Smrg         glVertex3f( -0.8, 0.8, 0.8 );
37032001f49Smrg         glEnd();
37132001f49Smrg         break;
37232001f49Smrg      }
37332001f49Smrg      break;
37432001f49Smrg   case 3:
37532001f49Smrg      glMatrixMode( GL_TEXTURE );
37632001f49Smrg      glLoadMatrixf( texmat_swap_rq );
37732001f49Smrg      glMatrixMode( GL_MODELVIEW );
37832001f49Smrg      glTranslatef( -0.8, -0.8, 0.0 );
37932001f49Smrg      glScalef( 1.6, 1.6, 1.0 );
38032001f49Smrg      switch (texgenenabled) {
38132001f49Smrg      case 0:
38232001f49Smrg         glBegin( GL_QUADS );
38332001f49Smrg         glTexCoord3f( 0.0, 0.0, 0.5 );
38432001f49Smrg         glVertex2f( 0.0, 0.0 );
38532001f49Smrg
38632001f49Smrg         glTexCoord3f( 0.5, 0.0, 0.5 );
38732001f49Smrg         glVertex2f( 1.0, 0.0 );
38832001f49Smrg
38932001f49Smrg         glTexCoord3f( 0.5, 0.5, 0.5 );
39032001f49Smrg         glVertex2f( 1.0, 1.0 );
39132001f49Smrg
39232001f49Smrg         glTexCoord3f( 0.0, 0.5, 0.5 );
39332001f49Smrg         glVertex2f( 0.0, 1.0 );
39432001f49Smrg         glEnd();
39532001f49Smrg         break;
39632001f49Smrg      case 1:
39732001f49Smrg         glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
39832001f49Smrg         glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
39932001f49Smrg         glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
40032001f49Smrg         glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
40132001f49Smrg         glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2);
40232001f49Smrg         glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2);
40332001f49Smrg         glTexGenfv(GL_R, GL_OBJECT_PLANE, ObjPlaneR);
40432001f49Smrg         glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane);
40532001f49Smrg
40632001f49Smrg         glEnable( GL_TEXTURE_GEN_S );
40732001f49Smrg         glEnable( GL_TEXTURE_GEN_T );
40832001f49Smrg         glEnable( GL_TEXTURE_GEN_R );
40932001f49Smrg
41032001f49Smrg         glTexCoord1f( 0.0 ); /* to make sure Q is 1.0 */
41132001f49Smrg         glBegin( GL_QUADS );
41232001f49Smrg         glVertex3f( 0.0, 0.0, 0.5 );
41332001f49Smrg         glVertex3f( 1.0, 0.0, 0.5 );
41432001f49Smrg         glVertex3f( 1.0, 1.0, 0.5 );
41532001f49Smrg         glVertex3f( 0.0, 1.0, 0.5 );
41632001f49Smrg         glEnd();
41732001f49Smrg         break;
41832001f49Smrg      case 2:
41932001f49Smrg         /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */
42032001f49Smrg         glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
42132001f49Smrg         glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
42232001f49Smrg         glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
42332001f49Smrg         glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
42432001f49Smrg         glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2);
42532001f49Smrg         glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2);
42632001f49Smrg         glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane);
42732001f49Smrg         glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane);
42832001f49Smrg
42932001f49Smrg         glEnable( GL_TEXTURE_GEN_S );
43032001f49Smrg         glEnable( GL_TEXTURE_GEN_T );
43132001f49Smrg
43232001f49Smrg         glBegin( GL_QUADS );
43332001f49Smrg         glTexCoord3f( 0.0, 0.0, 0.5 );
43432001f49Smrg         glVertex2f( 0.0, 0.0);
43532001f49Smrg
43632001f49Smrg         glTexCoord3f( 0.0, 0.0, 0.5 );
43732001f49Smrg         glVertex2f( 1.0, 0.0);
43832001f49Smrg
43932001f49Smrg         glTexCoord3f( 0.0, 0.0, 0.5 );
44032001f49Smrg         glVertex2f( 1.0, 1.0);
44132001f49Smrg
44232001f49Smrg         glTexCoord3f( 0.0, 0.0, 0.5 );
44332001f49Smrg         glVertex2f( 0.0, 1.0);
44432001f49Smrg         glEnd();
44532001f49Smrg         break;
44632001f49Smrg      }
44732001f49Smrg      break;
44832001f49Smrg   case 4:
44932001f49Smrg      switch (texgenenabled) {
45032001f49Smrg      case 0:
45132001f49Smrg         glBegin( GL_QUADS );
45232001f49Smrg         /* don't need r coordinate but still setting it I'm mean */
45332001f49Smrg         glTexCoord4f( 0.0, 0.0, 0.0, 0.5 );
45432001f49Smrg         glVertex2f( -0.8, -0.8 );
45532001f49Smrg
45632001f49Smrg         glTexCoord4f( 0.5, 0.0, 0.2, 0.5 );
45732001f49Smrg         glVertex2f( 0.8, -0.8 );
45832001f49Smrg
45932001f49Smrg         glTexCoord4f( 0.5, 0.5, 0.5, 0.5 );
46032001f49Smrg         glVertex2f( 0.8, 0.8 );
46132001f49Smrg
46232001f49Smrg         glTexCoord4f( 0.0, 0.5, 0.5, 0.5 );
46332001f49Smrg         glVertex2f( -0.8, 0.8 );
46432001f49Smrg         glEnd();
46532001f49Smrg         break;
46632001f49Smrg      case 1:
46732001f49Smrg         glTranslatef( -0.8, -0.8, 0.0 );
46832001f49Smrg         glScalef( 1.6, 1.6, 1.0 );
46932001f49Smrg         /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */
47032001f49Smrg         glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
47132001f49Smrg         glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
47232001f49Smrg         glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
47332001f49Smrg         glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
47432001f49Smrg         glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2);
47532001f49Smrg         glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2);
47632001f49Smrg         glTexGenfv(GL_R, GL_OBJECT_PLANE, ObjPlaneR);
47732001f49Smrg         glTexGenfv(GL_Q, GL_OBJECT_PLANE, ObjPlaneQ);
47832001f49Smrg
47932001f49Smrg         glEnable( GL_TEXTURE_GEN_S );
48032001f49Smrg         glEnable( GL_TEXTURE_GEN_T );
48132001f49Smrg         glEnable( GL_TEXTURE_GEN_R );
48232001f49Smrg         glEnable( GL_TEXTURE_GEN_Q );
48332001f49Smrg
48432001f49Smrg         glBegin( GL_QUADS );
48532001f49Smrg         glVertex2f( 0.0, 0.0 );
48632001f49Smrg         glVertex2f( 1.0, 0.0 );
48732001f49Smrg         glVertex2f( 1.0, 1.0 );
48832001f49Smrg         glVertex2f( 0.0, 1.0 );
48932001f49Smrg         glEnd();
49032001f49Smrg         break;
49132001f49Smrg      case 2:
49232001f49Smrg         glTranslatef( -0.8, -0.8, 0.0 );
49332001f49Smrg         glScalef( 1.6, 1.6, 1.0 );
49432001f49Smrg         /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */
49532001f49Smrg         glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
49632001f49Smrg         glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
49732001f49Smrg         glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
49832001f49Smrg         glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
49932001f49Smrg         glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2);
50032001f49Smrg         glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2);
50132001f49Smrg         glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane);
50232001f49Smrg         glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane);
50332001f49Smrg
50432001f49Smrg         glEnable( GL_TEXTURE_GEN_S );
50532001f49Smrg         glEnable( GL_TEXTURE_GEN_T );
50632001f49Smrg
50732001f49Smrg         glBegin( GL_QUADS );
50832001f49Smrg         glTexCoord4f( 0.0, 0.0, 0.0, 0.5 );
50932001f49Smrg         glVertex2f( 0.0, 0.0 );
51032001f49Smrg
51132001f49Smrg         glTexCoord4f( 0.0, 0.0, 0.2, 0.5 );
51232001f49Smrg         glVertex2f( 1.0, 0.0 );
51332001f49Smrg
51432001f49Smrg         glTexCoord4f( 0.0, 0.0, 0.5, 0.5 );
51532001f49Smrg         glVertex2f( 1.0, 1.0 );
51632001f49Smrg
51732001f49Smrg         glTexCoord4f( 0.0, 0.0, 0.75, 0.5 );
51832001f49Smrg         glVertex2f( 0.0, 1.0 );
51932001f49Smrg         glEnd();
52032001f49Smrg         break;
52132001f49Smrg      }
52232001f49Smrg      break;
52332001f49Smrg   }
52432001f49Smrg
52532001f49Smrg   glPopMatrix();
52632001f49Smrg   glDisable( GL_TEXTURE_2D );
52732001f49Smrg
52832001f49Smrg}
52932001f49Smrg
53032001f49Smrgstatic void display( void )
53132001f49Smrg{
53232001f49Smrg   int		numX = 3, numY = 3;
53332001f49Smrg   float	xBase = (float) winWidth * 0.01;
53432001f49Smrg   float	xOffset = (winWidth - xBase) / numX;
53532001f49Smrg   float	xSize = max( xOffset - xBase, 1 );
53632001f49Smrg   float	yBase = (float) winHeight * 0.01;
53732001f49Smrg   float	yOffset = (winHeight - yBase) / numY;
53832001f49Smrg   float	ySize = max( yOffset - yBase, 1 );
53932001f49Smrg   float	x, y;
54032001f49Smrg   int		i, j;
54132001f49Smrg
54232001f49Smrg   glViewport( 0, 0, winWidth, winHeight );
54332001f49Smrg   glDisable( GL_SCISSOR_TEST );
54432001f49Smrg   glClearColor( 0.0, 0.0, 0.0, 0.0 );
54532001f49Smrg   glClear( GL_COLOR_BUFFER_BIT );
54632001f49Smrg   glEnable( GL_SCISSOR_TEST );
54732001f49Smrg
54832001f49Smrg   x = xBase;
54932001f49Smrg   y = (winHeight - 1) - yOffset;
55032001f49Smrg
55132001f49Smrg   for ( i = 0 ; i < numY ; i++ )
55232001f49Smrg   {
55332001f49Smrg
55432001f49Smrg      labelInfoColor = labelColor1;
55532001f49Smrg
55632001f49Smrg
55732001f49Smrg      for ( j = 0 ; j < numX ; j++ ) {
55832001f49Smrg	 drawSample( x, y, xSize, ySize, i, j+2 );
55932001f49Smrg	 x += xOffset;
56032001f49Smrg      }
56132001f49Smrg
56232001f49Smrg      x = xBase;
56332001f49Smrg      y -= yOffset;
56432001f49Smrg   }
56532001f49Smrg
56632001f49Smrg   if ( doubleBuffered ) {
56732001f49Smrg      glutSwapBuffers();
56832001f49Smrg   } else {
56932001f49Smrg      glFlush();
57032001f49Smrg   }
57132001f49Smrg
57232001f49Smrg   checkErrors();
57332001f49Smrg}
57432001f49Smrg
57532001f49Smrgstatic void usage( char *name )
57632001f49Smrg{
57732001f49Smrg   fprintf( stderr, "usage: %s [ options ]\n", name );
57832001f49Smrg   fprintf( stderr, "\n" );
57932001f49Smrg   fprintf( stderr, "options:\n" );
58032001f49Smrg   fprintf( stderr, "    -sb    single buffered\n" );
58132001f49Smrg   fprintf( stderr, "    -db    double buffered\n" );
58232001f49Smrg   fprintf( stderr, "    -info  print OpenGL driver info\n" );
58332001f49Smrg}
58432001f49Smrg
58532001f49Smrgstatic void instructions( void )
58632001f49Smrg{
58732001f49Smrg   fprintf( stderr, "texgenmix - mixed texgen/non-texgen texture coordinate test\n" );
58832001f49Smrg   fprintf( stderr, "all quads should look the same!\n" );
58932001f49Smrg   fprintf( stderr, "\n" );
59032001f49Smrg   fprintf( stderr, "  [t] - toggle texturing\n" );
59132001f49Smrg}
59232001f49Smrg
59332001f49Smrgint main( int argc, char *argv[] )
59432001f49Smrg{
59532001f49Smrg   GLboolean info = GL_FALSE;
59632001f49Smrg   int i;
59732001f49Smrg
59832001f49Smrg   glutInit( &argc, argv );
59932001f49Smrg
60032001f49Smrg   for ( i = 1 ; i < argc ; i++ ) {
60132001f49Smrg      if ( !strcmp( "-sb", argv[i] ) ) {
60232001f49Smrg	 doubleBuffered = GL_FALSE;
60332001f49Smrg      } else if ( !strcmp( "-db", argv[i] ) ) {
60432001f49Smrg	 doubleBuffered = GL_TRUE;
60532001f49Smrg      } else if ( !strcmp( "-info", argv[i] ) ) {
60632001f49Smrg	 info = GL_TRUE;
60732001f49Smrg      } else {
60832001f49Smrg	 usage( argv[0] );
60932001f49Smrg	 exit( 1 );
61032001f49Smrg      }
61132001f49Smrg   }
61232001f49Smrg
61332001f49Smrg   if ( doubleBuffered ) {
61432001f49Smrg      glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
61532001f49Smrg   } else {
61632001f49Smrg      glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE );
61732001f49Smrg   }
61832001f49Smrg
61932001f49Smrg   glutInitWindowSize( winWidth, winHeight );
62032001f49Smrg   glutInitWindowPosition( 0, 0 );
62132001f49Smrg   glutCreateWindow( "Mixed texgen/non-texgen texture coordinate test" );
62232001f49Smrg   glewInit();
62332001f49Smrg
62432001f49Smrg   initialize();
62532001f49Smrg   instructions();
62632001f49Smrg
62732001f49Smrg   if ( info ) {
62832001f49Smrg      printf( "\n" );
62932001f49Smrg      printf( "GL_RENDERER   = %s\n", (char *) glGetString( GL_RENDERER ) );
63032001f49Smrg      printf( "GL_VERSION    = %s\n", (char *) glGetString( GL_VERSION ) );
63132001f49Smrg      printf( "GL_VENDOR     = %s\n", (char *) glGetString( GL_VENDOR ) ) ;
63232001f49Smrg      printf( "GL_EXTENSIONS = %s\n", (char *) glGetString( GL_EXTENSIONS ) );
63332001f49Smrg   }
63432001f49Smrg
63532001f49Smrg   glutDisplayFunc( display );
63632001f49Smrg   glutReshapeFunc( reshape );
63732001f49Smrg   glutKeyboardFunc( keyboard );
63832001f49Smrg   glutSpecialFunc( special );
63932001f49Smrg   glutMainLoop();
64032001f49Smrg
64132001f49Smrg   return 0;
64232001f49Smrg}
643