#include #include #include "Oni.h" #include "Oni_Persistence.h" #include "Daodan_Utility.h" #include "BFW_Utility.h" #include "daodan_gl.h" #include "oni_gl.h" #define max_modes (104) // Dirty hack to add more resolutions, it really should only be 16 ^_^ #define builtin_modes (sizeof(daodan_reslist) / sizeof(M3tDisplayMode)) #define builtin_depths (sizeof(daodan_resdepths) / sizeof(short)) const M3tDisplayMode daodan_reslist[] = { { 720 , 480, 0, 0 }, { 720 , 576, 0, 0 }, { 768 , 480, 0, 0 }, { 800 , 480, 0, 0 }, { 800 , 600, 0, 0 }, { 852 , 480, 0, 0 }, { 856 , 480, 0, 0 }, { 960 , 540, 0, 0 }, { 960 , 720, 0, 0 }, { 1024, 576, 0, 0 }, { 1024, 600, 0, 0 }, { 1024, 640, 0, 0 }, { 1024, 768, 0, 0 }, { 1152, 768, 0, 0 }, { 1152, 864, 0, 0 }, { 1280, 720, 0, 0 }, { 1280, 768, 0, 0 }, { 1280, 800, 0, 0 }, { 1280, 960, 0, 0 }, { 1280, 1024, 0, 0 }, { 1366, 768, 0, 0 }, { 1400, 1050, 0, 0 }, { 1440, 900, 0, 0 }, { 1600, 900, 0, 0 }, { 1600, 1200, 0, 0 }, { 1920, 1080, 0, 0 }, { 1920, 1200, 0, 0 }, { 1920, 1440, 0, 0 }, }; short daodan_resdepths[] = { 16, 32 }; DEVMODE orig_devmode, cur_devmode, new_devmode; void init_daodan_gl() { DDrStartupMessage("initalizing daodan gl"); memset(&orig_devmode, 0, sizeof(orig_devmode)); orig_devmode.dmSize = sizeof(orig_devmode); if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &orig_devmode)) { orig_devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; orig_devmode.dmBitsPerPel = 32; orig_devmode.dmPelsWidth = GetSystemMetrics(SM_CXSCREEN); orig_devmode.dmPelsHeight = GetSystemMetrics(SM_CYSCREEN); } memcpy(&cur_devmode, &orig_devmode, sizeof(orig_devmode)); memcpy(&new_devmode, &orig_devmode, sizeof(orig_devmode)); } void update_cdmode() { if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &cur_devmode)) { cur_devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; cur_devmode.dmBitsPerPel = 32; cur_devmode.dmPelsWidth = GetSystemMetrics(SM_CXSCREEN); cur_devmode.dmPelsHeight = GetSystemMetrics(SM_CYSCREEN); } } unsigned int ONICALL daodan_enumerate_valid_display_modes(M3tDisplayMode modes[max_modes]) { unsigned int vmodes = 0; unsigned int screen_x = orig_devmode.dmPelsWidth; unsigned int screen_y = orig_devmode.dmPelsHeight; int i, j; DDrStartupMessage("listing display modes"); if (!M3gResolutionSwitch) daodan_resdepths[0] = orig_devmode.dmBitsPerPel; for (i = 0; i < builtin_depths; i ++) { bool scrInsert = false; modes[vmodes].Width = 640; modes[vmodes].Height = 480; modes[vmodes].Depth = daodan_resdepths[i]; if (++vmodes == max_modes - builtin_modes + i) goto modesfull; for (j = 0; j < builtin_modes; j ++) if (!(daodan_reslist[j].Width == 640 && daodan_reslist[j].Height == 480) && !(daodan_reslist[j].Width == screen_x && daodan_reslist[j].Height == screen_y) && ((daodan_reslist[j].Width < screen_x && daodan_reslist[j].Height < screen_y) || (M3gResolutionSwitch && daodan_testmode(daodan_reslist[j])))) { if (!scrInsert && (daodan_reslist[j].Width > screen_x || (daodan_reslist[j].Width == screen_x && daodan_reslist[j].Height > screen_y))) { modes[vmodes].Width = screen_x; modes[vmodes].Height = screen_y; modes[vmodes].Depth = daodan_resdepths[i]; if (++vmodes == max_modes - builtin_modes + i) goto modesfull; scrInsert = true; } modes[vmodes].Width = daodan_reslist[j].Width; modes[vmodes].Height = daodan_reslist[j].Height; modes[vmodes].Depth = daodan_resdepths[i]; if (++vmodes == max_modes - builtin_modes + i) goto modesfull; } if (!scrInsert) { modes[vmodes].Width = screen_x; modes[vmodes].Height = screen_y; modes[vmodes].Depth = daodan_resdepths[i]; if (++vmodes == max_modes - builtin_modes + i) goto modesfull; } if (!M3gResolutionSwitch) goto modesfull; } modesfull: DDrStartupMessage("%d modes available", vmodes); return vmodes; } bool daodan_testmode(M3tDisplayMode mode) { DEVMODE devmode; memset(&devmode, 0, sizeof(devmode)); devmode.dmSize = sizeof(devmode); devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; devmode.dmBitsPerPel = mode.Depth; devmode.dmPelsWidth = mode.Width; devmode.dmPelsHeight = mode.Height; return (ChangeDisplaySettings(&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); } int daodan_set_display_mode(short width, short height, short depth) { if (M3gResolutionSwitch) { DEVMODE new_devmode; new_devmode.dmSize = sizeof(new_devmode); new_devmode.dmFields = DM_BITSPERPEL | DM_PELSHEIGHT | DM_PELSWIDTH; new_devmode.dmPelsWidth = width; new_devmode.dmPelsHeight = height; new_devmode.dmBitsPerPel = depth; if (ChangeDisplaySettings(&new_devmode, CDS_TEST) != DISP_CHANGE_SUCCESSFUL) return 0; if (ChangeDisplaySettings(&new_devmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) return 0; update_cdmode(); gl->DisplayMode.Width = cur_devmode.dmPelsWidth; gl->DisplayMode.Height = cur_devmode.dmPelsHeight; if (cur_devmode.dmBitsPerPel > depth) gl->DisplayMode.Depth = cur_devmode.dmBitsPerPel; } else { update_cdmode(); if (cur_devmode.dmBitsPerPel > depth) gl->DisplayMode.Depth = cur_devmode.dmBitsPerPel; } return 1; } void daodan_set_gamma(float gamma) { WORD ramp[3 * 256]; int i; if (!gl_gamma_ramp_valid) return; gamma = (1.0f - gamma) * 1.2f + 0.4f; for (i = 0; i < sizeof(ramp); i++) { int value = (int)(pow(gl_gamma_ramp[i] / 65535.0f, gamma) * 65535.0f); if (value < 0) value = 0; else if (value > 65535) value = 65535; ramp[i] = value; } if (gl_api->wglSetDeviceGammaRamp3DFX) gl_api->wglSetDeviceGammaRamp3DFX(gl->HDC, ramp); else SetDeviceGammaRamp(gl->HDC, ramp); } int ONICALL daodangl_platform_initialize() { static M3tDisplayMode lastmode = {0, 0, 0, 0}; if (lastmode.Width != gl->DisplayMode.Width || lastmode.Height != gl->DisplayMode.Height || lastmode.Depth != gl->DisplayMode.Depth) if (!daodan_set_display_mode(gl->DisplayMode.Width, gl->DisplayMode.Height, gl->DisplayMode.Depth)) if (gl->DisplayMode.Width != 640 || gl->DisplayMode.Height != 480 || gl->DisplayMode.Depth != 16) { gl->DisplayMode.Width = 640; gl->DisplayMode.Height = 480; if (!daodan_set_display_mode(640, 480, 16)) goto exit_err; } if (lastmode.Width != gl->DisplayMode.Width || lastmode.Height != gl->DisplayMode.Height) { RECT Rect; Rect.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (gl->DisplayMode.Width / 2); Rect.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (gl->DisplayMode.Height / 2); Rect.right = Rect.left + gl->DisplayMode.Width; Rect.bottom = Rect.top + gl->DisplayMode.Height; AdjustWindowRect(&Rect, WS_OVERLAPPED | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, FALSE); SetWindowPos(ONgPlatformData.Window, NULL, Rect.left, Rect.top, Rect.right - Rect.left, Rect.bottom - Rect.top, SWP_NOACTIVATE | SWP_NOZORDER); } if (gl->HDC == NULL) if ((gl->HDC = GetDC(ONgPlatformData.Window)) == NULL) goto exit_err; if (gl_api->wglGetDeviceGammaRamp3DFX != NULL) { DDrStartupMessage("Using 3DFX gamma adjustment"); if (gl_api->wglGetDeviceGammaRamp3DFX(gl->HDC, gl_gamma_ramp)) gl_gamma_ramp_valid = 1; } else { DDrStartupMessage("Using standard Windows gamma adjustment"); if (GetDeviceGammaRamp(gl->HDC, gl_gamma_ramp)) gl_gamma_ramp_valid = 1; } // if (gl_gamma_ramp_valid) // daodan_set_gamma(ONrPersist_GetGamma()); Its not working :( // else DDrStartupMessage("gamma adjustment not supported"); if (!gl_platform_set_pixel_format(gl->HDC)) if (gl->DisplayMode.Depth != 16) { if (!daodan_set_display_mode(gl->DisplayMode.Width, gl->DisplayMode.Height, 16)) goto exit_err; if (!gl_platform_set_pixel_format(gl->HDC)) goto exit_err; } lastmode.Width = gl->DisplayMode.Width; lastmode.Height = gl->DisplayMode.Height; lastmode.Depth = gl->DisplayMode.Depth; return 0; exit_err: AUrMessageBox(1, "Failed to initialize OpenGL contexts; Oni will now exit."); exit(0); return 1; }