#include #include // The texture handles GLuint Tex[3]; // The texture filenames const char* TexFiles[3] = { "layer0.bmp", "layer1.bmp", "layer2.bmp" }; // The font we will be using FONT* Font; // Possible source factors const int NumSourceFactors = 9; const int SourceFactors[NumSourceFactors] = { GL_ONE, GL_ZERO, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA_SATURATE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA }; // Source factor names const char* SourceNames[NumSourceFactors] = { "GL_ONE", "GL_ZERO", "GL_DST_COLOR", "GL_ONE_MINUS_DST_COLOR", "GL_SRC_ALPHA_SATURATE", "GL_SRC_ALPHA", "GL_ONE_MINUS_SRC_ALPHA", "GL_DST_ALPHA", "GL_ONE_MINUS_DST_ALPHA" }; // Possible destination factors const int NumDestFactors = 8; const int DestFactors[NumDestFactors] = { GL_ONE, GL_ZERO, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA }; // Destination factor names const char* DestNames[NumDestFactors] = { "GL_ONE", "GL_ZERO", "GL_SRC_COLOR", "GL_ONE_MINUS_SRC_COLOR", "GL_SRC_ALPHA", "GL_ONE_MINUS_SRC_ALPHA", "GL_DST_ALPHA", "GL_ONE_MINUS_DST_ALPHA" }; void Init() { // Start up Allegro and AllegroGL systems allegro_init(); install_allegro_gl(); install_keyboard(); // Set the color depth to 32 - needed for some blending modes allegro_gl_set(AGL_COLOR_DEPTH, 32); allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH); // Set up a suitable viewing window set_color_depth(32); set_gfx_mode(GFX_OPENGL_WINDOWED, 256, 300, 0, 0); // Enable texturing and blending glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); // We are using 24 bit textures in this case. allegro_gl_set_texture_format(GL_RGB8); // Load the textures for(int i = 0; i < 3; i++) { BITMAP* temp_bmp = load_bitmap(TexFiles[i], 0); Tex[i] = allegro_gl_make_texture(temp_bmp); glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); destroy_bitmap(temp_bmp); } // Convert the default Allegro font to an AllegroGL font Font = allegro_gl_convert_allegro_font(font, AGL_FONT_TYPE_TEXTURED, 1.0); // Set up coordinates that mimic a per-pixel style glOrtho(0, SCREEN_W, 0, SCREEN_H, 1.0, -1.0); // Set the background color to black glClearColor(0.0, 0.0, 0.0, 0.0); } int main() { Init(); bool quit = false; int src_f = 0, dst_f = 0; float layer_alpha[3] = { 1.0, 0.8, 0.6 }; int key = 0; while(!quit) { // Clear the window glClear(GL_COLOR_BUFFER_BIT); // Draw the three layers for(int i = 0; i < 3; i++) { if(i == 0) glBlendFunc(GL_ONE, GL_ZERO); else if(i == 1) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); else glBlendFunc(SourceFactors[src_f], DestFactors[dst_f]); glBindTexture(GL_TEXTURE_2D, Tex[i]); glBegin(GL_QUADS); glColor4f(1.0, 1.0, 1.0, layer_alpha[i]); glTexCoord2i(0, 0); glVertex2i(0, 0); glTexCoord2i(1, 0); glVertex2i(255, 0); glTexCoord2i(1, 1); glVertex2i(255, 255); glTexCoord2i(0, 1); glVertex2i(0, 255); glEnd(); } glBlendFunc(GL_ONE, GL_ZERO); allegro_gl_printf(Font, 0, 300, 0, makeacol(255, 255, 255, 255), "SRC: %s", SourceNames[src_f]); allegro_gl_printf(Font, 0, 290, 0, makeacol(255, 255, 255, 255), "DST: %s", DestNames[dst_f]); allegro_gl_printf(Font, 0, 278, 0, makeacol(255, 255, 255, 255), "Top layer alpha: %f", layer_alpha[2]); allegro_gl_printf(Font, 0, 268, 0, makeacol(255, 255, 255, 255), "Bottom layer alpha: %f", layer_alpha[1]); glFlush(); // Wait for a keypress clear_keybuf(); key = readkey() >> 8; // Cycle through the different blending modes. if(key == KEY_S) src_f++; if(key == KEY_D) dst_f++; if(src_f >= NumSourceFactors) { src_f = 0; dst_f++; } if(dst_f >= NumDestFactors) { dst_f = 0; } // Adjust alpha of the two top layers. if(key == KEY_RIGHT) layer_alpha[2] += 0.05; if(key == KEY_LEFT) layer_alpha[2] -= 0.05; if(key == KEY_UP) layer_alpha[1] += 0.05; if(key == KEY_DOWN) layer_alpha[1] -= 0.05; // Quit if ESC is pressed if(key == KEY_ESC) { quit = true; } } return 0; } END_OF_MAIN();