int main(int argc, char **argv) { init_glew(); GLFWwindow *window = initialize_window(g_windowWidth, g_windowHeight, g_gameTitle); bool running = true; /* Loop until the user closes the window */ while (running) { /* Render here */ setColor(0.5f, 0.69f, 1.0f, 1.0f); /*Swap front and back buffers */ glfwSwapBuffers(window); /*poll for and process events*/ glfwPollEvents(); running = toggleExit(window, running); window = toggleFullScreenWindow(window, GLFW_KEY_F11); } glfwTerminate(); return EXIT_SUCCESS; }
ui_element_instance_ptr UIElement::instantiate(HWND p_parent,ui_element_config::ptr cfg,ui_element_instance_callback_ptr p_callback) { set_configuration(cfg); m_callback = p_callback; initialize_window(p_parent); return this; }
void UI::load_window(const std::string &file_name) { std::shared_ptr<Window> window{new Window{}}; initialize_window(window); serialization::XMLSerializer serializer{file_name}; creation::WindowLoader loader{serializer, m_renderer, window.get(), m_factory}; loader.load(); m_windows.push_back(window); }
void initialize_application() { gtk_init(0, NULL); initialize_window(); initialize_horizontal_box(); initialize_grid(); initialize_vertical_box(); initialize_button_newgame(); initialize_score_label(); initialize_next_piece(); new_game(); }
int main(int argc, char *argv[]) { if (SDL_Init(SDL_INIT_VIDEO) != 0) return 1; // Initialize the window. struct Window window; if (initialize_window(&window) != 0) return 2; set_window_title(&window, "Stars and Moons"); set_window_dimensions(&window, 50, 50, WINDOW_DEFAULT_WIDTH, WINDOW_DEFAULT_HEIGHT, WINDOW_DEFAULT_ASPECT_RATIO); struct GraphicResources graphic_resources; // Provide room for five images. if (initialize_graphic_resources(&graphic_resources, 5) != 0) return 3; load_all_images(5, &graphic_resources); // Initialize game data. struct GameState game_state; if (initialize_game_state(&game_state, BOARD_ROWS, BOARD_COLS) != 0) return 4; set_game_player(&game_state, STAR); set_all_game_matrix_values(&game_state, GAME_STATE_SENTINEL); draw_window(&window, &game_state, &graphic_resources); SDL_Event event; int run_game = 1; while (run_game == 1) { process_window_events(&window, &game_state, &graphic_resources); if (game_state.run_game == 0) run_game = 0; } SDL_Quit(); destroy_game_state(&game_state); destroy_graphic_resources(&graphic_resources); destroy_window(&window); return 0; }
int Application::start_application( Application* app, int width, int height, float fps, const char* title, bool show_window) { LoopData ldata; app->show_window = show_window; assert( app ); // only create an app the first time this function is called if ( SDL_WasInit( 0 ) ) return -2; // init SDL if (show_window) { if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) == -1 ) { std::cout << "Error initializing SDL: " << SDL_GetError() << std::endl; return -1; } } else { if ( SDL_Init( SDL_INIT_TIMER ) == -1 ) { std::cout << "Error initializing SDL: " << SDL_GetError() << std::endl; return -1; } } if (show_window) { if ( !initialize_window( width, height, title ) ) goto FAIL; } // initialize the application if ( !app->initialize() ) goto FAIL; // run main loop app->running = true; ldata.app = app; ldata.fps = fps; ldata.running = &app->running; run_main_loop( loop_update_func, &ldata, fps ); // clean up and exit app->destroy(); std::cout << "Exiting Normally" << std::endl; return 0; FAIL: std::cerr << "Failed to start applcation, aborting.\n"; return -1; }
int main (int argc, char *argv[]) { /*FIXME Clean this main */ GtkWidget *window, *entry, *grid, *frame, *combo1, *combo2, *combo3; gtk_init(&argc, &argv); /* Creates main window */ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); initialize_window(window); /* Creates a grid */ grid = gtk_grid_new (); gtk_container_add(GTK_CONTAINER(window), grid); /* Creates a text entry and attaches to grid */ entry = new_entry_with_buffer(NULL, 0); GtkEntryBuffer *buffer = gtk_entry_get_buffer((GtkEntry *)entry); gtk_grid_attach(GTK_GRID(grid), entry, 0, 0, 3, 1); /*FIXME Regulate paramaters via xml */ /* Creates favorite bands' combo and attaches to grid */ combo1 = new_combo_box_with_text("Velvet Underground", "Joy Division", "My Bloody Valentine"); g_signal_connect( G_OBJECT(combo1), "changed", G_CALLBACK( cb_changed ), GTK_ENTRY_BUFFER(buffer)); frame = gtk_frame_new("Favorite Bands"); gtk_container_add(GTK_CONTAINER(frame), combo1); gtk_grid_attach(GTK_GRID(grid), frame, 0, 1, 1, 1); /* Creates favorite foods' combo and attaches to grid */ combo2 = new_combo_box_with_text("Mexican", "Japanese", "Italian"); g_signal_connect( G_OBJECT(combo2), "changed", G_CALLBACK( cb_changed ), GTK_ENTRY_BUFFER(buffer)); frame = gtk_frame_new("Favorite Foods"); gtk_container_add(GTK_CONTAINER(frame), combo2); gtk_grid_attach(GTK_GRID(grid), frame, 1, 1, 1, 1); /* Creates favorite movies' combo and attaches to grid */ combo3 = new_combo_box_with_text("Dekalog", "Acossado", "Magnolia"); g_signal_connect( G_OBJECT(combo3), "changed", G_CALLBACK( cb_changed ), GTK_ENTRY_BUFFER(buffer)); frame = gtk_frame_new("Favorite Movies"); gtk_container_add(GTK_CONTAINER(frame), combo3); gtk_grid_attach(GTK_GRID(grid), frame, 2, 1, 1, 1); /* Shows all widgets recursively */ gtk_widget_show_all(window); gtk_main(); return 0; }
SubtitleRenderer:: SubtitleRenderer(int layer, const std::string& font_path, float font_size, float margin_left, float margin_bottom, bool centered, unsigned int white_level, unsigned int box_opacity) : prepared_(), dispman_element_(), dispman_display_(), screen_width_(), screen_height_(), display_(), context_(), surface_(), vg_font_(), vg_font_border_(), vg_font_italic_(), vg_font_italic_border_(), ft_library_(), ft_face_(), ft_stroker_(), line_height_(), box_offset_(), box_h_padding_(), margin_left_(margin_left), margin_bottom_(margin_bottom), centered_(centered), white_level_(white_level), box_opacity_(box_opacity) { try { initialize_window(layer); initialize_egl(); initialize_fonts(font_path, font_size); } catch (...) { destroy(); throw; } }
int main (int argc, char *argv[]){ Gui *gui = (Gui *)malloc(sizeof(Gui));; gui->space = cpSpaceNew(); gui->current_body = NULL; cpSpaceSetGravity(gui->space, cpv(0, GRAVITY)); cpEnableSegmentToSegmentCollisions(); gtk_init(&argc, &argv); initialize_window(gui); initialize_client(gui); pthread_t t1; int iret1 = pthread_create(&t1, NULL, client_recv1, gui); gtk_main(); cpSpaceFree(gui->space); free(gui); return 0; }
int main(int argc, char *argv[]) { if (SDL_Init(SDL_INIT_VIDEO) != 0) return 1; // Initialize the window. struct Window window; if (initialize_window(&window) != 0) return 2; set_window_title(&window, "Stars and Moons"); set_window_dimensions(&window, 50, 50, WINDOW_DEFAULT_WIDTH, WINDOW_DEFAULT_HEIGHT, WINDOW_DEFAULT_ASPECT_RATIO); // Initializes with room for five images. // TODO: Remove the hardcoded number. struct GraphicResources graphic_resources; if (initialize_graphic_resources(&graphic_resources, 5) != 0) return 3; int image_errors = 0; if ((image_errors = load_all_images(5, &graphic_resources, window.renderer)) != 0) { printf("Error loading %d image(s).\n", image_errors); return 4; } // Initialize game data. struct GameState game_state; if (initialize_game_state(&game_state, BOARD_ROWS, BOARD_COLS) != 0) return 5; set_game_player(&game_state, STAR); set_all_game_matrix_values(&game_state, GAME_STATE_SENTINEL); draw_window(&window, &game_state, &graphic_resources); int frames_counted = 0; int run_game = 1; while (run_game == 1) { ++frames_counted; run_game = process_window_events(&window, &game_state, &graphic_resources); draw_window(&window, &game_state, &graphic_resources); if (run_game == 2) { set_all_game_matrix_values(&game_state, GAME_STATE_SENTINEL); run_game = 1; } } // Calculate an estimate of the game's FPS. Uint32 time_since_start = SDL_GetTicks(); int seconds = time_since_start / 1000; int fps = frames_counted / seconds; printf("Rendered %d frames in %lu seconds\n", frames_counted, time_since_start / 1000); printf("FPS = %d\n", fps); // Free all the memories. destroy_game_state(&game_state); destroy_graphic_resources(&graphic_resources); destroy_window(&window); SDL_Quit(); return 0; }
SubtitleRenderer:: SubtitleRenderer(int display, int layer, const std::string& font_path, const std::string& italic_font_path, float font_size, float margin_left, float margin_bottom, bool centered, unsigned int white_level, unsigned int box_opacity, unsigned int lines) : prepared_(), dispman_element_(), dispman_display_(), display_(), context_(), surface_(), vg_font_(), vg_font_border_(), ft_library_(), ft_face_(), ft_face_italic_(), ft_stroker_(), line_height_(), box_offset_(), box_h_padding_(), margin_left_(), margin_bottom_(), buffer_width_(), buffer_height_(), centered_(centered), white_level_(white_level), box_opacity_(box_opacity) { try { uint32_t screen_width, screen_height; ENFORCE(graphics_get_display_size(display, &screen_width, &screen_height) >= 0); initialize_fonts(font_path, italic_font_path, font_size*screen_height); int abs_margin_bottom = static_cast<int>(margin_bottom * screen_height + 0.5f) - box_offset_; int buffer_padding = (line_height_+2)/4; int buffer_bottom = clamp(abs_margin_bottom + box_offset_ - buffer_padding, 0, (int) screen_height-1); int buffer_top = clamp(buffer_bottom + line_height_ * (int) lines + buffer_padding*2, 0, (int) screen_height-1); buffer_width_ = screen_width; buffer_height_ = buffer_top - buffer_bottom + 1; margin_left_ = (screen_width - screen_height) / 2 + static_cast<int>(margin_left * screen_height + 0.5f); margin_bottom_ = abs_margin_bottom - buffer_bottom; initialize_window(display, layer, 0, screen_height - buffer_top - 1, screen_width, buffer_height_); initialize_vg(); } catch (...) { destroy(); throw; } }
int main (int argc, char *argv[]) { /* Vars */ GtkWidget *vbox; GtkWidget *window; GtkWidget *table; GtkWidget *label; GtkWidget *entry; GtkWidget *button; GtkWidget* scrolled; GtkWidget *menubar; GtkWidget *filemenu; GtkWidget *file; GtkWidget *quit; GtkWidget *reindexer; /* Set default directory to index */ indexdir = "."; /* Run the indexer */ reindex(NULL, NULL); /* Create the search objects */ createSearch(); /* Make the GUI */ gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); initialize_window(window); /* Create a 10x5 table */ table = gtk_table_new (10, 5, FALSE); gtk_container_add (GTK_CONTAINER (window), table); /* create a new label. */ label = gtk_label_new ("Search Terms:" ); gtk_table_set_homogeneous(GTK_TABLE (table), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2); entry = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (entry),1000); gtk_table_attach_defaults (GTK_TABLE (table), entry, 1, 3, 1, 2); button = gtk_button_new_with_label ("OR Search"); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (orsearch), (gpointer) entry); gtk_table_attach_defaults (GTK_TABLE (table), button, 3, 4, 1, 2); button = gtk_button_new_with_label ("AND Search"); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (andsearch), (gpointer) entry); gtk_table_attach_defaults (GTK_TABLE (table), button, 4, 5, 1, 2); textview = gtk_text_view_new(); gtk_text_view_set_editable( GTK_TEXT_VIEW (textview), 0); gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview), 0); scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_container_add (GTK_CONTAINER (scrolled), textview); gtk_table_attach_defaults (GTK_TABLE (table), scrolled, 0, 5, 2, 10); vbox = gtk_vbox_new(FALSE, 0); gtk_table_attach_defaults (GTK_TABLE (table), vbox, 0, 5, 0, 1); menubar = gtk_menu_bar_new(); filemenu = gtk_menu_new(); file = gtk_menu_item_new_with_label("File"); reindexer = gtk_menu_item_new_with_label("Reindex"); gtk_signal_connect (GTK_OBJECT (reindexer), "activate", G_CALLBACK(reindex), NULL); quit = gtk_menu_item_new_with_label("Quit"); gtk_signal_connect (GTK_OBJECT (quit), "activate", G_CALLBACK(destroy), NULL); gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu); gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), reindexer); gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit); gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file); gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 3); gtk_widget_show_all(window); gtk_main (); return 0; }
void UI::add_window(std::shared_ptr<Window> window) { initialize_window(window); m_windows.push_back(window); }
int start_simulation(void) { cl_device_id *dev; cl_uint devc; cl_context context; cl_command_queue *cmd_queue; cl_mem src, dst, wdth, hght, *offy; cl_int err; cl_kernel kern; cl_program prog; cl_platform_id pform; size_t rows, columns, runs, print_each = 0, offsetx, offsety, *y, swapoffy; int gui_enabled, platform, device; unsigned int *buff0; unsigned int i; struct dispatcher_context *c; int random; char fname[1024]; cl_uint cqc; #if 1 do { printf("Width: "); scanf(SZTF, &columns); if (columns % 32) { printf("Width must be a multiple of 32\n"); continue; } if (columns == 0) { printf("Width must be > 0\n"); continue; } break; } while (true); do { printf("Height: "); scanf(SZTF, &rows); if (rows == 0) { printf("Width must be > 0\n"); continue; } break; } while (true); printf("Runs: "); scanf(SZTF, &runs); printf("Random? "); scanf("%d", &random); if (!random) { printf("File name: "); scanf("%s", fname); printf("Offset X: "); scanf(SZTF, &offsetx); printf("Offset Y: "); scanf(SZTF, &offsety); } printf("GUI? "); scanf("%d", &gui_enabled); if (!gui_enabled) { printf("Print after run: "); scanf(SZTF, &print_each); } printf("Platform index: "); scanf("%d", &platform); printf("Device index (-1 for all): "); scanf("%d", &device); do { printf("Swap offset: "); scanf(SZTF, &swapoffy); if (swapoffy == 0) swapoffy = rows; if (rows % swapoffy != 0) { printf("Swap offset must be a factor of the row count\n"); continue; } break; } while (true); #else columns = 512; rows = 512; runs = 1000; gui_enabled = 1; print_each = 0; random = 1; offsetx = 0; offsety = 0; platform = 0; device = 0; swapoffy = rows; #endif err = get_devices(&dev, &devc, &pform, platform, device); if (err) return err; err = initialize_context_cmd_queue(dev, devc, pform, &context, &cmd_queue, &cqc); if (err) return err; err = load_kernel(context, dev, devc, &prog, &kern); if (err) return err; buff0 = (unsigned int*)malloc(rows * (columns / 8)); if (!buff0) return -1; if (random) { srand((unsigned int)time(NULL)); for (i = 0; i < (rows * (columns / 8)) / 4; i++) { buff0[i] = rand() | (rand() << 16); } } else { memset(buff0, 0, rows * (columns / 8)); if (!load_file_to_buffer(buff0, fname, offsetx, offsety, columns, rows)) return -1; } err = compute_buffer_sizes(context, cmd_queue, cqc, kern, columns, rows, swapoffy, &y); if (err) return err; err = create_buffers(context, swapoffy * (columns / 8), columns, swapoffy, &src, &dst, &wdth, &hght, &offy, y, buff0, devc); if (err) return err; if (gui_enabled) { if (!initialize_window()) return -1; } c = (struct dispatcher_context *)malloc(sizeof(*c)); if (!c) return -1; c->cmd_queue = cmd_queue; c->cqc = cqc; c->kern = kern; c->columns = columns; c->rows = rows; c->print_each = print_each; c->runs = runs; c->gui_enabled = gui_enabled; c->buff0 = buff0; c->src = src; c->dst = dst; c->wdth = wdth; c->hght = hght; c->offy = offy; c->y = y; c->swapoffy = swapoffy; c->context = context; c->win_height = rows; return start_dispatcher(c); }