/* dealloc */ void handle_deinit( void ) { // Unsubscribe from services tick_timer_service_unsubscribe(); battery_state_service_unsubscribe(); bluetooth_connection_service_unsubscribe(); // Destroy image objects destroy_graphics( background_image, background_layer ); destroy_graphics( battery_image, battery_layer ); destroy_graphics( bluetooth_image, bluetooth_layer ); destroy_graphics( icon_bitmap, icon_layer ); // Destroy text objects text_layer_destroy( text_time_layer ); text_layer_destroy( text_ampm_layer ); text_layer_destroy( text_secs_layer ); text_layer_destroy( text_days_layer ); text_layer_destroy( text_date_layer ); text_layer_destroy( text_week_layer ); text_layer_destroy( temp_layer ); // Destroy inverter layer inverter_layer_destroy( currentDayLayer ); // Destroy font objects fonts_unload_custom_font( font_time ); fonts_unload_custom_font( font_days ); fonts_unload_custom_font( font_date ); // Clean up AppSync system app_sync_deinit( &app ); // Destroy window window_destroy( window ); }
int main(int argc, char *argv[]) { int width=0; int height=0; pixel_format pf=PF_ERROR; char *filename=NULL; u8 *image_data=NULL; FILE *image_file=NULL; int i=0, c=0, image_bytes=0; SDL_Event e; int quit=0; if(parse_args(argc, argv, &width, &height, &pf, &filename)) { display_help(); goto end; } image_bytes=width*height*get_pixel_format_bits(pf)/8; image_data=(u8 *)malloc(image_bytes); image_file=fopen(filename, "rb"); if(!image_file) { printf("File %s does not exist\n", filename); goto end; } for(i=0;(c=fgetc(image_file))!=EOF&&i<image_bytes;i++) image_data[i]=(u8)c; fclose(image_file); init_graphics(width, height); blit_image(width, height, pf, image_data); while(!quit) { SDL_Delay(1.0/15.0f); while(SDL_PollEvent(&e)) { if(e.type==SDL_QUIT) quit=1; } } destroy_graphics(width, height); end: if(image_data) free(image_data); if(filename) free(filename); return 0; }
int main(int argc, char** argv) { if(!glfwInit()) { error("Failed to intialize GLFW."); return 1; } GLFWwindow* win; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); win = glfwCreateWindow(800, 600, "Halberd", NULL, NULL); if(!win) { error("Unable to create window."); return 1; } glfwSetFramebufferSizeCallback(win, sizeCallback); glfwMakeContextCurrent(win); glewExperimental = 1; if(glewInit() != GLEW_OK) { error("glewInit() failed."); glfwDestroyWindow(win); return 1; } glGetError(); // Because GLEW is silly. <http://stackoverflow.com/questions/20034615/why-does-glewinit-result-in-gl-invalid-enum-after-making-some-calls-to-glfwwin> GLuint VAO; // FIXME: Stupid Hack. <http://stackoverflow.com/questions/13403807/glvertexattribpointer-raising-gl-invalid-operation> glGenVertexArrays(1, &VAO); glBindVertexArray(VAO); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); init_graphics(); update_camera(800, 600); init_input(win); init_player(0, 0); init_ui(); init_settings(); /*init_maps();*/ // TODO: Figure out the correct way to start up /*get_tileset_id("Plains.png");*/ /*load_maps("test");*/ float delta = 0; glfwSetTime(0); do { delta = glfwGetTime(); glfwSetTime(0); glfwPollEvents(); if(!ui_present()) update_player(delta); update_actors(delta); update_ui(delta); update_input_states(delta); render_game(); glfwSwapBuffers(win); } while(!glfwWindowShouldClose(win) && get_input_state(4) != 2); destroy_player_actor(); destroy_actors(); /*destroy_maps();*/ destroy_ui(); destroy_graphics(); cleanup_settings(); glfwDestroyWindow(win); glfwTerminate(); return 0; }
void destroy_game(Game* G) { destroy_timer(G->timer); destroy_graphics(G->graphics); free(G); }