//=========================================================================== // windowedMode // Only adjusts the window style and size. //=========================================================================== void windowedMode(int width, int height) { // We need to have a large enough client area. RECT rect; int xoff = (GetSystemMetrics(SM_CXSCREEN) - width) / 2, yoff = (GetSystemMetrics(SM_CYSCREEN) - height) / 2; LONG style; if(ArgCheck("-nocenter")) xoff = yoff = 0; if(ArgCheckWith("-xpos", 1)) xoff = atoi(ArgNext()); if(ArgCheckWith("-ypos", 1)) yoff = atoi(ArgNext()); rect.left = xoff; rect.top = yoff; rect.right = xoff + width; rect.bottom = yoff + height; // Set window style. style = GetWindowLong(windowHandle, GWL_STYLE) | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; SetWindowLong(windowHandle, GWL_STYLE, style); AdjustWindowRect(&rect, style, FALSE); SetWindowPos(windowHandle, 0, xoff, yoff, /*rect.left, rect.top, */ rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER); screenWidth = width; screenHeight = height; }
/* * Set the data path. The game module is responsible for calling this. */ void R_InitDataPaths(const char *path, boolean justGamePaths) { int i; M_TranslatePath(path, dataPath); Dir_ValidDir(dataPath); VERBOSE(Con_Message("R_SetDataPath: %s\n", M_Pretty(dataPath))); // Update the paths of each class. for(i = 0; i < NUM_RESOURCE_CLASSES; i++) { // The Graphics class resources are under Doomsday's control. if(justGamePaths && i == RC_GRAPHICS) continue; memset(&classInfo[i], 0, sizeof(classInfo[i])); // The -texdir option specifies a path to look for TGA textures. if(ArgCheckWith(explicitOption[i][0], 1)) { M_TranslatePath(ArgNext(), classInfo[i].path); } else { // Build the path for the resource class using the default // elements. strcpy(classInfo[i].path, dataPath); strcat(classInfo[i].path, defaultResourcePath[i]); } Dir_ValidDir(classInfo[i].path); // The overriding path. if(ArgCheckWith(explicitOption[i][1], 1)) { M_TranslatePath(ArgNext(), classInfo[i].overridePath); } Dir_ValidDir(classInfo[i].overridePath); VERBOSE2(Con_Message (" %i: %s (%s)\n", i, M_Pretty(classInfo[i].path), M_Pretty(classInfo[i].overridePath))); } }
/* * DD_InitDGL * Load the rendering DLL and setup the driver struct. The rendering DLL * could be changed at runtime (but such an operation is currently never * done). Returns true if successful. */ int DD_InitDGL(void) { char *libName = DEFAULT_LIB_NAME; // See if a specific renderer DLL is specified. if(ArgCheckWith("-gl", 1)) libName = ArgNext(); // Load the DLL. #ifdef WIN32 dglHandle = LoadLibrary(libName); #endif #ifdef UNIX dglHandle = lt_dlopenext(libName); #endif if(!dglHandle) { #ifdef WIN32 DD_ErrorBox(true, "DD_InitDGL: Loading of %s failed (error %i).\n", libName, GetLastError()); #endif #ifdef UNIX DD_ErrorBox(true, "DD_InitDGL: Loading of %s failed.\n %s.\n", libName, lt_dlerror()); #endif return false; } // Prepare the driver struct. if(!DD_InitDGLDriver()) { DD_ErrorBox(true, "DD_InitDGL: Rendering DLL %s is incompatible.\n", libName); return false; } // Check the version of the DLL. if(gl.GetInteger(DGL_VERSION) < DGL_VERSION_NUM) { DD_ErrorBox(true, "DD_InitDGL: Version %i renderer found. " "Version %i is required.\n", gl.GetInteger(DGL_VERSION), DGL_VERSION_NUM); return false; } return true; }
/** * NOTE: Window, height, etc. must be set before calling this. */ void Window::Setup(void) { uint realWidth = GetSystemMetrics(SM_CXSCREEN); uint realHeight = GetSystemMetrics(SM_CYSCREEN); int xOff, yOff; RECT rect; // Update our bitdepth if it's not yet known. if(!bits) UseDesktopBits(); DP("Window setup:"); if(isWindow) { if(width > realWidth) width = realWidth; if(height > realHeight) height = realHeight; // Center by default. xOff = (realWidth - width) / 2; yOff = (realHeight - height) / 2; // Check for modifier options. if(ArgCheck("-nocenter")) xOff = yOff = 0; if(ArgCheckWith("-xpos", 1)) xOff = atoi(ArgNext()); if(ArgCheckWith("-ypos", 1)) yOff = atoi(ArgNext()); LONG style = GetWindowLong(hwnd, GWL_STYLE) | WS_VISIBLE | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_SYSMENU | WS_MINIMIZEBOX; SetWindowLong(hwnd, GWL_STYLE, style); // Adjust the size of the window so the client area is the // right size. rect.left = rect.top = 0; rect.right = width; rect.bottom = height; AdjustWindowRect(&rect, style, FALSE); // But we also want the window's top left corner to be at // (xOff, yOff). SetWindowPos(hwnd, HWND_TOP, xOff, yOff, rect.right - rect.left, rect.bottom - rect.top, 0); DP(" Windowed mode: x=%i, y=%i, w=%i, h=%i", xOff, yOff, rect.right - rect.left, rect.bottom - rect.top); } else { // In fullscreen, the setup is much simpler. SetWindowLong(hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); SetWindowPos(hwnd, HWND_TOP, 0, 0, width, height, 0); DP(" Fullscreen mode: w=%i, h=%i", width, height); } }
//=========================================================================== // fullscreenMode // Change the display mode using the Win32 API. // The closest available refresh rate is selected. //=========================================================================== int fullscreenMode(int width, int height, int bpp) { DEVMODE current, testMode, newMode; int res, i; // First get the current settings. memset(¤t, 0, sizeof(current)); current.dmSize = sizeof(DEVMODE); if(EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, ¤t)) { if(!bpp) bpp = current.dmBitsPerPel; } else if(!bpp) { // A safe fallback. bpp = 16; } // Override refresh rate? if(ArgCheckWith("-refresh", 1)) current.dmDisplayFrequency = strtol(ArgNext(), 0, 0); // Clear the structure. memset(&newMode, 0, sizeof(newMode)); newMode.dmSize = sizeof(newMode); // Let's enumerate all possible modes to find the most suitable one. for(i = 0;; i++) { memset(&testMode, 0, sizeof(testMode)); testMode.dmSize = sizeof(DEVMODE); if(!EnumDisplaySettings(NULL, i, &testMode)) break; if(testMode.dmPelsWidth == (unsigned) width && testMode.dmPelsHeight == (unsigned) height && testMode.dmBitsPerPel == (unsigned) bpp) { // This looks promising. We'll take the one that best matches // the current refresh rate. if(abs(current.dmDisplayFrequency - testMode.dmDisplayFrequency) < abs(current.dmDisplayFrequency - newMode.dmDisplayFrequency)) { memcpy(&newMode, &testMode, sizeof(DEVMODE)); } } } if(!newMode.dmPelsWidth) { // A perfect match was not found. Let's try something. newMode.dmPelsWidth = width; newMode.dmPelsHeight = height; newMode.dmBitsPerPel = bpp; newMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; } if((res = ChangeDisplaySettings(&newMode, 0)) != DISP_CHANGE_SUCCESSFUL) { Con_Message("drOpenGL.setResolution: Error %x.\n", res); return 0; // Failed, damn you. } // Set the correct window style and size. SetWindowLong(windowHandle, GWL_STYLE, WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); SetWindowPos(windowHandle, 0, 0, 0, width, height, SWP_NOZORDER); // Update the screen size variables. screenWidth = width; screenHeight = height; if(bpp) screenBits = bpp; // Done! return 1; }