int main (int argc, char *argv[]) { bcm_host_init(); // Clear application state memset( state, 0, sizeof( *state ) ); setup_user_options(argc, argv); // Start OGLES init_egl(); init_textures(); build_gears(); // setup the scene based on rendering mode if (state->useGLES2) { init_scene_GLES2(); // Setup the model projection/world init_model_projGLES2(); } else { // using gles1 init_scene_GLES1(); // Setup the model projection/world init_model_projGLES1(); } // animate the gears run_gears(); exit_func(); return 0; }
static void update_image (APP_STATE_T * state, GstBuffer * buffer) { GstVideoGLTextureUploadMeta *meta = NULL; if (state->current_buffer) { gst_buffer_unref (state->current_buffer); } else { /* Setup the model world */ init_model_proj (state); TRACE_VC_MEMORY ("after init_model_proj"); /* initialize the OGLES texture(s) */ init_textures (state, buffer); TRACE_VC_MEMORY ("after init_textures"); } state->current_buffer = gst_buffer_ref (buffer); TRACE_VC_MEMORY_ONCE_FOR_ID ("before GstVideoGLTextureUploadMeta", gid0); if (state->can_avoid_upload) { GstMemory *mem = gst_buffer_peek_memory (state->current_buffer, 0); g_assert (gst_is_gl_memory (mem)); state->tex = ((GstGLMemory *) mem)->tex_id; } else if ((meta = gst_buffer_get_video_gl_texture_upload_meta (buffer))) { if (meta->n_textures == 1) { guint ids[4] = { state->tex, 0, 0, 0 }; if (!gst_video_gl_texture_upload_meta_upload (meta, ids)) { GST_WARNING ("failed to upload to texture"); } } } TRACE_VC_MEMORY_ONCE_FOR_ID ("after GstVideoGLTextureUploadMeta", gid1); }
int main(int argc, char** argv) { init_ogl(p_state); create_perspective_matrix(&p_state->p_matrix, 45, 1.0, 0.1, 100); identity(&p_state->mv_matrix); identity(&p_state->send_mv_matrix); rotate_matrix(&p_state->send_mv_matrix, 180, 1.0, 0, 0); translate_matrix(&p_state->send_mv_matrix, 0, 0, -5); //rotate_matrix(&p_state->mv_matrix, 45, 1.0, 0, 0); translate_matrix(&p_state->mv_matrix, 0, 0, -5); init_shaders(p_state); init_framebuffer(p_state); init_textures(p_state); encode_loop(p_state); while(1) { } // return NULL; }
static void open_ogl (void) { TRACE_VC_MEMORY ("state 0"); #if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_EGL) bcm_host_init (); TRACE_VC_MEMORY ("after bcm_host_init"); #endif /* Start OpenGLES */ init_ogl (state); TRACE_VC_MEMORY ("after init_ogl"); /* Wrap the EGL display */ state->gst_display = gst_egl_display_new (state->display, NULL); /* Setup the model world */ init_model_proj (state); TRACE_VC_MEMORY ("after init_model_proj"); /* initialize the OGLES texture(s) */ init_textures (state); TRACE_VC_MEMORY ("after init_textures"); }
int main () { bcm_host_init(); printf("Note: ensure you have sufficient gpu_mem configured\n"); // Clear application state memset( state, 0, sizeof( *state ) ); // Start OGLES init_ogl(state); // Setup the model world init_model_proj(state); // initialise the OGLES texture(s) init_textures(state); while (!terminate) { update_model(state); redraw_scene(state); } exit_func(); return 0; }
void myinit() { // initialization glClearColor(0,0,0,0); // clear to black color glShadeModel(GL_SMOOTH); // shading is smooth glEnable(GL_TEXTURE_2D); init_textures(); // call the init_textures function glEnable(GL_DEPTH_TEST); glEnable(GL_AUTO_NORMAL); GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0}; // diffuse lighting effect glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); glEnable(GL_LIGHTING); // enable the lighting glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glViewport(0,0,640,480); // set up viewport to 640x480 glMatrixMode(GL_PROJECTION); // projection mode glLoadIdentity(); gluPerspective(45,1.333,0.1,1000); // viewing angle of 45 degrees, 1.333 comes from 640/480 glMatrixMode(GL_MODELVIEW); // modelview mode glLoadIdentity(); glEnable(GL_POLYGON_SMOOTH); // smooth polygons and lines glEnable(GL_LINE_SMOOTH); }
/* Initialize the rendering objects and context properties */ void init_gl(int argc, char* argv[]) { /* Initialize the main window */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutInitWindowSize(233, 90); glutCreateWindow("Texture Filter"); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); /* Launch GLEW processing */ GLenum err = glewInit(); if (err != GLEW_OK) { perror("Couldn't initialize GLEW"); exit(1); } /* Create VBOs */ init_buffers(); /* Create texture */ init_textures(); /* Create and compile shaders */ init_shaders(); }
void onInit() { sys::info << "app::COGLDev06NormalMapApp::onInit()" << sys::endl; pCamera = new app::CCamera(60.0f, mConfig.mRatio, 0.1f, 100.0f); pCamera->translateLocal(math::vec3(0.0f, -2.0f, -5.0f)); pShadowFBO = new ogl::CShadowFramebuffer(mConfig.mWidth, mConfig.mHeight); init_programs(); init_lights(); init_textures(); init_objects(); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepthf(1.0f); glEnable(GL_CULL_FACE); glFrontFace(GL_CW); glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); }
int main(int argc, char** argv) { SDL_Event event; int keypress = 0; // Init random number generator srand(clock()); // Init everything sdl_init("OpenGL example"); opengl_init(); audioplayer_init(); // Init internal data init_sin_table(); init_textures(); // Load audioplayer tune audioplayer_loadtune(&simpletune); audioplayer_play(); // Loop until the end while(!keypress && audioplayer_isplaying()) { // Lock SDL surface if needed if(SDL_MUSTLOCK(screen)) if(SDL_LockSurface(screen) < 0) exit(EXIT_FAILURE); // Draw the plasma draw_cube(screen, audioplayer_getpos()); // Unlock the SDL surface if needed if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); // Update screen SDL_GL_SwapBuffers(); // Handle SDL events while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: case SDL_KEYDOWN: keypress = 1; break; } } } // Exit gracefully SDL_Quit(); return EXIT_SUCCESS; }
void init() { stack_position = StackPosition::CENTERED; init_random(); input.init(); init_modes(); init_textures(); menu.init(); menu.init_graphics(); }
void init_struct(t_mega *all) { all->e.refresh = 1; init_hook(&all->hook); init_cam(&all->cam, (int)START_X, (int)START_Y); init_player(&all->player); init_textures(all); all->sprites = init_sprites(all); init_minimap(&all->e, &all->hook.minimap); stock_minimap(all); all->door.x = 0; }
int main(int argc, char *argv[]) { #ifdef DEBUG gtk_init(&argc, &argv); gtk_gl_init(&argc, &argv); #else gtk_init(NULL, NULL); gtk_gl_init(NULL, NULL); #endif setup_splash(); splash("Starting up..."); // Init logfile FILE* f = fopen("slade.log", "wt"); fclose(f); load_main_config(); init_console(); setup_icons(); log_message("Init textures...\n"); init_textures(); log_message("Loading colour configurations...\n"); load_colour_configs(); string ccfg = col_config; set_colour_config(ccfg); log_message("Setup editor window...\n"); setup_editor_window(); log_message("Setup wad manager window...\n"); splash_hide(); setup_main_window(); log_message("Init OK.\n"); open_main_window(); // Setup gl font //font_list = glGenLists(256); //PangoFontDescription *font_desc = pango_font_description_from_string("Monospace 10"); //gdk_gl_font_use_pango_font(font_desc, 0, 255, font_list); gtk_main(); save_main_config(); return 0; }
void init(){ glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); // habilitando as texturas init_textures(); compoe_sala(); }
Map::Map(const std::string map_src): event_step_on(glm::ivec2(0, 0)), event_step_off(glm::ivec2(0, 0)) { //Load the map MapLoader map_loader; bool result = map_loader.load_map(map_src); if(!result) { LOG(ERROR) << "Couldn't load map"; return; } locations = map_loader.get_object_mapping(); //returns a vector of MapObjectProperties (see map_loader.hpp for structure) //Get the loaded map data map_width = map_loader.get_map_width(); map_height = map_loader.get_map_height(); // hack to construct postion dispatcher as we need map diametions event_step_on = PositionDispatcher<int>(glm::ivec2(map_width, map_height)); event_step_off = PositionDispatcher<int>(glm::ivec2(map_width, map_height)); LOG(INFO) << "Map width: " << map_width << " Map height: " << map_height; std::vector<std::shared_ptr<Layer>> layers = map_loader.get_layers(); for(auto layer : layers) { layer_ids.push_back(layer->get_id()); ObjectManager::get_instance().add_object(layer); if (layer->get_name() == Config::get_instance()["layers"]["special_layer_name"]) { special_layer_id = layer->get_id(); } } tilesets = map_loader.get_tilesets(); //Get the tilesets //TODO: We'll only support one tileset at the moment //Get an object list blocker = std::vector<std::vector<int>>(map_width, std::vector<int>(map_height, 0)); //Generate the geometry needed for this map init_shaders(); init_textures(); // generate_tileset_coords(texture_atlases[0]); generate_data(); }
int main(int argc, char *argv[]) { printf("mpflow - Copyright (C) 2009 Walter de Jong <*****@*****.**>\n"); get_options(argc, argv); if (lock_program() == -1) { printf("another instance of mpflow is already running\n"); return 1; } init_mpd(); /* init app */ SDK_init(); create_window(); set_app_icon(); init_gl(); draw_startup(); /* only a border */ /* note that the order of init_() functions here is important (!) */ init_textures(); init_text(); init_covers(); init_events(); init_widget_covers(); init_widget_about(); init_widget_aboutbutton(); init_widget_titlebar(); main_widget = &w_titlebar; prepare_widgets(); draw(); for(;;) { SDK_handle_events(); move_covers(); if (!moving) SDL_WaitEvent(NULL); else SDK_sleep(FRAME_DELAY); } exit_program(0); return 0; }
void scene_init(void) { // galaxies_init(); // glClearDepth(0.0f); // glDepthFunc(GL_LEQUAL); // glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); init_textures(); glShadeModel(GL_SMOOTH); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); }
void dc_capture_init(struct dc_capture *capture, int x, int y, uint32_t width, uint32_t height, bool cursor, bool compatibility) { memset(capture, 0, sizeof(struct dc_capture)); capture->x = x; capture->y = y; capture->width = width; capture->height = height; capture->capture_cursor = cursor; obs_enter_graphics(); if (!gs_gdi_texture_available()) compatibility = true; capture->compatibility = compatibility; init_textures(capture); obs_leave_graphics(); if (!capture->valid) return; if (compatibility) { BITMAPINFO bi = {0}; BITMAPINFOHEADER *bih = &bi.bmiHeader; bih->biSize = sizeof(BITMAPINFOHEADER); bih->biBitCount = 32; bih->biWidth = width; bih->biHeight = height; bih->biPlanes = 1; capture->hdc = CreateCompatibleDC(NULL); capture->bmp = CreateDIBSection(capture->hdc, &bi, DIB_RGB_COLORS, (void**)&capture->bits, NULL, 0); capture->old_bmp = SelectObject(capture->hdc, capture->bmp); } }
int init_env(t_env *e) { if (!(e->mlx = mlx_init())) return (0); e->win = mlx_new_window(e->mlx, WIN_X, WIN_Y, "Wolf3D"); e->img_ptr = NULL; e->pos_cam.x = e->map_x / 2.0; e->pos_cam.y = e->map_y - 3; check_start_pos(e); e->fov = 6000.0; e->a_cam = 9000; e->gif = 0; e->fps = 0; e->frame = 0; e->old_clock = clock(); e->speed = 0.30; e->a_speed = 600; if (!init_trigo(e) || !init_textures(e)) return (0); return (1); }
int main(int argc, char* argv[]) { //glut initialization glutInit(&argc, argv); glutInitWindowSize(init_win_width, init_win_height); win_id = glutCreateWindow(win_title); if(win_id <= 0) { fprintf(stderr, "Error: glutCreateWindow() returned %d\n", win_id); exit(1); } //scene initialization init(); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutIdleFunc(idle); glutMouseFunc(mouse); glutMotionFunc(motion); set_projection(); set_lighting(); init_textures(); glEnable(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); numOfVerts = NULL; glBindTexture(GL_TEXTURE_2D, 0); glutMainLoop(); return 0; }
int main(int argc, char *argv[]) { gtk_init(&argc, &argv); setup_splash(); splash("Starting up..."); //gtk_gl_init(&argc, &argv); // Init logfile FILE* f = fopen("slade.log", "wt"); fclose(f); load_main_config(); init_console(); setup_icons(); init_textures(); load_colour_configs(); string ccfg = col_config; set_colour_config(ccfg); setup_editor_window(); setup_main_window(); open_main_window(); // Setup gl font //font_list = glGenLists(256); //PangoFontDescription *font_desc = pango_font_description_from_string("Monospace 10"); //gdk_gl_font_use_pango_font(font_desc, 0, 255, font_list); splash_hide(); gtk_main(); save_main_config(); return 0; }
int main(void) { initXWindows(); srand(time(NULL)); clock_gettime(CLOCK_REALTIME, &timePause); clock_gettime(CLOCK_REALTIME, &timeStart); init_opengl(); init_ship(); //Do this to allow fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); init_textures(); while(!done) { while(XPending(dpy)) { XEvent e; XNextEvent(dpy, &e); check_resize(&e); check_mouse(&e); check_keys(&e); } clock_gettime(CLOCK_REALTIME, &timeCurrent); timeSpan = timeDiff(&timeStart, &timeCurrent); timeCopy(&timeStart, &timeCurrent); physicsCountdown += timeSpan; while (physicsCountdown >= physicsRate) { physics(); physicsCountdown -= physicsRate; render(); } //physics(); //render(); glXSwapBuffers(dpy, win); } cleanupXWindows(); cleanup_fonts(); return 0; }
void *render_task(void *dummy) { init_ogl(p_state); create_perspective_matrix(&p_state->p_matrix, 45, 1.0, 0.1, 100); identity(&p_state->mv_matrix); identity(&p_state->send_mv_matrix); rotate_matrix(&p_state->send_mv_matrix, 180, 1.0, 0, 0); translate_matrix(&p_state->send_mv_matrix, 0, 0, -5); //rotate_matrix(&p_state->mv_matrix, 45, 1.0, 0, 0); translate_matrix(&p_state->mv_matrix, 0, -10, -15); init_shaders(p_state); init_framebuffer(p_state); init_textures(p_state); encode_loop(p_state, &robot); return NULL; }
int _main () { bcm_host_init(); // Clear application state memset( state, 0, sizeof( *state ) ); // Start OGLES init_ogl(state); // Setup the model world init_model_proj(state); // initialise the OGLES texture(s) init_textures(state); while (!terminate) { update_model(state); redraw_scene(state); } exit_func(); return 0; }
int main( int argc, char **argv ) { /* Print copyright notice */ fprintf( stderr, "Tux Rider World Challenge -- http://www.barlow-server.com\n" "a fork from:\n" "Tux Racer " VERSION " -- a Sunspire Studios Production " "(http://www.sunspirestudios.com)\n" "(c) 1999-2000 Jasmin F. Patry " "<*****@*****.**>\n" "\"Tux Racer\" is a trademark of Jasmin F. Patry\n" "Tux Rider World Challenge comes with ABSOLUTELY NO WARRANTY. " "This is free software,\nand you are welcome to redistribute " "it under certain conditions.\n" "See http://www.gnu.org/copyleft/gpl.html for details.\n\n" ); /* Init the game clock */ g_game.secs_since_start = 0; /* Seed the random number generator */ srand( time(NULL) ); /* * Set up the game configuration */ /* Don't support multiplayer, yet... */ g_game.num_players = 2; /* Create a Tcl interpreter */ g_game.tcl_interp = Tcl_CreateInterp(); if ( g_game.tcl_interp == NULL ) { handle_error( 1, "cannot create Tcl interpreter" ); } /* Setup the configuration variables and read the ~/.tuxracer/options file */ init_game_configuration(); read_config_file(); /* Set up the debugging modes */ init_debug(); /* Setup diagnostic log if requested */ if ( getparam_write_diagnostic_log() ) { setup_diagnostic_log(); } /* * Setup Tcl stdout and stderr channels to point to C stdout and stderr * streams */ setup_tcl_std_channels(); /* * Initialize rendering context, create window */ winsys_init( &argc, argv, WINDOW_TITLE, WINDOW_TITLE ); /* Ingore key-repeat messages */ winsys_enable_key_repeat(0); /* Set up a function to clean up when program exits */ winsys_atexit( cleanup ); /* * Initial OpenGL settings */ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); init_opengl_extensions(); /* Print OpenGL debugging information if requested */ if ( debug_mode_is_active( DEBUG_GL_INFO ) ) { print_debug( DEBUG_GL_INFO, "OpenGL information:" ); print_gl_info(); } /* * Load the game data and initialize game state */ register_game_config_callbacks( g_game.tcl_interp ); register_course_load_tcl_callbacks( g_game.tcl_interp ); register_key_frame_callbacks( g_game.tcl_interp ); register_fog_callbacks( g_game.tcl_interp ); register_course_light_callbacks( g_game.tcl_interp ); register_particle_callbacks( g_game.tcl_interp ); register_texture_callbacks( g_game.tcl_interp ); register_font_callbacks( g_game.tcl_interp ); register_sound_tcl_callbacks( g_game.tcl_interp ); register_sound_data_tcl_callbacks( g_game.tcl_interp ); register_course_manager_callbacks( g_game.tcl_interp ); init_saved_games(); load_tux(); init_textures(); init_fonts(); init_audio_data(); init_audio(); init_ui_manager(); init_course_manager(); init_joystick(); /* Read the tuxracer_init.tcl file */ read_game_init_script(); /* Need to set up an initial view position for select_course (quadtree simplification) */ //Player 0 = classic mode player ; Player 1 = Speed Only Mode Player g_game.player[0].view.pos = make_point( 0., 0., 0. ); g_game.player[1].view.pos = make_point( 0., 0., 0. ); /* Placeholder name until we give players way to enter name */ g_game.player[0].name = "noname"; g_game.player[1].name = "nonameSpeedOnly"; init_preview(); splash_screen_register(); intro_register(); racing_register(); game_over_register(); paused_register(); reset_register(); game_type_select_register(); racing_mode_select_register(); event_select_register(); race_select_register(); credits_register(); loading_register(); g_game.mode = NO_MODE; set_game_mode( SPLASH ); g_game.difficulty = DIFFICULTY_LEVEL_NORMAL; init_keyboard(); winsys_show_cursor( False ); /* We use this to "prime" the GLUT loop */ winsys_set_idle_func( main_loop ); /* * ...and off we go! */ winsys_process_events(); return 0; }
/* Initialise Video, PAD, DVD, Font */ void* Initialise (void) { VIDEO_Init (); PAD_Init (); DVD_Init(); *(volatile unsigned long*)0xcc00643c = 0x00000000; //allow 32mhz exi bus // Disable IPL modchips to allow access to IPL ROM fonts ipl_set_config(6); usleep(1000); //wait for modchip to disable (overkill) __SYS_ReadROM(IPLInfo,256,0); // Read IPL tag // Wii has no IPL tags for "PAL" so let libOGC figure out the video mode if(!is_gamecube()) { vmode = VIDEO_GetPreferredMode(NULL); //Last mode used } else { // Gamecube, determine based on IPL int retPAD = 0, retCnt = 10000; while(retPAD <= 0 && retCnt >= 0) { retPAD = PAD_ScanPads(); usleep(100); retCnt--; } // L Trigger held down ignores the fact that there's a component cable plugged in. if(VIDEO_HaveComponentCable() && !(PAD_ButtonsDown(0) & PAD_TRIGGER_L)) { if(strstr(IPLInfo,"MPAL")!=NULL) { swissSettings.sramVideo = 2; vmode = &TVMpal480Prog; //Progressive 480p } else if((strstr(IPLInfo,"PAL")!=NULL)) { swissSettings.sramVideo = 1; vmode = &TVPal576ProgScale; //Progressive 576p } else { swissSettings.sramVideo = 0; vmode = &TVNtsc480Prog; //Progressive 480p } } else { //try to use the IPL region if(strstr(IPLInfo,"MPAL")!=NULL) { swissSettings.sramVideo = 2; vmode = &TVMpal480IntDf; //PAL-M } else if(strstr(IPLInfo,"PAL")!=NULL) { swissSettings.sramVideo = 1; vmode = &TVPal576IntDfScale; //PAL } else { swissSettings.sramVideo = 0; vmode = &TVNtsc480IntDf; //NTSC } } } initialise_video(vmode); populateVideoStr(vmode); init_font(); init_textures(); whichfb = 0; drive_version(&driveVersion[0]); swissSettings.hasDVDDrive = *(u32*)&driveVersion[0] ? 1 : 0; if(!driveVersion[0]) { // Reset DVD if there was a modchip DrawFrameStart(); WriteFontStyled(640/2, 250, "Initialise DVD .. (HOLD B if NO DVD Drive)", 0.8f, true, defaultColor); DrawFrameFinish(); dvd_reset(); // low-level, basic dvd_read_id(); if(!(PAD_ButtonsHeld(0) & PAD_BUTTON_B)) { dvd_set_streaming(*(char*)0x80000008); } drive_version(&driveVersion[0]); swissSettings.hasDVDDrive = *(u32*)&driveVersion[0] ? 1 : 0; if(!swissSettings.hasDVDDrive) { DrawFrameStart(); DrawMessageBox(D_INFO, "No DVD Drive Detected !!"); DrawFrameFinish(); sleep(2); } } return xfb[0]; }
// uiloop void uiloop() { auto ok = glfwInit(); error_if_not(ok, "glfw init error"); // setting an error callback glfwSetErrorCallback([](int ecode, const char* msg){ return error(msg); }); // glfwWindowHint(GLFW_SAMPLES, scene->image_samples*scene->image_samples); auto window = glfwCreateWindow(scene->image_width, scene->image_height, "graphics14 | model", NULL, NULL); error_if_not(window, "glfw window error"); glfwMakeContextCurrent(window); glfwSetCharCallback(window, [](GLFWwindow* window, unsigned int key) { switch (key) { case 's': scene->draw_captureimage = true; break; case 'w': scene->draw_wireframe = ! scene->draw_wireframe; break; } }); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); #ifdef _WIN32 auto ok1 = glewInit(); error_if_not(GLEW_OK == ok1, "glew init error"); #endif auto state = new ShadeState(); init_shaders(state); init_textures(scene,state); auto mouse_last_x = -1.0; auto mouse_last_y = -1.0; while(! glfwWindowShouldClose(window)) { glfwGetFramebufferSize(window, &scene->image_width, &scene->image_height); scene->camera->width = (scene->camera->height * scene->image_width) / scene->image_height; shade(scene,state); if(glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT)) { double x, y; glfwGetCursorPos(window, &x, &y); if (mouse_last_x < 0 || mouse_last_y < 0) { mouse_last_x = x; mouse_last_y = y; } auto delta_x = x - mouse_last_x, delta_y = y - mouse_last_y; set_view_turntable(scene->camera, delta_x*0.01, -delta_y*0.01, 0, 0, 0); mouse_last_x = x; mouse_last_y = y; } else { mouse_last_x = -1; mouse_last_y = -1; } if(scene->draw_captureimage) { auto image = image3f(scene->image_width,scene->image_height); glReadPixels(0, 0, scene->image_width, scene->image_height, GL_RGB, GL_FLOAT, &image.at(0,0)); write_png(image_filename, image, true); scene->draw_captureimage = false; } glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); delete state; }
ENTRYPOINT void init_splitflap (ModeInfo *mi) { splitflap_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; MI_INIT (mi, bps); bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_splitflap (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); bp->first_time_p = True; if (!mode_str || !*mode_str || !strcasecmp(mode_str, "text")) { bp->clock_p = 0; } else if (!strcasecmp (mode_str, "clock") || !strcasecmp (mode_str, "clock12")) { bp->clock_p = 12; grid_width = 8; grid_height = 1; } else if (!strcasecmp (mode_str, "clock24")) { bp->clock_p = 24; grid_width = 6; grid_height = 1; } else { fprintf (stderr, "%s: `mode' must be text, clock12 or clock24: not `%s'\n", progname, mode_str); exit (1); } if (! bp->clock_p) { bp->tc = textclient_open (MI_DISPLAY (mi)); bp->text[0] = 0; if (grid_width > 10) textclient_reshape (bp->tc, grid_width, grid_height, grid_width, grid_height, 0); } if (bp->clock_p) speed /= 4; glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); if (!wire) { GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0}; /* GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/ GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {1.0, 1.0, 1.0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } { double spin_speed = 0.5; double wander_speed = 0.005; double tilt_speed = 0.001; double spin_accel = 0.5; char *s = do_spin; while (*s) { if (*s == 'x' || *s == 'X') bp->spinx = True; else if (*s == 'y' || *s == 'Y') bp->spiny = True; else if (*s == 'z' || *s == 'Z') bp->spinz = True; else if (*s == '0') ; else { fprintf (stderr, "%s: spin must contain only the characters X, Y, or Z (not \"%s\")\n", progname, do_spin); exit (1); } s++; } bp->rot = make_rotator (bp->spinx ? spin_speed : 0, bp->spiny ? spin_speed : 0, bp->spinz ? spin_speed : 0, spin_accel, do_wander ? wander_speed : 0, False); bp->rot2 = (face_front_p ? make_rotator (0, 0, 0, 0, tilt_speed, True) : 0); bp->trackball = gltrackball_init (False); } bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint)); for (i = 0; i < countof(all_objs); i++) bp->dlists[i] = glGenLists (1); parse_color (mi, "textColor", bp->text_color); for (i = 0; i < countof(all_objs); i++) { const struct gllist *gll = *all_objs[i]; char *key = 0; GLfloat spec[4] = {0.4, 0.4, 0.4, 1.0}; GLfloat shiny = 80; /* 0-128 */ glNewList (bp->dlists[i], GL_COMPILE); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glRotatef (-90, 1, 0, 0); glBindTexture (GL_TEXTURE_2D, 0); switch (i) { case SPLITFLAP_QUARTER_FRAME: key = "frameColor"; break; case SPLITFLAP_OUTER_FRAME: key = "caseColor"; break; case SPLITFLAP_DISC_QUARTER: key = (wire ? "frameColor" : "discColor"); break; case SPLITFLAP_FIN_EDGE_HALF: case SPLITFLAP_FIN_FACE_HALF: key = "finColor"; break; default: abort(); } parse_color (mi, key, bp->component_colors[i]); if (wire && i == SPLITFLAP_FIN_EDGE_HALF) bp->component_colors[i][0] = bp->component_colors[i][1] = bp->component_colors[i][2] = 0.7; glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); switch (i) { case SPLITFLAP_OUTER_FRAME: if (! splitflap_obj_outer_frame) splitflap_obj_outer_frame = (struct gllist *) calloc (1, sizeof(*splitflap_obj_outer_frame)); splitflap_obj_outer_frame->points = draw_outer_frame(mi); break; default: renderList (gll, wire); break; } glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEndList (); } if (grid_width < 1) grid_width = 1; if (grid_height < 1) grid_height = 1; bp->flappers = (flapper *) calloc (grid_width * grid_height, sizeof (flapper)); for (i = 0; i < grid_width * grid_height; i++) { flapper *f = &bp->flappers[i]; if (!bp->clock_p) { f->spool = ascii_spool; f->spool_size = countof (ascii_spool); } else { switch (i) { case 0: if (bp->clock_p == 12) { f->spool = digit_s1_spool; f->spool_size = countof (digit_s1_spool); } else { f->spool = digit_01_spool; f->spool_size = countof (digit_01_spool); } break; case 1: case 3: case 5: f->spool = digit_spool; f->spool_size = countof (digit_spool); break; case 2: case 4: f->spool = digit_05_spool; f->spool_size = countof (digit_05_spool); break; case 6: f->spool = ap_spool; f->spool_size = countof (ap_spool); break; case 7: f->spool = m_spool; f->spool_size = countof (m_spool); break; default: abort(); } } f->target_index = random() % f->spool_size; /* f->target_index = 0; */ f->current_index = f->target_index; f->missing = (((random() % 10) == 0) ? (random() % f->spool_size) : -1); } bp->font_data = load_texture_font (mi->dpy, "flapFont"); init_textures (mi); reshape_splitflap (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); }
extern "C" int main(int argc, char **argv) { #if _WIN32 // hack to redirect output to text files freopen("stdout.txt", "w", stdout); freopen("stderr.txt", "w", stderr); #endif clientConsole = new narf::ClientConsole(); narf::console = clientConsole; narf::console->println("Version: " + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + std::string(VERSION_RELEASE) + "+" VERSION_REV); if (enet_initialize() != 0) { narf::console->println("Error initializing ENet"); return 1; } narf::cmd::cmds["set"] = cmdSet; narf::cmd::cmds["quit"] = cmdQuit; narf::cmd::cmds["connect"] = cmdConnect; narf::cmd::cmds["disconnect"] = cmdDisconnect; narf::cmd::cmds["save"] = cmdSave; narf::cmd::cmds["saveconfig"] = cmdSaveConfig; narf::cmd::cmds["load"] = cmdLoad; narf::cmd::cmds["stats"] = cmdStats; narf::cmd::cmds["about"] = cmdAbout; narf::cmd::cmds["music"] = cmdMusic; narf::MemoryFile iniMem; auto configFile = narf::util::appendPath(narf::util::userConfigDir("narfblock"), "client.ini"); narf::console->println("Attempting to open user config file: " + configFile); if (!iniMem.read(configFile)) { configFile = narf::util::appendPath(narf::util::dataDir(), "client.ini"); narf::console->println("Could not load user config file; falling back to local config file: " + configFile); if (!iniMem.read(configFile)) { narf::console->println("Could not load local config file; falling back to compile-time defaults"); } } if (iniMem.size) { config.load(iniMem.data, iniMem.size); } config.updateSignal += configEvent; client = enet_host_create(nullptr, 1, narf::net::MAX_CHANNELS, 0, 0); if (!client) { fatalError("Could not create ENet client"); return 1; } if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { fatalError("SDL_Init() failed: " + std::string(SDL_GetError())); SDL_Quit(); return 1; } musicMutex = SDL_CreateMutex(); config.initBool("audio.enabled", true); SDL_DisplayMode mode; // TODO: iterate over monitors? if (SDL_GetDesktopDisplayMode(0, &mode)) { fatalError("SDL_GetDesktopDisplayMode failed: " + std::string(SDL_GetError())); SDL_Quit(); return 1; } auto w = mode.w; auto h = mode.h; narf::console->println("Current video mode is " + std::to_string(w) + "x" + std::to_string(h)); // TODO: convert these to be modifiable at runtime and use config.init* bool fullscreen = config.getBool("video.fullscreen", true); float width_cfg = config.getFloat("video.width", 0.6f); float height_cfg = config.getFloat("video.height", 0.6f); if (!fullscreen) { if (width_cfg > 1) { w = (int32_t)width_cfg; } else { w = (int32_t)((float)w * width_cfg); } if (height_cfg > 1) { h = (int32_t)height_cfg; } else { h = (int32_t)((float)h * height_cfg); } narf::console->println("Setting video to windowed " + std::to_string(w) + "x" + std::to_string(h)); } else { narf::console->println("Setting video to fullscreen"); } if (!initVideo(w, h, fullscreen)) { fatalError("Error: could not set OpenGL video mode " + std::to_string(w) + "x" + std::to_string(h)); SDL_Quit(); return 1; } clientConsole->setGLContext(display); config.initBool("video.vsync", false); newWorld(); playerEID = world->entityManager.newEntity(); { narf::EntityRef player(world->entityManager, playerEID); // initial player position player->position = narf::Vector3f(15.0f, 10.0f, 3.0f * 16.0f); player->prevPosition = player->position; } // initialize camera to look at origin cam.orientation.yaw = atan2f(cam.position.y, cam.position.x); cam.orientation.pitch = 0.0f; bouncyBlockEID = world->entityManager.newEntity(); { narf::EntityRef bouncyBlock(world->entityManager, bouncyBlockEID); bouncyBlock->position = narf::Vector3f(10.0f, 10.0f, 21.0f); bouncyBlock->prevPosition = bouncyBlock->position; bouncyBlock->bouncy = true; bouncyBlock->model = true; } if (!init_textures()) { fatalError("init_textures() failed"); return 1; } renderer = new narf::Renderer(world, *display, tilesTex); config.initInt32("video.renderDistance", 5); fpsTextBuffer = new narf::font::TextBuffer(*display, nullptr); blockInfoBuffer = new narf::font::TextBuffer(*display, nullptr); entityInfoBuffer = new narf::font::TextBuffer(*display, nullptr); locationBuffer = new narf::font::TextBuffer(*display, nullptr); config.initString("video.hudFont", "DroidSansMono"); config.initInt32("video.hudFontSize", 30); if (!fpsTextBuffer->getFont()) { fatalError("Error: could not load HUD font"); return 1; } config.initString("video.consoleFont", "DroidSansMono"); config.initInt32("video.consoleFontSize", 18); if (!clientConsole->getFont()) { fatalError("Error: could not load Console font"); return 1; } config.initString("video.consoleCursorShape", "default"); config.initBool("video.stereo.enabled", false); config.initBool("video.stereo.cross", true); config.initFloat("video.stereo.separation", 0.1f); SDL_SetRelativeMouseMode(SDL_TRUE); config.initDouble("misc.tickRate", 60); config.initDouble("misc.maxFrameTime", 0.25); narf::console->println("Unicode test\xE2\x80\xBC pi: \xCF\x80 (2-byte sequence), square root: \xE2\x88\x9A (3-byte sequence), U+2070E: \xF0\xA0\x9C\x8E (4-byte sequence)"); gameLoop = new ClientGameLoop(config.getDouble("misc.maxFrameTime"), config.getDouble("misc.tickRate")); gameLoop->run(); if (connectState == ConnectState::Connected) { enet_peer_disconnect(server, (uint32_t)narf::net::DisconnectType::UserQuit); } else if (connectState == ConnectState::Connecting) { enet_peer_reset(server); } enet_host_flush(client); enet_host_destroy(client); enet_deinitialize(); SDL_Quit(); return 0; }
void init(char *filename) { glEnable(GL_TEXTURE_2D); init_textures(filename); }
FX_ENTRY GrContext_t FX_CALL grSstWinOpen( GrScreenResolution_t screen_resolution, GrScreenRefresh_t refresh_rate, GrColorFormat_t color_format, GrOriginLocation_t origin_location, int nColBuffers, int nAuxBuffers) { uint32_t screen_width, screen_height; struct retro_variable var = { "mupen64-screensize", 0 }; // ZIGGY // allocate static texture names // the initial value should be big enough to support the maximal resolution free_texture = 32*1024*1024; default_texture = free_texture++; color_texture = free_texture++; depth_texture = free_texture++; LOG("grSstWinOpen(%d, %d, %d, %d, %d %d)\r\n", screen_resolution&~0x80000000, refresh_rate, color_format, origin_location, nColBuffers, nAuxBuffers); width = 640; height = 480; bool ret = environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); if (ret && var.value) { if (sscanf(var.value ? var.value : "640x480", "%dx%d", &width, &height) != 2) { width = 640; height = 480; } } glViewport(0, 0, width, height); lfb_color_fmt = color_format; if (origin_location != GR_ORIGIN_UPPER_LEFT) DISPLAY_WARNING("origin must be in upper left corner"); if (nColBuffers != 2) DISPLAY_WARNING("number of color buffer is not 2"); if (nAuxBuffers != 1) DISPLAY_WARNING("number of auxiliary buffer is not 1"); if (isExtensionSupported("GL_ARB_texture_env_combine") == 0 && isExtensionSupported("GL_EXT_texture_env_combine") == 0) DISPLAY_WARNING("Your video card doesn't support GL_ARB_texture_env_combine extension"); if (isExtensionSupported("GL_ARB_multitexture") == 0) DISPLAY_WARNING("Your video card doesn't support GL_ARB_multitexture extension"); if (isExtensionSupported("GL_ARB_texture_mirrored_repeat") == 0) DISPLAY_WARNING("Your video card doesn't support GL_ARB_texture_mirrored_repeat extension"); nbAuxBuffers = 4; //glGetIntegerv(GL_AUX_BUFFERS, &nbAuxBuffers); if (nbAuxBuffers > 0) printf("Congratulations, you have %d auxilliary buffers, we'll use them wisely !\n", nbAuxBuffers); blend_func_separate_support = 1; packed_pixels_support = 0; if (isExtensionSupported("GL_EXT_blend_func_separate") == 0) { DISPLAY_WARNING("GL_EXT_blend_func_separate not supported.\n"); blend_func_separate_support = 0; } else { printf("GL_EXT_blend_func_separate supported.\n"); blend_func_separate_support = 1; } // we can assume that non-GLES has GL_EXT_packed_pixels // support -it's included since OpenGL 1.2 #ifdef GLES if (isExtensionSupported("GL_EXT_packed_pixels") != 0) #endif packed_pixels_support = 1; if (isExtensionSupported("GL_ARB_texture_non_power_of_two") == 0) { DISPLAY_WARNING("GL_ARB_texture_non_power_of_two supported.\n"); npot_support = 0; } else { printf("GL_ARB_texture_non_power_of_two supported.\n"); npot_support = 1; } if (isExtensionSupported("GL_EXT_fog_coord") == 0) { DISPLAY_WARNING("GL_EXT_fog_coord not supported.\n"); fog_coord_support = 0; } else { printf("GL_EXT_fog_coord supported.\n"); fog_coord_support = 1; } if (isExtensionSupported("GL_ARB_shading_language_100") && isExtensionSupported("GL_ARB_shader_objects") && isExtensionSupported("GL_ARB_fragment_shader") && isExtensionSupported("GL_ARB_vertex_shader")) {} #ifdef GLES if (isExtensionSupported("GL_EXT_texture_format_BGRA8888")) { printf("GL_EXT_texture_format_BGRA8888 supported.\n"); bgra8888_support = 1; } else { DISPLAY_WARNING("GL_EXT_texture_format_BGRA8888 not supported.\n"); bgra8888_support = 0; } #endif glViewport(0, 0, width, height); viewport_width = width; viewport_height = height; // VP try to resolve z precision issues // glMatrixMode(GL_MODELVIEW); // glLoadIdentity(); // glTranslatef(0, 0, 1-zscale); // glScalef(1, 1, zscale); widtho = width/2; heighto = height/2; pBufferWidth = pBufferHeight = -1; current_buffer = GL_BACK; texture_unit = GL_TEXTURE0; { int i; for (i=0; i<NB_TEXBUFS; i++) texbufs[i].start = texbufs[i].end = 0xffffffff; } FindBestDepthBias(); init_geometry(); init_textures(); init_combiner(); return 1; }