1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "arch.hh"
|
---|
10 | #include <ddraw.h>
|
---|
11 | #include <windows.h>
|
---|
12 | #include "dx5/r1_dx5.hh"
|
---|
13 |
|
---|
14 | i4_bool ddraw_check(HRESULT res);
|
---|
15 |
|
---|
16 | typedef struct
|
---|
17 | {
|
---|
18 | LPGUID lpGuid;
|
---|
19 | LPSTR lpDriverName;
|
---|
20 | } dd_device;
|
---|
21 |
|
---|
22 | dd_device dd_device_list[32];
|
---|
23 | sw32 num_dd_devices = 0;
|
---|
24 |
|
---|
25 | BOOL WINAPI dd_device_callback(LPGUID lpGuid, LPSTR lpDeviceDescription,
|
---|
26 | LPSTR lpDriverName, LPVOID lpUserArg)
|
---|
27 | {
|
---|
28 | //quit the enumeration if we've found everything
|
---|
29 | for (sw32 i=0;i<num_dd_devices;i++)
|
---|
30 | if (dd_device_list[i].lpGuid==lpGuid) return DDENUMRET_CANCEL;
|
---|
31 |
|
---|
32 | dd_device_list[num_dd_devices].lpGuid = lpGuid;
|
---|
33 | dd_device_list[num_dd_devices].lpDriverName = lpDriverName;
|
---|
34 | num_dd_devices++;
|
---|
35 |
|
---|
36 | if (num_dd_devices==31) return DDENUMRET_CANCEL;
|
---|
37 |
|
---|
38 | return DDENUMRET_OK;
|
---|
39 | }
|
---|
40 |
|
---|
41 | BOOL WINAPI dd_create_callback(LPGUID lpGuid, LPSTR lpDeviceDescription,
|
---|
42 | LPSTR lpDriverName, LPVOID lpUserArg)
|
---|
43 | {
|
---|
44 | char *desired_driver = (char *)lpUserArg;
|
---|
45 |
|
---|
46 | if (!stricmp(desired_driver,lpDriverName))
|
---|
47 | {
|
---|
48 | HRESULT res = DirectDrawCreate(lpGuid,i4_dx5_display->ddraw,0);
|
---|
49 | return DDENUMRET_CANCEL;
|
---|
50 | }
|
---|
51 |
|
---|
52 | return DDENUMRET_OK;
|
---|
53 | }
|
---|
54 |
|
---|
55 | i4_bool r1_dx5_class::init_ddraw(HWND main_hwnd)
|
---|
56 | {
|
---|
57 | HRESULT res;
|
---|
58 |
|
---|
59 | res = DirectDrawEnumerate(dd_device_callback,0);
|
---|
60 | if (res != DD_OK)
|
---|
61 | return i4_F;
|
---|
62 |
|
---|
63 | for (sw32 i=0;i<num_dd_devices;i++)
|
---|
64 | {
|
---|
65 | if (!stricmp(dd_device_list[i].lpDriverName,dd_driver_name)) break;
|
---|
66 | }
|
---|
67 | if (i==num_dd_devices) i=0;
|
---|
68 |
|
---|
69 | //create the direct draw object within the callback. GUID's are apparently not reliable outside
|
---|
70 | //of it??
|
---|
71 | DirectDrawEnumerate(dd_create_callback,(void *)dd_device_list[i].lpDriverName);
|
---|
72 |
|
---|
73 | //if it didnt get set, something fucked up
|
---|
74 | if (ddraw==0)
|
---|
75 | return i4_F;
|
---|
76 |
|
---|
77 | if (use_page_flip)
|
---|
78 | res = ddraw->SetCooperativeLevel(main_hwnd,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
|
---|
79 | else
|
---|
80 | res = ddraw->SetCooperativeLevel(main_hwnd,DDSCL_NORMAL);
|
---|
81 |
|
---|
82 | if (res != DD_OK) return i4_F;
|
---|
83 |
|
---|
84 | res = ddraw->QueryInterface(IID_IDirectDraw2,(void **)&ddraw2);
|
---|
85 | if(res != DD_OK) return i4_F;
|
---|
86 |
|
---|
87 | res = ddraw2->SetDisplayMode(640,480,16,0,0);
|
---|
88 | ddraw_check(res);
|
---|
89 | if (res != DD_OK) return i4_F;
|
---|
90 |
|
---|
91 | if (!create_ddraw_surfaces()) return i4_F;
|
---|
92 |
|
---|
93 | return i4_T;
|
---|
94 | }
|
---|
95 |
|
---|
96 | void r1_dx5_class::uninit_ddraw()
|
---|
97 | {
|
---|
98 | if (back_surface)
|
---|
99 | back_surface->Release();
|
---|
100 | if (primary_surface)
|
---|
101 | primary_surface->Release();
|
---|
102 | if (ddraw2)
|
---|
103 | ddraw2->Release();
|
---|
104 | if (ddraw)
|
---|
105 | ddraw->Release();
|
---|
106 | }
|
---|
107 |
|
---|
108 | i4_bool r1_dx5_class::create_ddraw_surfaces()
|
---|
109 | {
|
---|
110 | HRESULT res;
|
---|
111 | DDSURFACEDESC ddsd;
|
---|
112 |
|
---|
113 | if (use_page_flip)
|
---|
114 | {
|
---|
115 | //if we're page flipping, its a whole different ball game as far as creating the primary and secondary surfaces go
|
---|
116 | ZeroMemory(&ddsd, sizeof(ddsd));
|
---|
117 | ddsd.dwSize = sizeof(ddsd);
|
---|
118 | ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
|
---|
119 | ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
|
---|
120 | DDSCAPS_FLIP |
|
---|
121 | DDSCAPS_COMPLEX |
|
---|
122 | DDSCAPS_3DDEVICE |
|
---|
123 | DDSCAPS_VIDEOMEMORY;
|
---|
124 |
|
---|
125 | ddsd.dwBackBufferCount = 1;
|
---|
126 |
|
---|
127 | //get the primary surface
|
---|
128 | res = ddraw->CreateSurface(&ddsd, &primary_surface, NULL);
|
---|
129 | if (!ddraw_check(res))
|
---|
130 | return i4_F;
|
---|
131 |
|
---|
132 | // get the back buffer surface
|
---|
133 | DDSCAPS caps;
|
---|
134 | caps.dwCaps = DDSCAPS_BACKBUFFER;
|
---|
135 | res = primary_surface->GetAttachedSurface(&caps, &back_surface);
|
---|
136 | if (!ddraw_check(res))
|
---|
137 | return i4_F;
|
---|
138 | }
|
---|
139 | else
|
---|
140 | {
|
---|
141 |
|
---|
142 | //this will be non-page flipped (aka blitted)
|
---|
143 |
|
---|
144 | // Create the primary surface
|
---|
145 | memset(&ddsd,0,sizeof(DDSURFACEDESC));
|
---|
146 | ddsd.dwSize = sizeof(ddsd);
|
---|
147 | ddsd.dwFlags = DDSD_CAPS;
|
---|
148 | ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
---|
149 |
|
---|
150 |
|
---|
151 | res = ddraw2->CreateSurface(&ddsd,&primary_surface,0);
|
---|
152 | if (res != DD_OK) return i4_F;
|
---|
153 |
|
---|
154 | primary_surface->GetSurfaceDesc(&ddsd);
|
---|
155 |
|
---|
156 | ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
|
---|
157 | ddsd.dwWidth = 640;
|
---|
158 | ddsd.dwHeight = 480;
|
---|
159 | ddsd.ddsCaps.dwCaps = DDSCAPS_3DDEVICE;
|
---|
160 |
|
---|
161 | res = ddraw2->CreateSurface(&ddsd,&back_surface,0);
|
---|
162 | if (res != DD_OK) return i4_F;
|
---|
163 | }
|
---|
164 |
|
---|
165 | memset(&ddsd,0,sizeof(DDSURFACEDESC));
|
---|
166 | ddsd.dwSize = sizeof(DDSURFACEDESC);
|
---|
167 | primary_surface->GetSurfaceDesc(&ddsd);
|
---|
168 |
|
---|
169 | i4_pixel_format fmt;
|
---|
170 |
|
---|
171 | fmt.pixel_depth = I4_16BIT;
|
---|
172 | fmt.red_mask = ddsd.ddpfPixelFormat.dwRBitMask;
|
---|
173 | fmt.green_mask = ddsd.ddpfPixelFormat.dwGBitMask;
|
---|
174 | fmt.blue_mask = ddsd.ddpfPixelFormat.dwBBitMask;
|
---|
175 | fmt.calc_shift();
|
---|
176 |
|
---|
177 | screen_palette = i4_pal_man.register_pal(&fmt);
|
---|
178 |
|
---|
179 | return i4_T;
|
---|
180 | } |
---|