/* read_config: * Load settings from the configuration file, providing default values */ void read_global_config(const char *config) { ALLEGRO_CONFIG *c = al_load_config_file(config); if (!c) c = al_create_config(); fullscreen = get_config_int(c, "GFX", "fullscreen", fullscreen); bit_depth = get_config_int(c, "GFX", "bit_depth", bit_depth); screen_width = get_config_int(c, "GFX", "screen_width", screen_width); screen_height = get_config_int(c, "GFX", "screen_height", screen_height); window_width = get_config_int(c, "GFX", "window_width", window_height); window_height = get_config_int(c, "GFX", "window_height", screen_height); screen_samples = get_config_int(c, "GFX", "samples", screen_samples); use_vsync = get_config_int(c, "GFX", "vsync", use_vsync); logic_framerate = get_config_int(c, "TIMING", "logic_framerate", logic_framerate); limit_framerate = get_config_int(c, "TIMING", "limit_framerate", limit_framerate); max_frame_skip = get_config_int(c, "TIMING", "max_frame_skip", max_frame_skip); display_framerate = get_config_int(c, "TIMING", "display_framerate", display_framerate); reduce_cpu_usage = get_config_int(c, "TIMING", "reduce_cpu_usage", reduce_cpu_usage); sound_volume = get_config_int(c, "SOUND", "sound_volume", sound_volume); music_volume = get_config_int(c, "SOUND", "music_volume", music_volume); set_sound_volume(sound_volume / 10.0); set_music_volume(music_volume / 10.0); controller_id = get_config_int(c, "CONTROLS", "controller_id", controller_id); al_destroy_config(c); }
void InitConfig(void) { ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH); ALLEGRO_PATH *data = al_create_path("SuperDerpy.ini"); al_join_paths(path, data); config = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP)); if (!config) config=al_create_config(); al_destroy_path(path); al_destroy_path(data); }
void ConfigfileCreateConfig(void) { if (Configfile.config != NULL) { al_destroy_config(Configfile.config); Configfile.config = NULL; } Configfile.config = al_create_config(); }
ALLEGRO_CONFIG * create_config (void) { ALLEGRO_CONFIG *config = al_create_config (); if (! config) error (0, 0, "%s (void): failed to create configuration", __func__); return config; }
static mrb_value config_create(mrb_state *mrb, mrb_value self) { ALLEGRO_CONFIG *cfg; struct RData *data; cfg = al_create_config(); if (!cfg) { mrb_raise(mrb, E_ALLEGRO_ERROR, "could not create config"); } data = mrb_data_object_alloc(mrb, mrb_class_ptr(self), cfg, &mrbal_config_data_type); return mrb_obj_value(data); }
SYMBOL_EXPORT void InitConfig(struct Game* game) { const ALLEGRO_FILE_INTERFACE* iface = al_get_new_file_interface(); al_set_standard_file_interface(); ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH); ALLEGRO_PATH* data = al_create_path("SuperDerpy.ini"); al_join_paths(path, data); game->_priv.config = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP)); if (!game->_priv.config) { game->_priv.config = al_create_config(); } al_destroy_path(path); al_destroy_path(data); al_set_new_file_interface(iface); }
void EngineConfig::save(std::string filename) { if (m_Config == NULL) { m_Config = al_create_config(); } saveResolutionWidth(); saveResolutionHeight(); saveFullscreen(); saveFrameSpeed(); al_save_config_file(filename.c_str(), m_Config); }
static void read_allegro_cfg(void) { /* We assume that the stdio file interface is in effect. */ ALLEGRO_PATH *path; ALLEGRO_CONFIG *temp; if (!sys_config) sys_config = al_create_config(); #if defined(ALLEGRO_UNIX) && !defined(ALLEGRO_IPHONE) temp = al_load_config_file("/etc/allegro5rc"); if (temp) { al_merge_config_into(sys_config, temp); al_destroy_config(temp); } path = _al_unix_get_path(ALLEGRO_USER_HOME_PATH); if (path) { al_set_path_filename(path, "allegro5rc"); temp = al_load_config_file(al_path_cstr(path, '/')); if (temp) { al_merge_config_into(sys_config, temp); al_destroy_config(temp); } al_set_path_filename(path, ".allegro5rc"); temp = al_load_config_file(al_path_cstr(path, '/')); if (temp) { al_merge_config_into(sys_config, temp); al_destroy_config(temp); } al_destroy_path(path); } #endif path = early_get_exename_path(); if (path) { al_set_path_filename(path, "allegro5.cfg"); temp = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP)); if (temp) { al_merge_config_into(sys_config, temp); al_destroy_config(temp); } al_destroy_path(path); } /* Reconfigure logging in case something changed. */ _al_configure_logging(); }
static void write_scores(void) { ALLEGRO_CONFIG *cfg = al_create_config(); for (int i = 0; i < NUM_SCORES; i++) { char name[] = {'n', (char)('0'+i), '\0'}; char score[] = {'s', (char)('0'+i), '\0'}; char sc[32]; al_set_config_value(cfg, "scores", name, highScores[i].name); snprintf(sc, sizeof(sc), "%d", highScores[i].score); al_set_config_value(cfg, "scores", score, sc); } ALLEGRO_PATH *fn = userResourcePath(); al_set_path_filename(fn, "scores.cfg"); al_save_config_file(al_path_cstr(fn, ALLEGRO_NATIVE_PATH_SEP), cfg); al_destroy_path(fn); al_destroy_config(cfg); }
bool initialize_allegro(al_defs* al){ if(!al_init()){ fprintf(stderr, "[Sokoban] Failed to initialize graphics. \n"); return 0; } al->conf = al_load_config_file("res/config.ini"); if(!al->conf){ al->conf = al_create_config(); al_save_config_file("res/config.ini", al->conf); } al->width = atoi(al_get_config_value(al->conf, "window", "width")); al->height = atoi(al_get_config_value(al->conf, "window", "height")); al->disp = al_create_display(al->width, al->height); if(!al->disp){ fprintf(stderr, "[Sokoban] Failed to create display. \n"); return 0; } if(!al_init_image_addon()){ fprintf(stderr, "[Sokoban] Cannot initialize image addon. \n"); return 0; } if(!al_install_keyboard()){ fprintf(stderr, "[Sokoban] Cannot install keyboard. \n"); return 0; } al_init_font_addon(); if(!al_init_ttf_addon()){ fprintf(stderr, "[Sokoban] Cannot initialize fonts."); return 0; } load_resources(al); return 1; }
bool criar_configuracao(char *name){ /** Colocar a lista de configuracoes padroes aqui. */ ALLEGRO_CONFIG *new_config; new_config = al_create_config(); setar_configuracao("CAM_DIVISOR", "1.5", "camera", new_config); setar_configuracao("LUMINUS", "80", "camera", new_config); setar_configuracao("TIMER_DIVIDENDO", "1.0", "allegro", new_config); setar_configuracao("LARGURA", "1280", "allegro", new_config); setar_configuracao("ALTURA", "720", "allegro", new_config); setar_configuracao("IDIOMA", "data/idiomas/pt_br.conf", "system", new_config); setar_configuracao("DEBUG", "false", "system", new_config); if(!al_save_config_file(name, new_config)) { free(new_config); erro("Erro na criacao do arquivo de configuracao inicial\n"); } free(new_config); return TRUE; }
/** initializes a skin structure. Creates a new empty allegro config for the skin structure. @param skin skin structure to initialize. */ void algui_init_skin(ALGUI_SKIN *skin) { assert(skin); skin->filename = al_ustr_new(""); skin->config = al_create_config(); }
/* Function: al_get_system_config */ ALLEGRO_CONFIG *al_get_system_config(void) { if (!sys_config) sys_config = al_create_config(); return sys_config; }
int main(void) { int X_ROOMS=13; int Y_ROOMS=16; int X_ROOM_SIZE=256; int Y_ROOM_SIZE=128; int SCALE_FACTOR=4; int X_TILE_SIZE=8; int Y_TILE_SIZE=8; int LAST_OBJECT=0; int actid=0; int error=0; ALLEGRO_CONFIG *cfg; ALLEGRO_BITMAP *bmp,*virt,*tmp=NULL; ALLEGRO_DISPLAY *display; ALLEGRO_KEYBOARD_STATE key; ALLEGRO_FONT *font; signed int xcursor=0; signed int ycursor=0; signed char x=0; signed char y=0; signed char finex=0; signed char finey=0; char finish=0; ALLEGRO_COLOR black,white,red,color; int scale_cursor_x=0; int scale_cursor_y=0; int i=0; int a=0; unsigned char r,g,b=0; char pngfilename[20]; char *tmpbuf; char buf[5]; char buf2[5]; /* Iniciar el rollo */ tmpbuf=(char *)malloc(sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE); memset(tmpbuf,0,sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE); al_init(); al_init_image_addon(); al_init_primitives_addon(); al_init_font_addon(); al_init_ttf_addon(); cfg=al_load_config_file("sacagraf.cfg"); if (cfg==NULL) { cfg=al_create_config(); al_add_config_section(cfg,"Ajustes"); al_add_config_section(cfg,"Objetos"); al_set_config_value(cfg,"Ajustes","Habitaciones en horizontal","13"); al_set_config_value(cfg,"Ajustes","Habitaciones en vertical","16"); al_set_config_value(cfg,"Ajustes","Ancho de la habitacion original en pixels","256"); al_set_config_value(cfg,"Ajustes","Alto de la habitacion original en pixels","128"); al_set_config_value(cfg,"Ajustes","Ancho minimo del caracter original","8"); al_set_config_value(cfg,"Ajustes","Alto minimo del caracter original","8"); al_set_config_value(cfg,"Ajustes","Factor de escalado","4"); al_set_config_value(cfg,"Objetos","Ultimo","0"); al_save_config_file("sacagraf.cfg",cfg); } X_ROOMS=atoi(al_get_config_value(cfg,"Ajustes","Habitaciones en horizontal")); Y_ROOMS=atoi(al_get_config_value(cfg,"Ajustes","Habitaciones en vertical")); X_ROOM_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Ancho de la habitacion original en pixels")); Y_ROOM_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Alto de la habitacion original en pixels")); SCALE_FACTOR=atoi(al_get_config_value(cfg,"Ajustes","Factor de escalado")); X_TILE_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Alto minimo del caracter original")); Y_TILE_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Ancho minimo del caracter original")); LAST_OBJECT=atoi(al_get_config_value(cfg,"Objetos","Ultimo")); actid=LAST_OBJECT; al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED); display=al_create_display(X_ROOM_SIZE*SCALE_FACTOR,192*SCALE_FACTOR); bmp=al_load_bitmap("map.png"); virt=al_create_bitmap(X_ROOM_SIZE*SCALE_FACTOR,Y_ROOM_SIZE*SCALE_FACTOR); font=al_load_ttf_font("proggy.ttf",6*SCALE_FACTOR,0); al_install_keyboard(); black=al_map_rgb(0,0,0); white=al_map_rgba_f(1,1,1,1); red=al_map_rgba_f(1,0,0,0.7); /* Que empiece la fiesta */ while(!finish) { al_get_keyboard_state(&key); if (al_key_down(&key,ALLEGRO_KEY_ESCAPE)) { finish=1; } if (al_key_down(&key,ALLEGRO_KEY_LCTRL)) { finex=0; finey=0; if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { x++; if (x==X_ROOMS) x=X_ROOMS-1; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { x--; if (x<0) x=0; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { y--; if (y<0) y=0; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { y++; if (y>Y_ROOMS-1) y=Y_ROOMS-1; } } else if (al_key_down(&key,ALLEGRO_KEY_LSHIFT)) { if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { finex++; if (finex>X_TILE_SIZE) finex=X_TILE_SIZE; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { finex--; if (finex<-X_TILE_SIZE) finex=-X_TILE_SIZE; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { finey--; if (finey<-Y_TILE_SIZE) finey=-Y_TILE_SIZE; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { finey++; if (finey>Y_TILE_SIZE) finey=Y_TILE_SIZE; } } else if (al_key_down(&key,ALLEGRO_KEY_ALT)) { if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { scale_cursor_x++; //if (finex>8) finex=8; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { scale_cursor_x--; //if (finex<0) finex=0; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { scale_cursor_y--; //if (finey<0) finey=0; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { scale_cursor_y++; //if (finey>8) finey=8; } } else { if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { xcursor+=X_TILE_SIZE*SCALE_FACTOR; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { xcursor-=X_TILE_SIZE*SCALE_FACTOR; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { ycursor-=Y_TILE_SIZE*SCALE_FACTOR; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { ycursor+=Y_TILE_SIZE*SCALE_FACTOR; } } al_clear_to_color(black); al_set_target_bitmap(virt); //al_set_blender(ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA,white); al_draw_bitmap_region(bmp,0+(x*X_ROOM_SIZE)+finex,0+(y*Y_ROOM_SIZE)+finey,X_ROOM_SIZE,Y_ROOM_SIZE,0,0,0); al_set_target_bitmap(al_get_backbuffer(display)); al_draw_scaled_bitmap(virt,0,0,X_ROOM_SIZE,Y_ROOM_SIZE,0,0,X_ROOM_SIZE*SCALE_FACTOR,Y_ROOM_SIZE*SCALE_FACTOR,0); al_draw_line(0,512,1024,512,white,0); al_draw_textf(font,al_map_rgba(200,200,200,200),0,520,0,"mapa x: %d mapa y: %d habitacion nº: %d ajuste fino x: %d ajuste fijo y: %d",x,y,x+(y*13),finex,finey); if (error) { al_draw_textf(font,al_map_rgba(200,200,200,200),0,540,0,"Patron repetido"); al_flip_display(); al_rest(1); error=0; } if (al_key_down(&key,ALLEGRO_KEY_ENTER)) { tmp=al_create_bitmap((X_TILE_SIZE*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x),(Y_TILE_SIZE*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)); al_set_target_bitmap(tmp); al_draw_bitmap_region(al_get_backbuffer(display),xcursor,ycursor,(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x)+(X_TILE_SIZE*SCALE_FACTOR),(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)+(Y_TILE_SIZE*SCALE_FACTOR),0,0,0); memset(tmpbuf,0,sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE); memset(buf,0,5); for (i=0;i<(Y_TILE_SIZE*scale_cursor_y*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR);i+=SCALE_FACTOR) { for (a=0;a<(X_TILE_SIZE*scale_cursor_x*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR);a+=SCALE_FACTOR) { color=al_get_pixel(tmp,a,i); al_unmap_rgb(color,&r,&g,&b); if (!r && !g && !b) { strcat(tmpbuf,"0"); } else { strcat(tmpbuf,"1"); } } } /* Ya está la secuencia del gráfico en tmpbuf, examinamos todas las secuencias anteriores */ error=0; for (i=0;i<actid;i++) { memset(buf2,0,5); sprintf(buf2,"%d",i); if (!strcmp(al_get_config_value(cfg,"Objetos",buf2),tmpbuf)) { error=i; } } /* Si no hay secuencias repetidas lo grabamos */ if (!error) { sprintf(buf,"%d",actid); al_set_config_value(cfg,"Objetos",buf,tmpbuf); memset(pngfilename,0,20); sprintf(pngfilename,"dec%d.png",actid); al_save_bitmap(pngfilename,tmp); actid++; } al_destroy_bitmap(tmp); } al_set_target_bitmap(al_get_backbuffer(display)); //al_set_blender(ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA,red); al_draw_filled_rectangle(xcursor,ycursor,xcursor+((X_TILE_SIZE*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x)),ycursor+((Y_TILE_SIZE*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)),red); al_flip_display(); al_rest(0.1); } memset(buf,0,5); sprintf(buf,"%d",actid); al_set_config_value(cfg,"Objetos","Ultimo",buf); al_save_config_file("sacagraf.cfg",cfg); al_destroy_font(font); al_uninstall_keyboard(); al_destroy_bitmap(bmp); al_destroy_bitmap(virt); al_destroy_display(display); al_destroy_config(cfg); al_shutdown_ttf_addon(); al_shutdown_font_addon(); al_shutdown_image_addon(); al_shutdown_primitives_addon(); free(tmpbuf); return 0; }
GAME * game_init () { if (!al_init ()) { fprintf (stderr, "Failed to initialize Allegro.\n"); return NULL; } if (!al_init_image_addon ()) { fprintf (stderr, "Failed to initialize image addon.\n"); return NULL; } if (!al_install_keyboard ()) { fprintf (stderr, "Failed to install keyboard.\n"); return NULL; } al_init_font_addon (); if (!al_init_ttf_addon ()) { fprintf (stderr, "Failed to initialize ttf addon.\n"); return NULL; } if (!al_init_primitives_addon ()) { fprintf (stderr, "Failed to initialize primitives addon.\n"); return NULL; } GAME *game = al_malloc (sizeof (GAME)); if (!game) return NULL; srand (time (NULL)); game->running = true; game->paused = false; game->fullscreen = 1; game->windowed = 1; game->rrate = 60; game->suggest_vsync = 1; game->force_vsync = 0; game->current_npc = NULL; game->screen = screen_new (); char *filename; const char *str; filename = get_resource_path_str ("data/game.ini"); ALLEGRO_CONFIG *game_config = al_load_config_file (filename); al_free (filename); str = al_get_config_value (game_config, "", "org"); al_set_org_name (str); str = al_get_config_value (game_config, "", "app"); al_set_app_name (str); ALLEGRO_PATH *settpath = al_get_standard_path (ALLEGRO_USER_SETTINGS_PATH); ALLEGRO_PATH *gcpath = al_clone_path (settpath); al_set_path_filename (gcpath, "general.ini"); const char * gcpath_str = al_path_cstr (gcpath, ALLEGRO_NATIVE_PATH_SEP); ALLEGRO_CONFIG *gconfig = al_load_config_file (gcpath_str); if (!gconfig) { gconfig = al_create_config (); al_make_directory (al_path_cstr (settpath, ALLEGRO_NATIVE_PATH_SEP)); set_config_i (gconfig, "display", "width", game->screen.width); set_config_i (gconfig, "display", "height", game->screen.height); set_config_i (gconfig, "display", "fullscreen", game->fullscreen); set_config_i (gconfig, "display", "windowed", game->windowed); set_config_i (gconfig, "display", "refreshrate", game->rrate); set_config_i (gconfig, "display", "suggest_vsync", game->suggest_vsync); set_config_i (gconfig, "display", "force_vsync", game->force_vsync); } else { get_config_i (gconfig, "display", "width", &game->screen.width); get_config_i (gconfig, "display", "height", &game->screen.height); get_config_i (gconfig, "display", "fullscreen", &game->fullscreen); get_config_i (gconfig, "display", "windowed", &game->windowed); get_config_i (gconfig, "display", "refreshrate", &game->rrate); get_config_i (gconfig, "display", "suggest_vsync", &game->suggest_vsync); get_config_i (gconfig, "display", "force_vsync", &game->force_vsync); } al_save_config_file (gcpath_str, gconfig); al_destroy_path (settpath); al_destroy_path (gcpath); al_destroy_config (gconfig); int flags = 0; if (game->fullscreen == game->windowed) flags |= ALLEGRO_FULLSCREEN_WINDOW; else if (game->fullscreen) flags |= ALLEGRO_FULLSCREEN; else flags |= ALLEGRO_WINDOWED; al_set_new_display_option (ALLEGRO_VSYNC, game->suggest_vsync, ALLEGRO_SUGGEST); al_set_new_display_option (ALLEGRO_DEPTH_SIZE, 8, ALLEGRO_SUGGEST); al_set_new_display_flags (flags); al_set_new_display_refresh_rate (game->rrate); game->display = al_create_display (game->screen.width, game->screen.height); if (!game->display) { fprintf (stderr, "Failed to create display.\n"); al_free (game); return NULL; } al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP); game->timer = al_create_timer (1.0 / FPS); if (!game->timer) { fprintf (stderr, "Failed to create timer.\n"); al_free (game); return NULL; } game->screen.width = al_get_display_width (game->display); game->screen.height = al_get_display_height (game->display); screen_update_size (&game->screen, game->screen.width, game->screen.height); game->rrate = al_get_display_refresh_rate (game->display); game->event_queue = al_create_event_queue (); if (!game->event_queue) { fprintf (stderr, "Failed to create event queue.\n"); al_free (game); return NULL; } al_register_event_source (game->event_queue, al_get_display_event_source (game->display)); al_register_event_source (game->event_queue, al_get_timer_event_source (game->timer)); al_set_render_state (ALLEGRO_ALPHA_FUNCTION, ALLEGRO_RENDER_EQUAL); al_set_render_state (ALLEGRO_ALPHA_TEST_VALUE, 1); filename = get_resource_path_str ("data/sprites.ini"); game->sprites = sprite_load_sprites (filename); al_free (filename); filename = get_resource_path_str ("data/scenes.ini"); game->scenes = scene_load_file (filename); scene_load_scenes (game->scenes, game->sprites); al_free (filename); str = al_get_config_value (game_config, "", "scene"); game->current_scene = scene_get (game->scenes, str); str = al_get_config_value (game_config, "", "actor"); game->current_actor = sprite_new_actor (game->sprites, str); str = al_get_config_value (game_config, "", "portal"); SCENE_PORTAL *portal = scene_get_portal (game->scenes, str); al_destroy_config (game_config); filename = get_resource_path_str ("data/ui.ini"); game->ui = ui_load_file (filename); al_free (filename); sprite_center (game->current_actor, &portal->position); screen_center (&game->screen, portal->position, game->current_scene->map); return game; }
int main(void) { ALLEGRO_DISPLAY *display; ALLEGRO_TIMER *timer; ALLEGRO_EVENT_QUEUE *queue; int redraw = 0, i; bool quit = false; if (!al_init()) { abort_example("Could not initialise Allegro\n"); return 1; } al_init_primitives_addon(); al_install_mouse(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); srand(time(NULL)); white = al_map_rgba_f(1, 1, 1, 1); display = al_create_display(640, 480); if (!display) { abort_example("Could not create display\n"); return 1; } al_set_window_title(display, "Allegro Logo Generator"); al_install_keyboard(); /* Read logo parameters from logo.ini (if it exists). */ config = al_load_config_file("logo.ini"); if (!config) config = al_create_config(); for (i = 0; param_names[i]; i++) { char const *value = al_get_config_value(config, "logo", param_names[i]); if (value) strncpy(param_values[i], value, sizeof(param_values[i])); } font = al_load_font("data/DejaVuSans.ttf", 12, 0); if (!font) { abort_example("Could not load font\n"); return 1; } timer = al_create_timer(1.0 / 60); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_mouse_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); al_start_timer(timer); while (!quit) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (event.type == ALLEGRO_EVENT_KEY_CHAR) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { quit = true; } else if (event.keyboard.keycode == ALLEGRO_KEY_ENTER) { if (editing) { regenerate = true; editing = false; } else { cursor = 0; editing = true; } } else if (event.keyboard.keycode == ALLEGRO_KEY_UP) { if (selection > 0) { selection--; cursor = 0; editing = false; } } else if (event.keyboard.keycode == ALLEGRO_KEY_DOWN) { if (param_names[selection + 1]) { selection++; cursor = 0; editing = false; } } else { int c = event.keyboard.unichar; if (editing) { if (c >= 32) { ALLEGRO_USTR *u = al_ustr_new(param_values[selection]); al_ustr_set_chr(u, cursor, c); cursor++; al_ustr_set_chr(u, cursor, 0); strncpy(param_values[selection], al_cstr(u), sizeof param_values[selection]); al_ustr_free(u); } } else { if (c == 'r') randomize(); if (c == 's') save(); } } } if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { if (event.mouse.button == 1) { mouse_click(event.mouse.x, event.mouse.y); } } if (event.type == ALLEGRO_EVENT_TIMER) redraw++; if (redraw && al_is_event_queue_empty(queue)) { redraw = 0; render(); al_flip_display(); } } /* Write modified parameters back to logo.ini. */ for (i = 0; param_names[i]; i++) { al_set_config_value(config, "logo", param_names[i], param_values[i]); } al_save_config_file("logo.ini", config); al_destroy_config(config); return 0; }
int main(int argc, char **argv) { ALLEGRO_DISPLAY *display; ALLEGRO_TIMER *timer; ALLEGRO_CONFIG *config; char const *value; char str[256]; (void)argc; (void)argv; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_init_primitives_addon(); al_install_keyboard(); al_install_mouse(); al_init_image_addon(); al_init_font_addon(); init_platform_specific(); /* Read supersampling info from ex_draw.ini. */ ex.samples = 0; config = al_load_config_file("ex_draw.ini"); if (!config) config = al_create_config(); value = al_get_config_value(config, "settings", "samples"); if (value) ex.samples = strtol(value, NULL, 0); sprintf(str, "%d", ex.samples); al_set_config_value(config, "settings", "samples", str); al_save_config_file("ex_draw.ini", config); al_destroy_config(config); if (ex.samples) { al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE); al_set_new_display_option(ALLEGRO_SAMPLES, ex.samples, ALLEGRO_SUGGEST); } display = al_create_display(640, 640); if (!display) { abort_example("Unable to create display.\n"); } init(); timer = al_create_timer(1.0 / ex.FPS); ex.queue = al_create_event_queue(); al_register_event_source(ex.queue, al_get_keyboard_event_source()); al_register_event_source(ex.queue, al_get_mouse_event_source()); al_register_event_source(ex.queue, al_get_display_event_source(display)); al_register_event_source(ex.queue, al_get_timer_event_source(timer)); al_start_timer(timer); run(); al_destroy_event_queue(ex.queue); return 0; }
int main(void) { ALLEGRO_DISPLAY *display; ALLEGRO_FONT *font; ALLEGRO_CONFIG *config; ALLEGRO_EVENT_QUEUE *queue; bool write = false; bool flip = false; bool quit; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_init_font_addon(); al_init_image_addon(); al_install_keyboard(); al_install_mouse(); /* Read parameters from ex_vsync.ini. */ config = al_load_config_file("ex_vsync.ini"); if (!config) { config = al_create_config(); write = true; } /* 0 -> Driver chooses. * 1 -> Force vsync on. * 2 -> Force vsync off. */ vsync = option(config, "vsync", 0); fullscreen = option(config, "fullscreen", 0); frequency = option(config, "frequency", 0); /* Write the file back (so a template is generated on first run). */ if (write) { al_save_config_file("ex_vsync.ini", config); } al_destroy_config(config); /* Vsync 1 means force on, 2 means forced off. */ if (vsync) al_set_new_display_option(ALLEGRO_VSYNC, vsync, ALLEGRO_SUGGEST); /* Force fullscreen mode. */ if (fullscreen) { al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); /* Set a monitor frequency. */ if (frequency) al_set_new_display_refresh_rate(frequency); } display = al_create_display(640, 480); if (!display) { abort_example("Error creating display.\n"); } font = al_load_font("data/a4_font.tga", 0, 0); if (!font) { abort_example("Failed to load a4_font.tga\n"); } queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_mouse_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); quit = display_warning(queue, font); al_flush_event_queue(queue); while (!quit) { ALLEGRO_EVENT event; /* With vsync, this will appear as a 50% gray screen (maybe * flickering a bit depending on monitor frequency). * Without vsync, there will be black/white shearing all over. */ if (flip) al_clear_to_color(al_map_rgb_f(1, 1, 1)); else al_clear_to_color(al_map_rgb_f(0, 0, 0)); al_flip_display(); flip = !flip; while (al_get_next_event(queue, &event)) { switch (event.type) { case ALLEGRO_EVENT_DISPLAY_CLOSE: quit = true; case ALLEGRO_EVENT_KEY_DOWN: if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) quit = true; } } /* Let's not go overboard and limit flipping at 1000 Hz. Without * this my system locks up and requires a hard reboot :P */ al_rest(0.001); } al_destroy_font(font); al_destroy_event_queue(queue); return 0; }