1 /* $Id: paltex.c,v 1.2 1999/11/02 15:09:04 brianp Exp $ */
4 * Paletted texture demo. Written by Brian Paul.
5 * This program is in the public domain.
10 * Revision 1.2 1999/11/02 15:09:04 brianp
11 * new texture image, cleaned-up code
13 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
16 * Revision 3.1 1999/03/28 18:20:49 brianp
19 * Revision 3.0 1998/02/14 18:42:29 brianp
31 static float Rot
= 0.0;
34 static void Idle( void )
41 static void Display( void )
43 glClear( GL_COLOR_BUFFER_BIT
);
46 glRotatef(Rot
, 0, 0, 1);
49 glTexCoord2f(0, 1); glVertex2f(-1, -0.5);
50 glTexCoord2f(1, 1); glVertex2f( 1, -0.5);
51 glTexCoord2f(1, 0); glVertex2f( 1, 0.5);
52 glTexCoord2f(0, 0); glVertex2f(-1, 0.5);
61 static void Reshape( int width
, int height
)
63 glViewport( 0, 0, width
, height
);
64 glMatrixMode( GL_PROJECTION
);
66 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
67 glMatrixMode( GL_MODELVIEW
);
69 glTranslatef( 0.0, 0.0, -7.0 );
73 static void Key( unsigned char key
, int x
, int y
)
86 static void Init( void )
90 static char texture
[HEIGHT
][WIDTH
] = {
94 " M M M EEEE SS A A ",
100 GLubyte table
[256][4];
103 if (!glutExtensionSupported("GL_EXT_paletted_texture")) {
104 printf("Sorry, GL_EXT_paletted_texture not supported\n");
108 /* load the color table for each texel-index */
130 #ifdef GL_EXT_paletted_texture
132 #if defined(GL_EXT_shared_texture_palette) && defined(USE_SHARED_PALETTE)
133 printf("Using shared palette\n");
134 glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT
, /* target */
135 GL_RGBA
, /* internal format */
136 256, /* table size */
137 GL_RGBA
, /* table format */
138 GL_UNSIGNED_BYTE
, /* table type */
139 table
); /* the color table */
140 glEnable(GL_SHARED_TEXTURE_PALETTE_EXT
);
142 glColorTableEXT(GL_TEXTURE_2D
, /* target */
143 GL_RGBA
, /* internal format */
144 256, /* table size */
145 GL_RGBA
, /* table format */
146 GL_UNSIGNED_BYTE
, /* table type */
147 table
); /* the color table */
150 glTexImage2D(GL_TEXTURE_2D
, /* target */
152 GL_COLOR_INDEX8_EXT
, /* internal format */
153 WIDTH
, HEIGHT
, /* width, height */
155 GL_COLOR_INDEX
, /* texture format */
156 GL_UNSIGNED_BYTE
, /* texture type */
157 texture
); /* teh texture */
160 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
161 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
162 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
163 glEnable(GL_TEXTURE_2D
);
167 int main( int argc
, char *argv
[] )
169 glutInit( &argc
, argv
);
170 glutInitWindowPosition( 0, 0 );
171 glutInitWindowSize( 400, 400 );
173 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
175 glutCreateWindow(argv
[0]);
179 glutReshapeFunc( Reshape
);
180 glutKeyboardFunc( Key
);
181 glutDisplayFunc( Display
);
182 glutIdleFunc( Idle
);