1 /* $Id: paltex.c,v 1.4 2000/06/27 17:12:10 brianp Exp $ */
4 * Paletted texture demo. Written by Brian Paul.
5 * This program is in the public domain.
11 #define GL_GLEXT_LEGACY
15 static float Rot
= 0.0;
18 static void Idle( void )
25 static void Display( void )
27 glClear( GL_COLOR_BUFFER_BIT
);
30 glRotatef(Rot
, 0, 0, 1);
33 glTexCoord2f(0, 1); glVertex2f(-1, -0.5);
34 glTexCoord2f(1, 1); glVertex2f( 1, -0.5);
35 glTexCoord2f(1, 0); glVertex2f( 1, 0.5);
36 glTexCoord2f(0, 0); glVertex2f(-1, 0.5);
45 static void Reshape( int width
, int height
)
47 glViewport( 0, 0, width
, height
);
48 glMatrixMode( GL_PROJECTION
);
50 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
51 glMatrixMode( GL_MODELVIEW
);
53 glTranslatef( 0.0, 0.0, -7.0 );
57 static void Key( unsigned char key
, int x
, int y
)
70 static void Init( void )
74 static char texture
[HEIGHT
][WIDTH
] = {
78 " M M M EEEE SS A A ",
84 GLubyte table
[256][4];
86 if (!glutExtensionSupported("GL_EXT_paletted_texture")) {
87 printf("Sorry, GL_EXT_paletted_texture not supported\n");
91 /* load the color table for each texel-index */
113 #ifdef GL_EXT_paletted_texture
115 #if defined(GL_EXT_shared_texture_palette) && defined(USE_SHARED_PALETTE)
116 printf("Using shared palette\n");
117 glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT
, /* target */
118 GL_RGBA
, /* internal format */
119 256, /* table size */
120 GL_RGBA
, /* table format */
121 GL_UNSIGNED_BYTE
, /* table type */
122 table
); /* the color table */
123 glEnable(GL_SHARED_TEXTURE_PALETTE_EXT
);
125 glColorTableEXT(GL_TEXTURE_2D
, /* target */
126 GL_RGBA
, /* internal format */
127 256, /* table size */
128 GL_RGBA
, /* table format */
129 GL_UNSIGNED_BYTE
, /* table type */
130 table
); /* the color table */
133 glTexImage2D(GL_TEXTURE_2D
, /* target */
135 GL_COLOR_INDEX8_EXT
, /* internal format */
136 WIDTH
, HEIGHT
, /* width, height */
138 GL_COLOR_INDEX
, /* texture format */
139 GL_UNSIGNED_BYTE
, /* texture type */
140 texture
); /* teh texture */
143 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
144 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
145 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
146 glEnable(GL_TEXTURE_2D
);
150 int main( int argc
, char *argv
[] )
152 glutInit( &argc
, argv
);
153 glutInitWindowPosition( 0, 0 );
154 glutInitWindowSize( 400, 400 );
156 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
158 glutCreateWindow(argv
[0]);
162 glutReshapeFunc( Reshape
);
163 glutKeyboardFunc( Key
);
164 glutDisplayFunc( Display
);
165 glutIdleFunc( Idle
);