source: Daodan/src/Daodan_GL.c@ 693

Last change on this file since 693 was 692, checked in by alloc, 12 years ago

Daodan: Lots of cleanups (mostly unnecessary includes removed, empty files deleted, case of filenames corrected)

File size: 8.1 KB
RevLine 
[326]1#include <windows.h>
2#include <math.h>
3
4#include "Oni.h"
5#include "Daodan_Utility.h"
[677]6#include <GL/gl.h>
7#include <GL/glu.h>
8#include "Daodan_Win32.h"
[326]9
[692]10#include "Daodan_GL.h"
11#include "Oni_GL.h"
[297]12
[316]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))
15#define builtin_depths (sizeof(daodan_resdepths) / sizeof(short))
[297]16
[692]17bool daodan_testmode(M3tDisplayMode mode);
18
[297]19const M3tDisplayMode daodan_reslist[] = {
[316]20 { 720 , 480, 0, 0 },
21 { 720 , 576, 0, 0 },
22 { 768 , 480, 0, 0 },
23 { 800 , 480, 0, 0 },
[340]24 { 800 , 600, 0, 0 },
[316]25 { 852 , 480, 0, 0 },
26 { 856 , 480, 0, 0 },
27 { 960 , 540, 0, 0 },
28 { 960 , 720, 0, 0 },
29 { 1024, 576, 0, 0 },
30 { 1024, 600, 0, 0 },
31 { 1024, 640, 0, 0 },
[297]32 { 1024, 768, 0, 0 },
[316]33 { 1152, 768, 0, 0 },
34 { 1152, 864, 0, 0 },
35 { 1280, 720, 0, 0 },
36 { 1280, 768, 0, 0 },
37 { 1280, 800, 0, 0 },
38 { 1280, 960, 0, 0 },
[297]39 { 1280, 1024, 0, 0 },
[316]40 { 1366, 768, 0, 0 },
41 { 1400, 1050, 0, 0 },
42 { 1440, 900, 0, 0 },
43 { 1600, 900, 0, 0 },
[297]44 { 1600, 1200, 0, 0 },
45 { 1920, 1080, 0, 0 },
[340]46 { 1920, 1200, 0, 0 },
[316]47 { 1920, 1440, 0, 0 },
[297]48};
[677]49//Just going to always use 32 bits for now...
50//short daodan_resdepths[] = { 16, 32 };
51short daodan_resdepths[] = { 32 };
[326]52DEVMODE orig_devmode, cur_devmode, new_devmode;
53
[692]54/* Never called
[326]55void init_daodan_gl()
56{
[342]57 DDrStartupMessage("initalizing daodan gl");
58
[326]59 memset(&orig_devmode, 0, sizeof(orig_devmode));
60 orig_devmode.dmSize = sizeof(orig_devmode);
61
62 if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &orig_devmode))
63 {
64 orig_devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
65 orig_devmode.dmBitsPerPel = 32;
66 orig_devmode.dmPelsWidth = GetSystemMetrics(SM_CXSCREEN);
67 orig_devmode.dmPelsHeight = GetSystemMetrics(SM_CYSCREEN);
68 }
69
70 memcpy(&cur_devmode, &orig_devmode, sizeof(orig_devmode));
71 memcpy(&new_devmode, &orig_devmode, sizeof(orig_devmode));
72}
[692]73*/
[326]74
75void update_cdmode()
76{
77 if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &cur_devmode))
78 {
79 cur_devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
80 cur_devmode.dmBitsPerPel = 32;
81 cur_devmode.dmPelsWidth = GetSystemMetrics(SM_CXSCREEN);
82 cur_devmode.dmPelsHeight = GetSystemMetrics(SM_CYSCREEN);
83 }
84}
85
[316]86unsigned int ONICALL daodan_enumerate_valid_display_modes(M3tDisplayMode modes[max_modes])
[297]87{
88 unsigned int vmodes = 0;
[677]89 unsigned int screen_x = GetSystemMetrics(SM_CXSCREEN);
90 unsigned int screen_y = GetSystemMetrics(SM_CYSCREEN);
[297]91
[677]92 uint16_t i, j;
[297]93
[342]94 DDrStartupMessage("listing display modes");
[677]95 /*
[341]96 if (!M3gResolutionSwitch)
97 daodan_resdepths[0] = orig_devmode.dmBitsPerPel;
[677]98 */
[316]99 for (i = 0; i < builtin_depths; i ++)
[297]100 {
[340]101 bool scrInsert = false;
102
[316]103 modes[vmodes].Width = 640;
104 modes[vmodes].Height = 480;
105 modes[vmodes].Depth = daodan_resdepths[i];
106
107 if (++vmodes == max_modes - builtin_modes + i)
108 goto modesfull;
109
110 for (j = 0; j < builtin_modes; j ++)
111 if (!(daodan_reslist[j].Width == 640 && daodan_reslist[j].Height == 480) && !(daodan_reslist[j].Width == screen_x && daodan_reslist[j].Height == screen_y) &&
[341]112 ((daodan_reslist[j].Width < screen_x && daodan_reslist[j].Height < screen_y) || (M3gResolutionSwitch && daodan_testmode(daodan_reslist[j]))))
[297]113 {
[340]114 if (!scrInsert && (daodan_reslist[j].Width > screen_x || (daodan_reslist[j].Width == screen_x && daodan_reslist[j].Height > screen_y)))
115 {
116 modes[vmodes].Width = screen_x;
117 modes[vmodes].Height = screen_y;
118 modes[vmodes].Depth = daodan_resdepths[i];
119
120 if (++vmodes == max_modes - builtin_modes + i)
121 goto modesfull;
122
123 scrInsert = true;
124 }
125
[297]126 modes[vmodes].Width = daodan_reslist[j].Width;
127 modes[vmodes].Height = daodan_reslist[j].Height;
[316]128 modes[vmodes].Depth = daodan_resdepths[i];
[297]129
[316]130 if (++vmodes == max_modes - builtin_modes + i)
[297]131 goto modesfull;
132 }
133
[340]134 if (!scrInsert)
135 {
136 modes[vmodes].Width = screen_x;
137 modes[vmodes].Height = screen_y;
138 modes[vmodes].Depth = daodan_resdepths[i];
139
140 if (++vmodes == max_modes - builtin_modes + i)
141 goto modesfull;
142 }
[341]143
144 if (!M3gResolutionSwitch)
145 goto modesfull;
[297]146 }
147
148 modesfull:
[342]149 DDrStartupMessage("%d modes available", vmodes);
[297]150 return vmodes;
151}
[316]152
153bool daodan_testmode(M3tDisplayMode mode)
154{
155 DEVMODE devmode;
156 memset(&devmode, 0, sizeof(devmode));
157
158 devmode.dmSize = sizeof(devmode);
159 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
160 devmode.dmBitsPerPel = mode.Depth;
161 devmode.dmPelsWidth = mode.Width;
162 devmode.dmPelsHeight = mode.Height;
163
[340]164 return (ChangeDisplaySettings(&devmode, CDS_TEST | CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);
[316]165}
[326]166
167int daodan_set_display_mode(short width, short height, short depth)
168{
169 if (M3gResolutionSwitch)
170 {
171 DEVMODE new_devmode;
172 new_devmode.dmSize = sizeof(new_devmode);
173 new_devmode.dmFields = DM_BITSPERPEL | DM_PELSHEIGHT | DM_PELSWIDTH;
174 new_devmode.dmPelsWidth = width;
175 new_devmode.dmPelsHeight = height;
176 new_devmode.dmBitsPerPel = depth;
177
178 if (ChangeDisplaySettings(&new_devmode, CDS_TEST) != DISP_CHANGE_SUCCESSFUL)
179 return 0;
180
181 if (ChangeDisplaySettings(&new_devmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
182 return 0;
183
184 update_cdmode();
[677]185 gl_eng->DisplayMode.Width = cur_devmode.dmPelsWidth;
186 gl_eng->DisplayMode.Height = cur_devmode.dmPelsHeight;
[689]187 if (cur_devmode.dmBitsPerPel > (unsigned short)depth)
[677]188 gl_eng->DisplayMode.Depth = cur_devmode.dmBitsPerPel;
[326]189 }
190 else
191 {
192 update_cdmode();
[689]193 if (cur_devmode.dmBitsPerPel > (unsigned short)depth)
[677]194 gl_eng->DisplayMode.Depth = cur_devmode.dmBitsPerPel;
[326]195 }
196 return 1;
197}
198int ONICALL daodangl_platform_initialize()
199{
200 static M3tDisplayMode lastmode = {0, 0, 0, 0};
201
[677]202 if (lastmode.Width != gl_eng->DisplayMode.Width || lastmode.Height != gl_eng->DisplayMode.Height || lastmode.Depth != gl_eng->DisplayMode.Depth)
203 if (!daodan_set_display_mode(gl_eng->DisplayMode.Width, gl_eng->DisplayMode.Height, gl_eng->DisplayMode.Depth))
204 if (gl_eng->DisplayMode.Width != 640 || gl_eng->DisplayMode.Height != 480 || gl_eng->DisplayMode.Depth != 16)
[326]205 {
[677]206 gl_eng->DisplayMode.Width = 640;
207 gl_eng->DisplayMode.Height = 480;
[326]208 if (!daodan_set_display_mode(640, 480, 16))
209 goto exit_err;
210 }
211
[677]212 if (lastmode.Width != gl_eng->DisplayMode.Width || lastmode.Height != gl_eng->DisplayMode.Height)
[326]213 {
214 RECT Rect;
[677]215 Rect.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (gl_eng->DisplayMode.Width / 2);
216 Rect.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (gl_eng->DisplayMode.Height / 2);
217 Rect.right = Rect.left + gl_eng->DisplayMode.Width;
218 Rect.bottom = Rect.top + gl_eng->DisplayMode.Height;
[476]219 AdjustWindowRect(&Rect, WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_CAPTION |WS_TILEDWINDOW , FALSE);
[326]220
221 SetWindowPos(ONgPlatformData.Window, NULL, Rect.left, Rect.top, Rect.right - Rect.left, Rect.bottom - Rect.top, SWP_NOACTIVATE | SWP_NOZORDER);
222 }
223
[677]224 if (gl_eng->HDC == NULL)
225 if ((gl_eng->HDC = GetDC(ONgPlatformData.Window)) == NULL)
[326]226 goto exit_err;
227
228 if (gl_api->wglGetDeviceGammaRamp3DFX != NULL)
229 {
230 DDrStartupMessage("Using 3DFX gamma adjustment");
231
[677]232 if (gl_api->wglGetDeviceGammaRamp3DFX(gl_eng->HDC, gl_gamma_ramp))
[326]233 gl_gamma_ramp_valid = 1;
234 }
235 else
236 {
237 DDrStartupMessage("Using standard Windows gamma adjustment");
238
[690]239//WINE CRASH! if (GetDeviceGammaRamp(gl_eng->HDC, gl_gamma_ramp))
[326]240 gl_gamma_ramp_valid = 1;
241 }
[691]242
[692]243 /*if (gl_gamma_ramp_valid)
[473]244 daodan_set_gamma(ONrPersist_GetGamma());
[692]245 else*/
[326]246 DDrStartupMessage("gamma adjustment not supported");
247
[677]248 if (!gl_platform_set_pixel_format(gl_eng->HDC))
249 if (gl_eng->DisplayMode.Depth != 16)
[326]250 {
[677]251 if (!daodan_set_display_mode(gl_eng->DisplayMode.Width, gl_eng->DisplayMode.Height, 16))
[326]252 goto exit_err;
253
[677]254 if (!gl_platform_set_pixel_format(gl_eng->HDC))
[326]255 goto exit_err;
256 }
257
[677]258 lastmode.Width = gl_eng->DisplayMode.Width;
259 lastmode.Height = gl_eng->DisplayMode.Height;
260 lastmode.Depth = gl_eng->DisplayMode.Depth;
[473]261 return 1;
[326]262
263exit_err:
264 AUrMessageBox(1, "Failed to initialize OpenGL contexts; Oni will now exit.");
265 exit(0);
[473]266 return 0;
[326]267}
Note: See TracBrowser for help on using the repository browser.