- #include <iostream>
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_font.h>
- #include <allegro5/allegro_ttf.h>
- #include <allegro5/allegro_primitives.h>
- #include <gl/gl.h>
- #include <gl/glu.h>
- #include <allegro5/allegro_opengl.h>
- #include <stdlib.h>
- #include <stdio.h>
- using namespace std;
- /////////
- // Global variables specific to the demo
- static const unsigned int palleteSize = 3;
- struct palleteRGBA{
- unsigned char r;
- unsigned char g;
- unsigned char b;
- unsigned char a;
- };
- static palleteRGBA palette[palleteSize];
- // Just one texture right now.
- static const unsigned int numTextures = 1;
- GLuint textures[numTextures];
- // Texture Data
- // This contains INDICES into our palette array!
- static unsigned char textureToUse[256][256];
- /////////
- int main(int argc, char **argv)
- {
- ALLEGRO_DISPLAY *display = NULL;
- ALLEGRO_EVENT_QUEUE *event_queue = NULL;
- if(!al_init()) {
- fprintf(stderr, "failed to initialize allegro!\n");
- return -1;
- }
- al_set_new_display_flags(ALLEGRO_OPENGL);
- display = al_create_display(640, 480);
- if(!display) {
- fprintf(stderr, "failed to create display!\n");
- return -1;
- }
- event_queue = al_create_event_queue();
- if(!event_queue) {
- fprintf(stderr, "failed to create event_queue!\n");
- al_destroy_display(display);
- return -1;
- }
- ////////
- // Initialize OpenGL functions we want
- glEnable(GL_TEXTURE_2D);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glGenTextures(numTextures ,textures);
- // EXT OpenGL functions
- // This isn't passing.
- //*
- // define the type of the function
- ALLEGRO_DEFINE_PROC_TYPE(void, COLOR_TABLE_FUNC,
- (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *));
- //void glColorTableEXT(GLenum target,
- // GLenum internalformat,
- // GLsizei width,
- // GLenum format,
- // GLenum type,
- // const GLvoid *table)
- // declare the function pointer
- COLOR_TABLE_FUNC glColorTableEXT;
- // get the address of the function
- glColorTableEXT = (COLOR_TABLE_FUNC) al_get_opengl_proc_address("glColorTableEXT");
- //*/
- if(!al_have_opengl_extension("GL_EXT_paletted_texture"))
- //exit(1); // We don't have it!
- ////////
- // Initialize a palette (temporary) to use:
- // Red
- palette[0].r = 255;
- palette[0].g = 0;
- palette[0].b = 0;
- palette[0].a = 255;
- // Green
- palette[1].r = 0;
- palette[1].g = 255;
- palette[1].b = 0;
- palette[1].a = 255;
- // Blue
- palette[2].r = 0;
- palette[2].g = 0;
- palette[2].b = 255;
- palette[2].a = 255;
- // Populate the indicies
- for(int x = 0; x < 100; x++){
- for(int y = 0; y < 256; y++)
- textureToUse[x][y] = 0; //red
- }
- for(int x = 101; x < 200; x++){
- for(int y = 0; y < 256; y++)
- textureToUse[x][y] = 1; //green
- }
- for(int x = 201; x < 256; x++){
- for(int y = 0; y < 256; y++)
- textureToUse[x][y] = 2; //blue
- }
- al_register_event_source(event_queue, al_get_display_event_source(display));
- al_clear_to_color(al_map_rgb(0,0,0));
- al_flip_display();
- while(1)
- {
- ALLEGRO_EVENT ev;
- ALLEGRO_TIMEOUT timeout;
- al_init_timeout(&timeout, 0.06);
- bool get_event = al_wait_for_event_until(event_queue, &ev, &timeout);
- if(get_event && ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
- break;
- }
- //////////
- // Our OpenGL-Specific code goes here:
- glBindTexture(GL_TEXTURE_2D, 1);
- glColorTableEXT(GL_TEXTURE_2D, GL_RGBA8, 256, GL_RGBA, GL_UNSIGNED_BYTE, palette);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 256, 256, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, textureToUse);
- glBegin(GL_QUADS); // Draw A Quad
- glTexCoord2f(0.0f, 1.0f);glVertex3f(-1.0f, 1.0f, 0.0f);
- glTexCoord2f(1.0f, 1.0f);glVertex3f( 1.0f, 1.0f, 0.0f);
- glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
- glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
- glEnd();
- //////////
- al_clear_to_color(al_map_rgb(0,0,0));
- al_flip_display();
- }
- al_destroy_display(display);
- al_destroy_event_queue(event_queue);
- return 0;
- }