int main(int argc, char* argv[]) { vsx_argvector::get_instance()->init_from_argc_argv(argc, argv); if (vsx_argvector::get_instance()->has_param("help")) { glewInit(); app_print_cli_help(); exit(0); } // Initialise GLFW glfwInit(); set_modifiers(); int width, height, running, frames, x, y; double t, t1; char titlestr[ 200 ]; bool start_fullscreen = false; bool manual_resolution_set = false; int x_res = 1280; int y_res = 720; if (vsx_argvector::get_instance()->has_param("f")) { start_fullscreen = true; } if (vsx_argvector::get_instance()->has_param_with_value("s")) { vsx_string arg2 = vsx_argvector::get_instance()->get_param_value("s"); vsx_avector<vsx_string> parts; vsx_string deli = ","; explode(arg2, deli, parts); if (parts.size() == 2) { x_res = vsx_string_helper::s2i(parts[0]); y_res = vsx_string_helper::s2i(parts[1]); manual_resolution_set = true; } else { deli = "x"; explode(arg2, deli, parts); if ( parts.size() == 2 ) { x_res = vsx_string_helper::s2i(parts[0]); y_res = vsx_string_helper::s2i(parts[1]); manual_resolution_set = true; } } } if (start_fullscreen && !manual_resolution_set) { // try to get the resolution from the desktop for fullscreen GLFWvidmode video_mode; glfwGetDesktopMode(&video_mode); x_res = video_mode.Height; y_res = video_mode.Width; } if (vsx_argvector::get_instance()->has_param("gl_debug")) { printf("enabling GL DEBUG\n"); glfwOpenWindowHint( GLFW_OPENGL_DEBUG_CONTEXT , GL_TRUE ); } // OpenGL version glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 2); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1); if( !glfwOpenWindow( x_res, y_res, 0,0,0,0,16,0, start_fullscreen?GLFW_FULLSCREEN:GLFW_WINDOW ) ) // GLFW_FULLSCREEN { printf("Error! Could not create an OpenGL context. Please check your GPU drivers...\n"); glfwTerminate(); return 0; } glewInit(); if (start_fullscreen) glfwEnable( GLFW_MOUSE_CURSOR ); app_load(0); glfwEnable(GLFW_AUTO_POLL_EVENTS); for (int i = 1; i < argc; i++) { vsx_string arg1 = argv[i]; if (arg1 == "-p") { if (i+1 < argc) { i++; vsx_string arg2 = argv[i]; vsx_avector<vsx_string> parts; vsx_string deli = ","; explode(arg2, deli, parts); glfwSetWindowPos( vsx_string_helper::s2i(parts[0]), vsx_string_helper::s2i(parts[1]) ); } } } glfwSetKeyCallback(&key_event); glfwSetMouseButtonCallback(&mouse_button_event); glfwSetMousePosCallback(&mouse_pos_event); glfwSetCharCallback(&key_char_event); glfwSetMouseWheelCallback(&mouse_wheel); // set window size callback function glfwSetWindowSizeCallback(window_size); // Enable sticky keys glfwEnable( GLFW_STICKY_KEYS ); // vsync handling bool vsync = true; if (vsx_argvector::get_instance()->has_param("novsync")) { vsync = false; glfwSwapInterval(0); } else { glfwSwapInterval(1); } // Main loop running = GL_TRUE; frames = 0; if (vsx_argvector::get_instance()->has_param("gl_debug")) { // enable debug callback if (__GLEW_ARB_debug_output) { glDebugMessageCallbackARB( myErrorCallback, NULL); GLuint unusedIds = 0; glDebugMessageControlARB( GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, &unusedIds, true ); } } int display_gpu_vram_stats = 0; if (vsx_argvector::get_instance()->has_param("gl_vram")) { display_gpu_vram_stats = 1; } #if PLATFORM_FAMILY == PLATFORM_FAMILY_UNIX sprintf( titlestr, "Vovoid VSXu Artiste %s [GNU/Linux %d-bit]", vsxu_ver, PLATFORM_BITS); #endif #if PLATFORM_FAMILY == PLATFORM_FAMILY_WINDOWS sprintf( titlestr, "Vovoid VSXu Artiste %s [Windows %d-bit]", vsxu_ver, PLATFORM_BITS); #endif glfwSetWindowTitle( titlestr ); vsx_timer frame_delay; int initial_vram_free = 0; while( running ) { frame_delay.start(); if (mouse_pos_type) { if (mouse_pos_type == 1) app_mouse_move(last_x,last_y); else app_mouse_move_passive(last_x,last_y); mouse_pos_type = 0; } if (__GLEW_NVX_gpu_memory_info && display_gpu_vram_stats) { // #define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047 // #define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048 // #define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049 // #define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A // #define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B // GLint total_memory; // GLint total_available; GLint available_memory; // GLint eviction_count; // GLint eviction_size; // glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &total_memory); // glGetIntegerv(GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &total_available); // glGetIntegerv(GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX, &eviction_count); // glGetIntegerv(GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX, &eviction_size); glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &available_memory); // float available_memory_f = (float)available_memory; if (initial_vram_free == 0) initial_vram_free = available_memory >> 10; vsx_printf("GPU MEMORY INFO: Before frame: available vram: %d MB\n", available_memory >> 10); vsx_printf("GPU MEMORY INFO: Probably used vram: %d MB\n", initial_vram_free - (available_memory >> 10)); //if (gtm) //((vsx_tm*)gtm)->plot( available_memory_f, "gpu memory free" ); } app_pre_draw(); // Get time and mouse position t = glfwGetTime(); glfwGetMousePos( &x, &y ); float delta = t-t1; t1 = t; if (key_pressed != -1) { //printf("%f\n", delta); key_time += delta; if (key_time > 0.3f) { key_repeat_time += delta; if (key_repeat_time > initial_key_delay) { key_repeat_time = 0.0f; if (key_character != -1) app_char(key_character); app_key_down((long)key_pressed); initial_key_delay *= 0.99f; //printf("repeating key: %d\n", key_character); } } } frames ++; // Get window size (may be different than the requested size) glfwGetWindowSize( &width, &height ); height = height > 0 ? height : 1; // Set viewport vsx_gl_state::get_instance()->viewport_set( 0, 0, width, height ); // Clear color buffer glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Reset The Modelview Matrix app_draw(0); glfwSwapBuffers(); //#if (PLATFORM != PLATFORM_WINDOWS) // if (!vsync) // { // float dtime = frame_delay.dtime(); // if (dtime < 1.0f/60.0f) // { // float sleeptime = (1.0f / 60.0f - dtime)*1000000.0f; // usleep( (useconds_t) sleeptime ); // } // } //#endif running = glfwGetWindowParam( GLFW_OPENED ); }
static void load_options(void) { XFILE *file; Options tmp; int error = 0; long n, opt_n; get_set_video(0); /* DjV 007 030103 get current video mode */ if ((file = x_fopen(optname, O_DENYW | O_RDONLY, &error)) != NULL) { opt_n = sizeof(Options); tmp.version = 0; x_fread(file, &tmp, sizeof(int)); /* HR 240103: load older cfg versions */ if ( tmp.version >= MIN_VERSION && tmp.version < CFG_VERSION ) { memset(&tmp.V2_2, 0, sizeof(tmp.V2_2)); opt_n -= sizeof(tmp.V2_2); } x_fclose(file); } if ((file = x_fopen(optname, O_DENYW | O_RDONLY, &error)) != NULL) { if ((n = x_fread(file, &tmp, opt_n)) == opt_n) { if ( tmp.version >= MIN_VERSION /* DjV 005 120103 (was 0x119) */ && tmp.version <= CFG_VERSION && tmp.magic == MAGIC ) { options = tmp; if (opt_n != sizeof(Options)) /* HR 240103 */ { options.V2_2.fields = WD_SHSIZ | WD_SHDAT | WD_SHTIM | WD_SHATT; /* DjV 010 251202 HR 240103 */ options.attribs = FA_SUBDIR | FA_SYSTEM; /* DjV 004 251202 HR 240103 */ } ins_shorts(); /* DjV 019 080103 put kbd shortcuts into menu texts */ wd_deselect_all(); wd_default(); if (tmp.cprefs & SAVE_COLORS) error = load_colors(file); if (error == 0) if ((error = dsk_load(file)) == 0) if ((error = ft_load(file)) == 0) if ((error = icnt_load(file)) == 0) if ((error = app_load(file)) == 0) if ((error = prg_load(file)) == 0) error = wd_load(file); } else { alert_printf(1, MVALIDCF); x_fclose(file); return; } /* DjV 007 030103 ---vvv--- */ /* If read ok, set video state but do not change resolution */ get_set_video(1); /* DjV 007 030103 ---^^^--- */ } else { error = (n < 0) ? (int) n : EEOF; hndl_error(MLOADCFG, error); x_fclose(file); return; } x_fclose(file); } if (error != 0) { hndl_error(MLOADCFG, error); opt_default(); dsk_default(); ft_default(); icnt_default(); app_default(); prg_default(); wd_default(); } if (options.version < 0x0130) options.dial_mode = (options.cprefs & 0x80) ? XD_BUFFERED : XD_NORMAL; xd_setposmode((options.cprefs & DIALPOS_MODE) ? XD_MOUSE : XD_CENTERED); set_dialmode(); options.version = CFG_VERSION; }