/** * 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; }
void init() { allegro_init(); install_allegro_gl(); allegro_gl_set(AGL_Z_DEPTH, 16); allegro_gl_set(AGL_COLOR_DEPTH, 32); allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH); set_gfx_mode(GFX_OPENGL_WINDOWED, 1024, 1024, 0, 0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, SCREEN_W, SCREEN_H, 0, -10.0, 10.0); glEnable(GL_TEXTURE_2D); install_keyboard(); install_mouse(); }
void init() { allegro_init(); install_allegro_gl(); allegro_gl_set(AGL_Z_DEPTH, 16); allegro_gl_set(AGL_COLOR_DEPTH, 32); allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH); set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0); install_keyboard(); install_mouse(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0 * ASPECT_RATIO, 1.0 * ASPECT_RATIO, -1.0, 1.0, 2.0, 1000.0); glEnable(GL_DEPTH_TEST); disable_hardware_cursor(); }
int change_resolution(int fullscreen, int ResIndex) { int screen_mode; if(!IsInstalled) { return install(fullscreen,800,480,32); //Security mesure } KillTextures(); allegro_gl_set(AGL_COLOR_DEPTH, Resolutions->mode[ResIndex].bpp); if(fullscreen) screen_mode=GFX_OPENGL_FULLSCREEN; else screen_mode=GFX_OPENGL_WINDOWED; if (set_gfx_mode(screen_mode, Resolutions->mode[ResIndex].width,Resolutions->mode[ResIndex].height, 0, 0)) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set graphic mode\n%s\n", allegro_error); return 1; } SetOpenGL2D(); RefreshGLTextures(); AspectRatio=(float)SCREEN_W/(float)SCREEN_H; Fullscreen=fullscreen; Width=Resolutions->mode[ResIndex].width; Height=Resolutions->mode[ResIndex].height; depth=Resolutions->mode[ResIndex].bpp; ResolutionIndex=ResIndex; set_config_file("Resources/Setting.cfg"); set_config_int("graphics","Fullscreen",Fullscreen); set_config_int("graphics","Width",Width); set_config_int("graphics","Height",Height); set_config_int("graphics","depth",depth); set_config_int("graphics","ResolutionIndex",ResIndex); flush_config_file(); LoadSavegame(); return 0; }
/** \ingroup settings * * Loads the settings from the current config file, in the * section [OpenGL]. * Note that this function will not clear any settings currently * set, but will add them up, as if each of the setting were set * manually. * * \sa allegro_gl_save_settings() */ void allegro_gl_load_settings() { int set; char *section = "OpenGL"; set = get_config_int(section, "allegro_format", -1); if (set != -1) allegro_gl_set(AGL_ALLEGRO_FORMAT, set); set = get_config_int(section, "red_depth", -1); if (set != -1) allegro_gl_set(AGL_RED_DEPTH, set); set = get_config_int(section, "green_depth", -1); if (set != -1) allegro_gl_set(AGL_GREEN_DEPTH, set); set = get_config_int(section, "blue_depth", -1); if (set != -1) allegro_gl_set(AGL_BLUE_DEPTH, set); set = get_config_int(section, "alpha_depth", -1); if (set != -1) allegro_gl_set(AGL_ALPHA_DEPTH, set); set = get_config_int(section, "color_depth", -1); if (set != -1) allegro_gl_set(AGL_COLOR_DEPTH, set); set = get_config_int(section, "accum_red_depth", -1); if (set != -1) allegro_gl_set(AGL_ACC_RED_DEPTH, set); set = get_config_int(section, "accum_green_depth", -1); if (set != -1) allegro_gl_set(AGL_ACC_GREEN_DEPTH, set); set = get_config_int(section, "accum_blue_depth", -1); if (set != -1) allegro_gl_set(AGL_ACC_BLUE_DEPTH, set); set = get_config_int(section, "accum_alpha_depth", -1); if (set != -1) allegro_gl_set(AGL_ACC_ALPHA_DEPTH, set); set = get_config_int(section, "double_buffer", -1); if (set != -1) allegro_gl_set(AGL_DOUBLEBUFFER, set); set = get_config_int(section, "stereo_display", -1); if (set != -1) allegro_gl_set(AGL_STEREO, set); set = get_config_int(section, "aux_buffers", -1); if (set != -1) allegro_gl_set(AGL_AUX_BUFFERS, set); set = get_config_int(section, "z_depth", -1); if (set != -1) allegro_gl_set(AGL_Z_DEPTH, set); set = get_config_int(section, "stencil_depth", -1); if (set != -1) allegro_gl_set(AGL_STENCIL_DEPTH, set); set = get_config_int(section, "window_x", -1); if (set != -1) allegro_gl_set(AGL_WINDOW_X, set); set = get_config_int(section, "window_y", -1); if (set != -1) allegro_gl_set(AGL_WINDOW_Y, set); set = get_config_int(section, "fullscreen", -1); if (set != -1) allegro_gl_set(AGL_FULLSCREEN, set); set = get_config_int(section, "windowed", -1); if (set != -1) allegro_gl_set(AGL_WINDOWED, set); set = get_config_int(section, "video_memory_policy", -1); if (set != -1) allegro_gl_set(AGL_VIDEO_MEMORY_POLICY, set); set = get_config_int(section, "sample_buffers", -1); if (set != -1) allegro_gl_set(AGL_SAMPLE_BUFFERS, set); set = get_config_int(section, "samples", -1); if (set != -1) allegro_gl_set(AGL_SAMPLES, set); set = get_config_int(section, "float_color", -1); if (set != -1) allegro_gl_set(AGL_FLOAT_COLOR, set); set = get_config_int(section, "float_depth", -1); if (set != -1) allegro_gl_set(AGL_FLOAT_Z, set); agl_parse_section(AGL_REQUIRE, section, "require"); agl_parse_section(AGL_SUGGEST, section, "suggest"); }
/* Parses an input string to read settings */ static void agl_parse_section(int sec, char *section, char *name) { const char *end; char *buf; char *ptr; int strsize; int opt = 0; end = get_config_string(section, name, ""); strsize = ustrsizez(end); buf = (char*)malloc(sizeof(char) * strsize); if (!buf) { TRACE(PREFIX_E "parse_section: Ran out of memory " "while trying to allocate %i bytes!", (int)sizeof(char) * strsize); return; } memcpy(buf, end, strsize); end = buf + strsize; ptr = buf; while (ptr < end) { char *s = ustrtok_r(ptr, " ;|+", &ptr); if (!ustrcmp(s, "allegro_format")) opt |= AGL_ALLEGRO_FORMAT; if (!ustrcmp(s, "red_depth")) opt |= AGL_RED_DEPTH; if (!ustrcmp(s, "green_depth")) opt |= AGL_GREEN_DEPTH; if (!ustrcmp(s, "blue_depth")) opt |= AGL_BLUE_DEPTH; if (!ustrcmp(s, "alpha_depth")) opt |= AGL_ALPHA_DEPTH; if (!ustrcmp(s, "color_depth")) opt |= AGL_COLOR_DEPTH; if (!ustrcmp(s, "accum_red_depth")) opt |= AGL_ACC_RED_DEPTH; if (!ustrcmp(s, "accum_green_depth")) opt |= AGL_ACC_GREEN_DEPTH; if (!ustrcmp(s, "accum_blue_depth")) opt |= AGL_ACC_BLUE_DEPTH; if (!ustrcmp(s, "accum_alpha_depth")) opt |= AGL_ACC_ALPHA_DEPTH; if (!ustrcmp(s, "double_buffer")) opt |= AGL_DOUBLEBUFFER; if (!ustrcmp(s, "stereo_display")) opt |= AGL_STEREO; if (!ustrcmp(s, "aux_buffers")) opt |= AGL_AUX_BUFFERS; if (!ustrcmp(s, "z_depth")) opt |= AGL_Z_DEPTH; if (!ustrcmp(s, "stencil_depth")) opt |= AGL_STENCIL_DEPTH; if (!ustrcmp(s, "window_x")) opt |= AGL_WINDOW_X; if (!ustrcmp(s, "window_y")) opt |= AGL_WINDOW_Y; if (!ustrcmp(s, "fullscreen")) opt |= AGL_FULLSCREEN; if (!ustrcmp(s, "windowed")) opt |= AGL_WINDOWED; if (!ustrcmp(s, "video_memory_policy")) opt |= AGL_VIDEO_MEMORY_POLICY; if (!ustrcmp(s, "sample_buffers")) opt |= AGL_SAMPLE_BUFFERS; if (!ustrcmp(s, "samples")) opt |= AGL_SAMPLES; if (!ustrcmp(s, "float_color")) opt |= AGL_FLOAT_COLOR; if (!ustrcmp(s, "float_depth")) opt |= AGL_FLOAT_Z; } free(buf); allegro_gl_set(sec, opt); }
/** \ingroup settings * Sets a configuration option. * Use this routine to configure the framebuffer, *before* * setting a graphics mode. Options are integer constants, and all * values are effectively integers. * * Three of the options are special. #AGL_SUGGEST and * #AGL_REQUIRE are used to mark which of the other options * are merely suggestions and which are absolute requirements. If * the OpenGL implementation can't provide a feature which you mark * with #AGL_REQUIRE, the call to set_gfx_mode will fail. * If you don't mark an option as either suggested or required, that * option will be ignored (#AGL_DONTCARE). * You can OR (|) together the other constants when using one of * these three options to indicate your preferences for several * settings at one time. Selecting an option as one of the suggestion * modes will remove it from the others. For example, if you first set * the color depth to be required, but then decide that you want it to be * suggested instead, then the option will be removed from the required * settings. Setting any option to #AGL_DONTCARE will remove any previous * setting attributed to it, and default values will be used if necessary. * * The remaining options are: * <pre> * #AGL_ALLEGRO_FORMAT, * #AGL_RED_DEPTH, * #AGL_GREEN_DEPTH, * #AGL_BLUE_DEPTH, * #AGL_ALPHA_DEPTH, * #AGL_COLOR_DEPTH, * #AGL_ACC_RED_DEPTH, * #AGL_ACC_GREEN_DEPTH, * #AGL_ACC_BLUE_DEPTH, * #AGL_ACC_ALPHA_DEPTH, * #AGL_DOUBLEBUFFER, * #AGL_STEREO, * #AGL_AUX_BUFFERS, * #AGL_Z_DEPTH, * #AGL_STENCIL_DEPTH, * #AGL_WINDOW_X, * #AGL_WINDOW_Y, * #AGL_RENDERMETHOD * #AGL_FULLSCREEN * #AGL_WINDOWED * #AGL_VIDEO_MEMORY_POLICY * #AGL_SAMPLE_BUFFERS * #AGL_SAMPLES * #AGL_FLOAT_COLOR * #AGL_FLOAT_Z * </pre> * * \param option Selects which option to change. * \param value The new option value. * * \b Example: * <pre> * allegro_gl_set(#AGL_COLOR_DEPTH, 32); * allegro_gl_set(#AGL_RENDERMETHOD, 1); * allegro_gl_set(#AGL_REQUIRE, #AGL_COLOR_DEPTH | #AGL_RENDERMETHOD); * </pre> * * \sa allegro_gl_get(), allegro_gl_clear_settings() */ void allegro_gl_set(int option, int value) { switch (option) { /* Options stating importance of other options */ case AGL_REQUIRE: __allegro_gl_required_settings |= value; __allegro_gl_suggested_settings &= ~value; break; case AGL_SUGGEST: __allegro_gl_suggested_settings |= value; __allegro_gl_required_settings &= ~value; break; case AGL_DONTCARE: __allegro_gl_required_settings &= ~value; __allegro_gl_suggested_settings &= ~value; break; /* Options configuring the mode set */ case AGL_ALLEGRO_FORMAT: allegro_gl_display_info.allegro_format = value; break; case AGL_RED_DEPTH: allegro_gl_display_info.pixel_size.rgba.r = value; break; case AGL_GREEN_DEPTH: allegro_gl_display_info.pixel_size.rgba.g = value; break; case AGL_BLUE_DEPTH: allegro_gl_display_info.pixel_size.rgba.b = value; break; case AGL_ALPHA_DEPTH: allegro_gl_display_info.pixel_size.rgba.a = value; break; case AGL_COLOR_DEPTH: switch (value) { case 8: allegro_gl_set(AGL_RED_DEPTH, 3); allegro_gl_set(AGL_GREEN_DEPTH, 3); allegro_gl_set(AGL_BLUE_DEPTH, 2); allegro_gl_set(AGL_ALPHA_DEPTH, 0); break; case 15: allegro_gl_set(AGL_RED_DEPTH, 5); allegro_gl_set(AGL_GREEN_DEPTH, 5); allegro_gl_set(AGL_BLUE_DEPTH, 5); allegro_gl_set(AGL_ALPHA_DEPTH, 1); break; case 16: allegro_gl_set(AGL_RED_DEPTH, 5); allegro_gl_set(AGL_GREEN_DEPTH, 6); allegro_gl_set(AGL_BLUE_DEPTH, 5); allegro_gl_set(AGL_ALPHA_DEPTH, 0); break; case 24: case 32: allegro_gl_set(AGL_RED_DEPTH, 8); allegro_gl_set(AGL_GREEN_DEPTH, 8); allegro_gl_set(AGL_BLUE_DEPTH, 8); allegro_gl_set(AGL_ALPHA_DEPTH, value-24); break; } allegro_gl_display_info.colour_depth = value; break; case AGL_ACC_RED_DEPTH: allegro_gl_display_info.accum_size.rgba.r = value; break; case AGL_ACC_GREEN_DEPTH: allegro_gl_display_info.accum_size.rgba.g = value; break; case AGL_ACC_BLUE_DEPTH: allegro_gl_display_info.accum_size.rgba.b = value; break; case AGL_ACC_ALPHA_DEPTH: allegro_gl_display_info.accum_size.rgba.a = value; break; case AGL_DOUBLEBUFFER: allegro_gl_display_info.doublebuffered = value; break; case AGL_STEREO: allegro_gl_display_info.stereo = value; break; case AGL_AUX_BUFFERS: allegro_gl_display_info.aux_buffers = value; break; case AGL_Z_DEPTH: allegro_gl_display_info.depth_size = value; break; case AGL_STENCIL_DEPTH: allegro_gl_display_info.stencil_size = value; break; case AGL_WINDOW_X: allegro_gl_display_info.x = value; break; case AGL_WINDOW_Y: allegro_gl_display_info.y = value; break; case AGL_RENDERMETHOD: allegro_gl_display_info.rmethod = value; break; case AGL_FULLSCREEN: allegro_gl_display_info.fullscreen = value; break; case AGL_WINDOWED: allegro_gl_display_info.fullscreen = !value; break; case AGL_VIDEO_MEMORY_POLICY: if ((value == AGL_KEEP) || (value == AGL_RELEASE)) allegro_gl_display_info.vidmem_policy = value; break; case AGL_SAMPLE_BUFFERS: allegro_gl_display_info.sample_buffers = value; break; case AGL_SAMPLES: allegro_gl_display_info.samples = value; break; case AGL_FLOAT_COLOR: allegro_gl_display_info.float_color = value; break; case AGL_FLOAT_Z: allegro_gl_display_info.float_depth = value; break; } }
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); }
int main() { /* Setup Allegro/AllegroGL */ if (allegro_init()) return 1; if (install_allegro_gl()) return 1; if (install_keyboard() < 0) { allegro_message("Unable to install keyboard\n"); return 1; } if (install_mouse() == -1) { allegro_message("Unable to install mouse\n"); return 1; } if (install_timer() < 0) { allegro_message("Unable to install timers\n"); return 1; } /* lock timer */ LOCK_VARIABLE(rotation_counter); LOCK_FUNCTION(rotation_counter_handler); /* set desktop resolution */ DESKTOP_W = GetSystemMetrics(SM_CXVIRTUALSCREEN); DESKTOP_H = GetSystemMetrics(SM_CYVIRTUALSCREEN); /* get monitor resolution/count */ int monitor_count; MONITOR *monitors = get_monitors(&monitor_count); /* generate point data */ PLACE places[POINT_COUNT]; int c; for (c = 1; c < POINT_COUNT - 1; c++) { places[c].x = sin((M_PI * (GLfloat)c) / 10.0f) * 200.0f; places[c].y = cos((M_PI * (GLfloat)c) / 10.0f) * 200.0f; } places[0].x = 0.01; places[0].y = 200.0f; places[POINT_COUNT - 1].x = 0.01; places[POINT_COUNT - 1].y = -200.0f; /* setup display */ allegro_gl_set(AGL_Z_DEPTH, 8); allegro_gl_set(AGL_COLOR_DEPTH, 16); allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH); glDepthFunc(GL_LEQUAL); if (set_gfx_mode(GFX_OPENGL_WINDOWED_BORDERLESS, DESKTOP_W, DESKTOP_H, 0, 0)) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set graphic mode\n%s\n", allegro_error); return 1; } /* move window so it covers the desktop */ position_window(0, 0); /* fake information to use if only 1 monitor */ MONITOR fake = {0, 512, 512, 512}; /* setup lighting model */ glShadeModel(GL_FLAT); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); GLfloat ambient[] = { 0.1f, 0.1f, 0.1f }; glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); int selected = -1; /* the point currently being moved */ GLfloat rotation[3] = {0, 0, 0}; /* the rotation of the mesh */ install_int(rotation_counter_handler, 20); /* install the rotation handler */ /* enter main program loop */ while(!key[KEY_ESC]) { while (rotation_counter > 0) { /* rotate the mesh */ rotation[0] += M_PI / 24.0f; rotation[1] += M_PI / 16.0f; rotation[2] += M_PI / 8.0f; rotation_counter--; } /* clear the buffers */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* process monitor 0 */ MONITOR *m = &monitors[0]; /* adjust mouse so its relative to the monitor */ int mx = (mouse_x - m->x) - (m->w / 2); int my = (mouse_y - m->y) - (m->h / 2); /* if the left mouse is pushed, find a close point */ if (mouse_b & 1) { if (selected == -1) { GLfloat distance = 10; for (c = 0; c < POINT_COUNT; c++) { GLfloat dx = mx - places[c].x; GLfloat dy = my - places[c].y; GLfloat d = sqrt(dx * dx + dy * dy); if (d < distance) { distance = d; selected = c; } } } } else selected = -1; /* move selected point */ if (selected >= 0) { places[selected].x = mx; places[selected].y = my; } /* center the viewport on monitor */ glViewport(m->x, DESKTOP_H - m->h - m->y, m->w, m->h); /* setup viewport projection */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-m->w / 2, m->w / 2, m->h / 2, -m->h / 2); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* draw points */ glColor3ub(0, 255, 0); glBegin(GL_LINE_STRIP); for (c = 0; c < POINT_COUNT; c++) { glVertex2f(places[c].x, places[c].y); } glEnd(); glColor3ub(255, 255, 255); for (c = 0; c < POINT_COUNT; c++) { draw_square(places[c].x, places[c].y, 10); } /* draw vertical line */ glBegin(GL_LINE_STRIP); glVertex2f(0.0f, -m->h); glVertex2f(0.0f, m->h); glEnd(); /* draw the mouse */ glColor3ub(255, 255, 255); draw_square(mx, my, 20); /* process viewport 1 */ /* select second monitor */ if (monitor_count > 1) { /* if 2nd monitor exists use it */ m = &monitors[1]; } else { /* use fake monitor */ m = &fake; } /* adjust mouse so its relative to the monitor*/ mx = (mouse_x - m->x) - (m->w / 2); my = (mouse_y - m->y) - (m->h / 2); /* center the viewport on the monitor*/ glViewport(m->x, DESKTOP_H - m->h - m->y, m->w, m->h); /* setup viewport projection */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, (float)m->w / (float)m->h, 0.1f, 2000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* turn on lighting and depth testing */ glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); /* move mesh so its visible */ glTranslatef(0.0f, 0.0f, -1000.0f); /* rotate mesh */ glRotatef(rotation[0], 1.0f, 0.0f, 0.0f); glRotatef(rotation[1], 0.0f, 1.0f, 0.0f); glRotatef(rotation[2], 0.0f, 0.0f, 1.0f); GLfloat p1[3] = {0, 0, 0}; GLfloat p2[3] = {0, 0, 0}; GLfloat p3[3] = {0, 0, 0}; GLfloat p4[3] = {0, 0, 0}; GLfloat vec1[3]; GLfloat vec2[3]; GLfloat normal[3]; /* draw mesh to screen */ glColor3ub(0, 255, 0); for (c = 0; c < (POINT_COUNT - 1); c++) { GLfloat a1 = 0; GLfloat a2 = M_PI / 16.0f; GLfloat d1 = places[c].x; GLfloat d2 = places[c + 1].x; p1[0] = sin(a1) * d1; p1[1] = places[c].y; p1[2] = cos(a1) * d1; p2[0] = sin(a2) * d1; p2[1] = places[c].y; p2[2] = cos(a2) * d1; p3[0] = sin(a2) * d2; p3[1] = places[c + 1].y; p3[2] = cos(a2) * d2; p4[0] = sin(a1) * d2; p4[1] = places[c + 1].y; p4[2] = cos(a1) * d2; buildVector(vec1, p1, p2); buildVector(vec2, p1, p4); cross_product_f(vec2[0], vec2[1], vec2[2], vec1[0], vec1[1], vec1[2], &normal[0], &normal[1], &normal[2]); normalize_vector_f(&normal[0], &normal[1], &normal[2]); glBegin(GL_QUAD_STRIP); glNormal3fv(normal); glVertex3fv(p1); glVertex3fv(p4); int s = 0; for (s = 1; s < 32; s++) { a2 = (M_PI * (GLfloat)(s + 1)) / 16.0f; d1 = places[c].x; d2 = places[c + 1].x; copyPoint(p1, p2); copyPoint(p4, p3); p2[0] = sin(a2) * d1; p2[1] = places[c].y; p2[2] = cos(a2) * d1; p3[0] = sin(a2) * d2; p3[1] = places[c + 1].y; p3[2] = cos(a2) * d2; buildVector(vec1, p1, p2); buildVector(vec2, p1, p4); cross_product_f(vec2[0], vec2[1], vec2[2], vec1[0], vec1[1], vec1[2], &normal[0], &normal[1], &normal[2]); normalize_vector_f(&normal[0], &normal[1], &normal[2]); glNormal3fv(normal); glVertex3fv(p2); glVertex3fv(p3); } glEnd(); } /* turn off lighting and depth testing */ glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); /* if not using the fake monitor */ if (m != &fake) { /* setup viewport projection */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-m->w / 2, m->w / 2, m->h / 2, -m->h / 2); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* draw the mouse */ glColor3ub(255, 255, 255); draw_square(mx, my, 20); } /* flip the contents to the screen */ allegro_gl_flip(); } free(monitors); return 0; }
int install() { int screen_mode; if(IsInstalled) return 0; if(allegro_init()) return 1; if(install_allegro_gl()) return 1; set_window_title("Sharp Fighters"); Resolutions=get_gfx_mode_list(GFX_OPENGL_FULLSCREEN); LoadSettings(); LoadCollisionData(); if(install_keyboard()) return 1; if(install_timer()) return 1; if(install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL)) return 1; JoyStickEnabled=(install_joystick(JOY_TYPE_AUTODETECT)==0); JoyStickEnabled=JoyStickEnabled && num_joysticks; LoadInput(); if(install_fonts()) printf("One or more font files were not loaded.\n"); allegro_gl_set(AGL_COLOR_DEPTH, depth); allegro_gl_set(AGL_RENDERMETHOD, 1); allegro_gl_set(AGL_DOUBLEBUFFER, 1); allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER | AGL_RENDERMETHOD); if(Fullscreen) screen_mode=GFX_OPENGL_FULLSCREEN; else screen_mode=GFX_OPENGL_WINDOWED; if (set_gfx_mode(screen_mode, Width,Height, 0, 0)) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set graphic mode\n%s\n", allegro_error); return 1; } set_close_button_callback(close_button_handler); SetOpenGL2D(); screenimage=(IMAGE*)malloc(sizeof(IMAGE)); screenimage->ID=0; AspectRatio=(float)SCREEN_W/(float)SCREEN_H; if(install_int(Ticks,1)) return 1; if(install_int(ProcessKeys,25)) return 1; IsInstalled=1; return 0; }