| 1 |
+ |
#include <windows.h> |
| 2 |
+ |
#include <math.h> |
| 3 |
+ |
|
| 4 |
+ |
#include "Oni.h" |
| 5 |
+ |
#include "Oni_Persistence.h" |
| 6 |
+ |
#include "Daodan_Utility.h" |
| 7 |
+ |
|
| 8 |
+ |
#include "BFW_Utility.h" |
| 9 |
+ |
|
| 10 |
|
#include "daodan_gl.h" |
| 11 |
+ |
#include "oni_gl.h" |
| 12 |
|
|
| 13 |
|
#define max_modes (104) // Dirty hack to add more resolutions, it really should only be 16 ^_^ |
| 14 |
|
#define builtin_modes (sizeof(daodan_reslist) / sizeof(M3tDisplayMode)) |
| 45 |
|
|
| 46 |
|
const short daodan_resdepths[] = { 16, 32 }; |
| 47 |
|
|
| 48 |
+ |
DEVMODE orig_devmode, cur_devmode, new_devmode; |
| 49 |
+ |
|
| 50 |
+ |
void init_daodan_gl() |
| 51 |
+ |
{ |
| 52 |
+ |
memset(&orig_devmode, 0, sizeof(orig_devmode)); |
| 53 |
+ |
orig_devmode.dmSize = sizeof(orig_devmode); |
| 54 |
+ |
|
| 55 |
+ |
if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &orig_devmode)) |
| 56 |
+ |
{ |
| 57 |
+ |
orig_devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; |
| 58 |
+ |
orig_devmode.dmBitsPerPel = 32; |
| 59 |
+ |
orig_devmode.dmPelsWidth = GetSystemMetrics(SM_CXSCREEN); |
| 60 |
+ |
orig_devmode.dmPelsHeight = GetSystemMetrics(SM_CYSCREEN); |
| 61 |
+ |
} |
| 62 |
+ |
|
| 63 |
+ |
memcpy(&cur_devmode, &orig_devmode, sizeof(orig_devmode)); |
| 64 |
+ |
memcpy(&new_devmode, &orig_devmode, sizeof(orig_devmode)); |
| 65 |
+ |
} |
| 66 |
+ |
|
| 67 |
+ |
void update_cdmode() |
| 68 |
+ |
{ |
| 69 |
+ |
if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &cur_devmode)) |
| 70 |
+ |
{ |
| 71 |
+ |
cur_devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; |
| 72 |
+ |
cur_devmode.dmBitsPerPel = 32; |
| 73 |
+ |
cur_devmode.dmPelsWidth = GetSystemMetrics(SM_CXSCREEN); |
| 74 |
+ |
cur_devmode.dmPelsHeight = GetSystemMetrics(SM_CYSCREEN); |
| 75 |
+ |
} |
| 76 |
+ |
} |
| 77 |
+ |
|
| 78 |
|
unsigned int ONICALL daodan_enumerate_valid_display_modes(M3tDisplayMode modes[max_modes]) |
| 79 |
|
{ |
| 80 |
|
unsigned int vmodes = 0; |
| 81 |
< |
unsigned int screen_x = GetSystemMetrics(SM_CXSCREEN); |
| 82 |
< |
unsigned int screen_y = GetSystemMetrics(SM_CYSCREEN); |
| 81 |
> |
unsigned int screen_x = orig_devmode.dmPelsWidth; |
| 82 |
> |
unsigned int screen_y = orig_devmode.dmPelsHeight; |
| 83 |
|
|
| 84 |
|
int i, j; |
| 85 |
|
|
| 104 |
|
goto modesfull; |
| 105 |
|
} |
| 106 |
|
|
| 107 |
< |
modes[vmodes].Width = GetSystemMetrics(SM_CXSCREEN); |
| 108 |
< |
modes[vmodes].Height = GetSystemMetrics(SM_CYSCREEN); |
| 107 |
> |
modes[vmodes].Width = screen_x; |
| 108 |
> |
modes[vmodes].Height = screen_y; |
| 109 |
|
modes[vmodes].Depth = daodan_resdepths[i]; |
| 110 |
|
|
| 111 |
|
if (++vmodes == max_modes - builtin_modes + i) |
| 129 |
|
|
| 130 |
|
return (ChangeDisplaySettings(&devmode, CDS_TEST) == DISP_CHANGE_SUCCESSFUL); |
| 131 |
|
} |
| 132 |
+ |
|
| 133 |
+ |
int daodan_set_display_mode(short width, short height, short depth) |
| 134 |
+ |
{ |
| 135 |
+ |
if (M3gResolutionSwitch) |
| 136 |
+ |
{ |
| 137 |
+ |
DEVMODE new_devmode; |
| 138 |
+ |
new_devmode.dmSize = sizeof(new_devmode); |
| 139 |
+ |
new_devmode.dmFields = DM_BITSPERPEL | DM_PELSHEIGHT | DM_PELSWIDTH; |
| 140 |
+ |
new_devmode.dmPelsWidth = width; |
| 141 |
+ |
new_devmode.dmPelsHeight = height; |
| 142 |
+ |
new_devmode.dmBitsPerPel = depth; |
| 143 |
+ |
|
| 144 |
+ |
if (ChangeDisplaySettings(&new_devmode, CDS_TEST) != DISP_CHANGE_SUCCESSFUL) |
| 145 |
+ |
return 0; |
| 146 |
+ |
|
| 147 |
+ |
if (ChangeDisplaySettings(&new_devmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) |
| 148 |
+ |
return 0; |
| 149 |
+ |
|
| 150 |
+ |
update_cdmode(); |
| 151 |
+ |
gl->DisplayMode.Width = cur_devmode.dmPelsWidth; |
| 152 |
+ |
gl->DisplayMode.Height = cur_devmode.dmPelsHeight; |
| 153 |
+ |
if (cur_devmode.dmBitsPerPel > depth) |
| 154 |
+ |
gl->DisplayMode.Depth = cur_devmode.dmBitsPerPel; |
| 155 |
+ |
} |
| 156 |
+ |
else |
| 157 |
+ |
{ |
| 158 |
+ |
update_cdmode(); |
| 159 |
+ |
if (cur_devmode.dmBitsPerPel > depth) |
| 160 |
+ |
gl->DisplayMode.Depth = cur_devmode.dmBitsPerPel; |
| 161 |
+ |
} |
| 162 |
+ |
return 1; |
| 163 |
+ |
} |
| 164 |
+ |
|
| 165 |
+ |
void daodan_set_gamma(float gamma) |
| 166 |
+ |
{ |
| 167 |
+ |
WORD ramp[3 * 256]; |
| 168 |
+ |
int i; |
| 169 |
+ |
|
| 170 |
+ |
if (!gl_gamma_ramp_valid) |
| 171 |
+ |
return; |
| 172 |
+ |
|
| 173 |
+ |
gamma = (1.0f - gamma) * 1.2f + 0.4f; |
| 174 |
+ |
|
| 175 |
+ |
for (i = 0; i < sizeof(ramp); i++) |
| 176 |
+ |
{ |
| 177 |
+ |
int value = (int)(pow(gl_gamma_ramp[i] / 65535.0f, gamma) * 65535.0f); |
| 178 |
+ |
|
| 179 |
+ |
if (value < 0) |
| 180 |
+ |
value = 0; |
| 181 |
+ |
else if (value > 65535) |
| 182 |
+ |
value = 65535; |
| 183 |
+ |
|
| 184 |
+ |
ramp[i] = value; |
| 185 |
+ |
} |
| 186 |
+ |
|
| 187 |
+ |
if (gl_api->wglSetDeviceGammaRamp3DFX) |
| 188 |
+ |
gl_api->wglSetDeviceGammaRamp3DFX(gl->HDC, ramp); |
| 189 |
+ |
else |
| 190 |
+ |
SetDeviceGammaRamp(gl->HDC, ramp); |
| 191 |
+ |
} |
| 192 |
+ |
|
| 193 |
+ |
int ONICALL daodangl_platform_initialize() |
| 194 |
+ |
{ |
| 195 |
+ |
static M3tDisplayMode lastmode = {0, 0, 0, 0}; |
| 196 |
+ |
|
| 197 |
+ |
if (lastmode.Width != gl->DisplayMode.Width || lastmode.Height != gl->DisplayMode.Height || lastmode.Depth != gl->DisplayMode.Depth) |
| 198 |
+ |
if (!daodan_set_display_mode(gl->DisplayMode.Width, gl->DisplayMode.Height, gl->DisplayMode.Depth)) |
| 199 |
+ |
if (gl->DisplayMode.Width != 640 || gl->DisplayMode.Height != 480 || gl->DisplayMode.Depth != 16) |
| 200 |
+ |
{ |
| 201 |
+ |
gl->DisplayMode.Width = 640; |
| 202 |
+ |
gl->DisplayMode.Height = 480; |
| 203 |
+ |
if (!daodan_set_display_mode(640, 480, 16)) |
| 204 |
+ |
goto exit_err; |
| 205 |
+ |
} |
| 206 |
+ |
|
| 207 |
+ |
if (lastmode.Width != gl->DisplayMode.Width || lastmode.Height != gl->DisplayMode.Height) |
| 208 |
+ |
{ |
| 209 |
+ |
RECT Rect; |
| 210 |
+ |
Rect.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (gl->DisplayMode.Width / 2); |
| 211 |
+ |
Rect.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (gl->DisplayMode.Height / 2); |
| 212 |
+ |
Rect.right = Rect.left + gl->DisplayMode.Width; |
| 213 |
+ |
Rect.bottom = Rect.top + gl->DisplayMode.Height; |
| 214 |
+ |
AdjustWindowRect(&Rect, WS_OVERLAPPED | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, FALSE); |
| 215 |
+ |
|
| 216 |
+ |
SetWindowPos(ONgPlatformData.Window, NULL, Rect.left, Rect.top, Rect.right - Rect.left, Rect.bottom - Rect.top, SWP_NOACTIVATE | SWP_NOZORDER); |
| 217 |
+ |
} |
| 218 |
+ |
|
| 219 |
+ |
if (gl->HDC == NULL) |
| 220 |
+ |
if ((gl->HDC = GetDC(ONgPlatformData.Window)) == NULL) |
| 221 |
+ |
goto exit_err; |
| 222 |
+ |
|
| 223 |
+ |
if (gl_api->wglGetDeviceGammaRamp3DFX != NULL) |
| 224 |
+ |
{ |
| 225 |
+ |
DDrStartupMessage("Using 3DFX gamma adjustment"); |
| 226 |
+ |
|
| 227 |
+ |
if (gl_api->wglGetDeviceGammaRamp3DFX(gl->HDC, gl_gamma_ramp)) |
| 228 |
+ |
gl_gamma_ramp_valid = 1; |
| 229 |
+ |
} |
| 230 |
+ |
else |
| 231 |
+ |
{ |
| 232 |
+ |
DDrStartupMessage("Using standard Windows gamma adjustment"); |
| 233 |
+ |
|
| 234 |
+ |
if (GetDeviceGammaRamp(gl->HDC, gl_gamma_ramp)) |
| 235 |
+ |
gl_gamma_ramp_valid = 1; |
| 236 |
+ |
} |
| 237 |
+ |
|
| 238 |
+ |
// if (gl_gamma_ramp_valid) |
| 239 |
+ |
// daodan_set_gamma(ONrPersist_GetGamma()); Its not working :( |
| 240 |
+ |
// else |
| 241 |
+ |
DDrStartupMessage("gamma adjustment not supported"); |
| 242 |
+ |
|
| 243 |
+ |
if (!gl_platform_set_pixel_format(gl->HDC)) |
| 244 |
+ |
if (gl->DisplayMode.Depth != 16) |
| 245 |
+ |
{ |
| 246 |
+ |
if (!daodan_set_display_mode(gl->DisplayMode.Width, gl->DisplayMode.Height, 16)) |
| 247 |
+ |
goto exit_err; |
| 248 |
+ |
|
| 249 |
+ |
if (!gl_platform_set_pixel_format(gl->HDC)) |
| 250 |
+ |
goto exit_err; |
| 251 |
+ |
} |
| 252 |
+ |
|
| 253 |
+ |
lastmode.Width = gl->DisplayMode.Width; |
| 254 |
+ |
lastmode.Height = gl->DisplayMode.Height; |
| 255 |
+ |
lastmode.Depth = gl->DisplayMode.Depth; |
| 256 |
+ |
|
| 257 |
+ |
return 0; |
| 258 |
+ |
|
| 259 |
+ |
exit_err: |
| 260 |
+ |
AUrMessageBox(1, "Failed to initialize OpenGL contexts; Oni will now exit."); |
| 261 |
+ |
exit(0); |
| 262 |
+ |
return 1; |
| 263 |
+ |
} |