/** \ingroup core * * Installs the AllegroGL addon to Allegro. * Allegro should already be initialized with allegro_init() * or install_allegro(). * * \return 0 on success; -1 on failure. * * \see remove_allegro_gl() */ int install_allegro_gl(void) { if (!system_driver) return -1; if (atexit(remove_allegro_gl)) return -1; if (system_driver->gfx_drivers) saved_gfx_drivers = system_driver->gfx_drivers; else saved_gfx_drivers = list_saved_gfx_drivers; system_driver->gfx_drivers = our_gfx_drivers; allegro_gl_clear_settings(); /* Save and replace old blit_between_formats methods */ #ifdef ALLEGRO_COLOR8 __blit_between_formats8 = __linear_vtable8.blit_between_formats; __linear_vtable8.blit_between_formats = allegro_gl_memory_blit_between_formats; #endif #ifdef ALLEGRO_COLOR16 __blit_between_formats15 = __linear_vtable15.blit_between_formats; __linear_vtable15.blit_between_formats = allegro_gl_memory_blit_between_formats; __blit_between_formats16 = __linear_vtable16.blit_between_formats; __linear_vtable16.blit_between_formats = allegro_gl_memory_blit_between_formats; #endif #ifdef ALLEGRO_COLOR24 __blit_between_formats24 = __linear_vtable24.blit_between_formats; __linear_vtable24.blit_between_formats = allegro_gl_memory_blit_between_formats; #endif #ifdef ALLEGRO_COLOR32 __blit_between_formats32 = __linear_vtable32.blit_between_formats; __linear_vtable32.blit_between_formats = allegro_gl_memory_blit_between_formats; #endif usetc(allegro_gl_error, 0); return 0; }
/** * Initialises the OpenGL and Allegro application. This function creates the global * Gui object that can be populated by various examples. */ void init() { // We simply initialise OpenGL and Allegro as we would do with any OpenGL // and Allegro application. allegro_init(); install_allegro_gl(); allegro_gl_clear_settings(); allegro_gl_set (AGL_COLOR_DEPTH, 32); allegro_gl_set (AGL_Z_DEPTH, 24); allegro_gl_set (AGL_FULLSCREEN, TRUE); allegro_gl_set (AGL_DOUBLEBUFFER, 1); allegro_gl_set (AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_Z_DEPTH | AGL_DOUBLEBUFFER); set_gfx_mode(GFX_OPENGL_WINDOWED, 640, 480, 0, 0); install_keyboard(); install_mouse(); install_timer(); glViewport(0, 0, 640, 480); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Now it's time to initialise the Guichan OpenGL back end // and the Guichan Allegro back end. imageLoader = new gcn::OpenGLAllegroImageLoader(); // The ImageLoader Guichan should use needs to be passed to the Image object // using a static function. gcn::Image::setImageLoader(imageLoader); graphics = new gcn::OpenGLGraphics(); // We need to tell the OpenGL Graphics object how big the screen is. graphics->setTargetPlane(640, 480); input = new gcn::AllegroInput(); // Now we create the Gui object to be used with this OpenGL // and Allegro application. globals::gui = new gcn::Gui(); // The Gui object needs a Graphics to be able to draw itself and an Input // object to be able to check for user input. In this case we provide the // Gui object with OpenGL and Allegro implementations of these objects hence // making Guichan able to utilise OpenGL and Allegro. globals::gui->setGraphics(graphics); globals::gui->setInput(input); }
int main () { allegro_init(); install_allegro_gl(); allegro_gl_clear_settings(); allegro_gl_set (AGL_COLOR_DEPTH, 32); allegro_gl_set (AGL_Z_DEPTH, 24); allegro_gl_set (AGL_FULLSCREEN, TRUE); allegro_gl_set (AGL_DOUBLEBUFFER, 1); allegro_gl_set (AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_Z_DEPTH | AGL_DOUBLEBUFFER | AGL_FULLSCREEN); if (set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0) < 0) { allegro_message ("Error setting OpenGL graphics mode:\n%s\n" "Allegro GL error : %s\n", allegro_error, allegro_gl_error); return -1; } install_keyboard(); install_timer(); LOCK_FUNCTION(secs_timer); LOCK_VARIABLE(secs); glShadeModel (GL_FLAT); glEnable (GL_DEPTH_TEST); glCullFace (GL_BACK); glEnable (GL_CULL_FACE); install_int (secs_timer, 1000); do { keyboard(); } while (!key[KEY_ESC]); set_gfx_mode (GFX_TEXT, 0, 0, 0, 0); allegro_message("Frames: %i, Seconds: %i, FPS: %f\n", frames, secs, (float)frames / (float)secs); return 0; }
int main() { FONT *lucidia_fnt; FONT *allegro_fnt; DATAFILE *dat; struct { float x, y, z; int c; } coord[NUM_STRINGS]; char *string = STRING; int i; allegro_init(); install_allegro_gl(); install_timer(); LOCK_FUNCTION(the_timer); LOCK_VARIABLE(chrono); install_int(the_timer, 2); allegro_gl_clear_settings(); allegro_gl_set(AGL_COLOR_DEPTH, 32); allegro_gl_set(AGL_Z_DEPTH, 24); allegro_gl_set(AGL_WINDOWED, TRUE); allegro_gl_set(AGL_DOUBLEBUFFER, 1); allegro_gl_set(AGL_RENDERMETHOD, 1); allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER | AGL_RENDERMETHOD | AGL_Z_DEPTH | AGL_WINDOWED); if (set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0)) { allegro_message("Error initializing OpenGL!\n"); return -1; } install_keyboard(); /* Load 2 copies of the datafile */ dat = load_datafile("lucidia.dat"); if (!dat) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to load lucidia.dat\n"); return -2; } lucidia_fnt = allegro_gl_convert_allegro_font((FONT*)dat[0].dat, AGL_FONT_TYPE_TEXTURED, 16.0); if (!lucidia_fnt) { unload_datafile(dat); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to convert font!\n"); return -3; } allegro_fnt = allegro_gl_convert_allegro_font(font, AGL_FONT_TYPE_TEXTURED, 16.0); if (!allegro_fnt) { allegro_gl_destroy_font(lucidia_fnt); unload_datafile(dat); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to convert font!\n"); return -4; } srand(time(NULL)); for (i = 0; i < NUM_STRINGS; i++) { coord[i].z = 0; coord[i].c = 0; } i = 0; /* Start nice text demo */ /* Setup OpenGL like we want */ glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glViewport(0, 0, SCREEN_W, SCREEN_H); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 60.0); /* Set culling mode - not that we have anything to cull */ glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glMatrixMode(GL_MODELVIEW); do { int c; /* Update rotation angle of text */ glLoadIdentity(); glTranslatef(0, 0, -30); glRotatef(-45, 1, 0, 0); glRotatef(-30, 0, 1, 0); /* Clear the screen and set a nice blender mode */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); /* Print the text wheel */ for (i = 0; i < NUM_STRINGS; i++) { allegro_gl_printf(lucidia_fnt, coord[i].x, coord[i].y, coord[i].z, coord[i].c, string); } /* Update the text wheel's position */ for (i = 0; i < NUM_STRINGS; i++) { int r, g, b; float angle2 = angle + i * M_PI * 2 / NUM_STRINGS; coord[i].x = 10 * cos(angle2) - 10; coord[i].y = 10 * sin(angle2); angle2 = angle2 * 180.0 / M_PI; #if ((((ALLEGRO_VERSION) << 16) | ((ALLEGRO_SUB_VERSION) << 8) | (ALLEGRO_WIP_VERSION)) == 0x40200) /* Work around an Allegro bug that's only in 4.2.0 */ while (angle2 > 360.0f) angle2 -= 360.0f; while (angle2 < 0) angle2 += 360.0f; #endif hsv_to_rgb(angle2, 1, 1, &r, &g, &b); coord[i].c = makeacol(r, g, b, 255); } /* Draw "AllegroGL" */ glLoadIdentity(); c = MID(0, (int)(255 - chrono / 100), 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING0) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 0, makecol(c, c, c), STRING0); c = MID(0, (int)(255 - chrono / 100) + 24, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING1) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 12, makecol(c, c, c), STRING1); c = MID(0, (int)(255 - chrono / 100) + 48, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING2) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 24, makecol(c, c, c), STRING2); c = MID(0, (int)(255 - chrono / 100) + 72, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING3) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 36, makecol(c, c, c), STRING3); c = MID(0, (int)(255 - chrono / 100) + 96, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING4) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 48, makecol(c, c, c), STRING4); c = MID(0, (int)(255 - chrono / 100) + 120, 255); allegro_gl_printf(allegro_fnt, -(strlen(URL) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 60, makecol(c, c, c), URL); allegro_gl_flip(); rest(2); } while (!key[KEY_ESC]); return 0; }
static int setup (void) { #define RESOLUTION_LIST 4 #define COLOUR_LIST 6 #define ZBUFFER_LIST 8 #define WINDOWED_BOX 9 #define DOUBLEBUFFER_BOX 10 #define BUTTON_OK 11 DIALOG dlg[] = { /* proc x y w h fg bg key flags d1 d2 dp */ { d_shadow_box_proc, 0, 0, 320, 200, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }, { d_ctext_proc, 160, 10, 0, 0, 0, 0, 0, 0, 0, 0, "____________", NULL, NULL }, { d_ctext_proc, 160, 8, 0, 0, 0, 0, 0, 0, 0, 0, "OpenGL Setup", NULL, NULL }, { d_text_proc, 10, 30, 0, 0, 0, 0, 0, 0, 0, 0, "Resolution", NULL, NULL }, { d_list_proc, 10, 40, 96, 52, 0, 0, 0, 0, 0, 0, resolution_lister, NULL, NULL }, { d_text_proc, 120, 30, 0, 0, 0, 0, 0, 0, 0, 0, "Colour depth", NULL, NULL }, { d_list_proc, 120, 40, 96, 48, 0, 0, 0, 0, 0, 0, colour_depth_lister, NULL, NULL }, { d_text_proc, 10, 104, 96, 48, 0, 0, 0, 0, 0, 0, "Z buffer", NULL, NULL }, { d_list_proc, 10, 114, 96, 48, 0, 0, 0, 0, 0, 0, zbuffer_depth_lister, NULL, NULL }, { d_check_proc, 10, 170, 96, 8, 0, 0, 0, 0, 1, 0, "Windowed", NULL, NULL }, { d_check_proc, 10, 180, 128, 8, 0, 0, 0,D_SELECTED, 1, 0, "Double Buffered", NULL, NULL }, { d_button_proc, 220, 150, 96, 18, 0, 0, 0, D_EXIT, 0, 0, "Ok", NULL, NULL }, { d_button_proc, 220, 174, 96, 18, 0, 0, 0, D_EXIT, 0, 0, "Exit", NULL, NULL }, { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }, { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } }; int x; if (mode == AGL_WINDOWED) dlg[WINDOWED_BOX].flags |= D_SELECTED; centre_dialog (dlg); set_dialog_color (dlg, makecol(0, 0, 0), makecol(255, 255, 255)); if (secs) { textprintf_centre_ex(screen, font, SCREEN_W / 2, SCREEN_H / 2 + 110, makecol(255, 255, 255), 0, "Frames: %i, Seconds: %i, FPS: %f", frames, secs, (float)frames / (float)secs); } x = do_dialog (dlg, 4); allegro_gl_clear_settings(); allegro_gl_set(AGL_COLOR_DEPTH, colour_depths[dlg[COLOUR_LIST].d1].depth); allegro_gl_set(AGL_Z_DEPTH, zbuffer_depths[dlg[ZBUFFER_LIST].d1].depth); allegro_gl_set(AGL_DOUBLEBUFFER, (dlg[DOUBLEBUFFER_BOX].flags & D_SELECTED) ? 1 : 0); allegro_gl_set(AGL_RENDERMETHOD, 1); mode = ((dlg[WINDOWED_BOX].flags & D_SELECTED) ? AGL_WINDOWED : AGL_FULLSCREEN); allegro_gl_set(mode, TRUE); allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_Z_DEPTH | AGL_DOUBLEBUFFER | AGL_RENDERMETHOD | mode); width = resolutions[dlg[RESOLUTION_LIST].d1].w; height = resolutions[dlg[RESOLUTION_LIST].d1].h; return (x == BUTTON_OK); }