DXGL r749 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r748‎ | r749 | r750 >
Date:08:08, 5 October 2017
Author:admin
Status:new
Tags:
Comment:
Merge 2D and 3D graphics tests in DXGL Test. (currently interactive vertex/texture tests are broken)
Update copyright year in installer.
Modified paths:
  • /Installer/dxgl.nsi (modified) (history)
  • /dxgltest/Tests2D.cpp (deleted) (history)
  • /dxgltest/Tests3D.cpp (deleted) (history)
  • /dxgltest/dxgltest.cpp (modified) (history)
  • /dxgltest/dxgltest.vcxproj (modified) (history)
  • /dxgltest/dxgltest.vcxproj.filters (modified) (history)
  • /dxgltest/tests.cpp (added) (history)
  • /dxgltest/tests.h (modified) (history)

Diff [purge]

Index: dxgltest/Tests3D.cpp
——@@ -1,2242 +0,0 @@
2 -// DXGL
3 -// Copyright (C) 2012-2013 William Feely
4 -
5 -// This library is free software; you can redistribute it and/or
6 -// modify it under the terms of the GNU Lesser General Public
7 -// License as published by the Free Software Foundation; either
8 -// version 2.1 of the License, or (at your option) any later version.
9 -
10 -// This library is distributed in the hope that it will be useful,
11 -// but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 -// Lesser General Public License for more details.
14 -
15 -// You should have received a copy of the GNU Lesser General Public
16 -// License along with this library; if not, write to the Free Software
17 -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 -
19 -#include "common.h"
20 -#include "MultiDD.h"
21 -#include "tests.h"
22 -#include "surfacegen.h"
23 -#include "timer.h"
24 -#include "misc.h"
25 -#define D3D_OVERLOADS
26 -#include "../ddraw/include/d3d.h"
27 -
28 -void InitTest3D(int test);
29 -void RunTestTimed3D(int test);
30 -void RunTestLooped3D(int test);
31 -bool RunTestMouse3D(int test, UINT Msg, WPARAM wParam, LPARAM lParam);
32 -
33 -
34 -static MultiDirectDraw *ddinterface;
35 -static MultiDirectDrawSurface *ddsurface;
36 -static MultiDirectDrawSurface *ddsrender;
37 -static MultiDirectDrawSurface *zbuffer;
38 -static MultiDirectDrawSurface *textures[8];
39 -static IDirect3D7 *d3d7;
40 -static IDirect3DDevice7 *d3d7dev;
41 -D3DMATERIAL7 material;
42 -static LPDIRECTDRAWCLIPPER ddclipper;
43 -static int width,height,bpp,refresh,backbuffers;
44 -static double fps;
45 -static bool fullscreen,resizable;
46 -static HWND hWnd;
47 -static int testnum;
48 -static unsigned int randnum;
49 -static int testtypes[] = {0,0,0};
50 -
51 -#define FVF_COLORVERTEX (D3DFVF_VERTEX | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
52 -struct COLORVERTEX
53 -{
54 - D3DVALUE x;
55 - D3DVALUE y;
56 - D3DVALUE z;
57 - D3DVALUE nx;
58 - D3DVALUE ny;
59 - D3DVALUE nz;
60 - D3DCOLOR color;
61 - D3DCOLOR specular;
62 - D3DVALUE tu;
63 - D3DVALUE tv;
64 -public:
65 - COLORVERTEX() {};
66 - COLORVERTEX(const D3DVECTOR& v, const D3DVECTOR& n, D3DCOLOR _color,
67 - D3DCOLOR _specular, D3DVALUE _tu, D3DVALUE _tv)
68 - {
69 - x = v.x; y = v.y; z = v.z;
70 - nx = n.x; ny = n.y; nz = n.z;
71 - color = _color; specular = _specular;
72 - tu = _tu; tv = _tv;
73 - }
74 -
75 -};
76 -
77 -static int numpoints = 0;
78 -static int numindices = 0;
79 -static D3DVERTEX *vertices = NULL;
80 -static D3DLVERTEX *litvertices = NULL;
81 -static COLORVERTEX *colorvertices = NULL;
82 -static WORD *mesh = NULL;
83 -static D3DLIGHT7 lights[8];
84 -static BOOL lightenable[8];
85 -static DWORD bgcolor = 0;
86 -
87 -typedef struct
88 -{
89 - DWORD ambient;
90 - DWORD diffuse;
91 - DWORD specular;
92 -} HEXLIGHTCOLOR;
93 -HEXLIGHTCOLOR hexlightcolor[8];
94 -
95 -typedef struct
96 -{
97 - D3DTEXTUREOP colorop;
98 - DWORD colorarg1;
99 - DWORD colorarg2;
100 - D3DTEXTUREOP alphaop;
101 - DWORD alphaarg1;
102 - DWORD alphaarg2;
103 - DWORD texturetype;
104 - TCHAR texturefile[MAX_PATH+1];
105 - MultiDirectDrawSurface* texture;
106 - BOOL colorkey;
107 - DWORD keycolor;
108 -} TEXSTAGE;
109 -
110 -typedef struct
111 -{
112 - int currentstage;
113 - TEXSTAGE texstages[8];
114 - DWORD diffuse;
115 - DWORD specular;
116 - DWORD factor;
117 - D3DFOGMODE vertexfog;
118 - D3DFOGMODE pixelfog;
119 - FLOAT fogstart;
120 - FLOAT fogend;
121 - FLOAT fogdensity;
122 - BOOL rangefog;
123 - DWORD fogcolor;
124 - BOOL alphatest;
125 - BOOL alphastipple;
126 - BOOL colorkey;
127 - BOOL colorkeyblend;
128 - D3DBLEND srcblend;
129 - D3DBLEND destblend;
130 - BYTE refalpha;
131 - D3DCMPFUNC alphafunc;
132 - D3DLINEPATTERN linepattern;
133 - DWORD fillstippletype;
134 - TCHAR fillstipplefile[MAX_PATH+1];
135 - DWORD fillstipple[32];
136 -} TEXSHADERSTATE;
137 -
138 -static TEXSHADERSTATE texshaderstate;
139 -const TEXSHADERSTATE defaulttexshaderstate =
140 -{
141 - 0,
142 - {
143 - {D3DTOP_MODULATE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_SELECTARG1,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0},
144 - {D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0},
145 - {D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0},
146 - {D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0},
147 - {D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0},
148 - {D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0},
149 - {D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0},
150 - {D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0},
151 - },
152 - 0xFFFFFFFF,
153 - 0,
154 - 0xFFFFFFFF,
155 - D3DFOG_NONE,
156 - D3DFOG_NONE,
157 - 0.0,
158 - 1.0,
159 - 1.0,
160 - FALSE,
161 - 0,
162 - FALSE,
163 - FALSE,
164 - FALSE,
165 - FALSE,
166 - D3DBLEND_ONE,
167 - D3DBLEND_ZERO,
168 - 0,
169 - D3DCMP_ALWAYS,
170 - {0,0}
171 -};
172 -
173 -typedef struct
174 -{
175 - DWORD texturetype;
176 - TCHAR texturefile[MAX_PATH+1];
177 - MultiDirectDrawSurface* texture;
178 - int currentlight;
179 -} VERTEXSHADERSTATE;
180 -static VERTEXSHADERSTATE vertexshaderstate;
181 -
182 -
183 -LRESULT CALLBACK D3DWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
184 -{
185 - bool paintwnd = true;
186 - POINT p;
187 - RECT srcrect,destrect;
188 - HRESULT error;
189 - PAINTSTRUCT paintstruct;
190 - switch(Msg)
191 - {
192 - case WM_CLOSE:
193 - DestroyWindow(hWnd);
194 - break;
195 - case WM_DESTROY:
196 - StopTimer();
197 - Sleep(100);
198 - for(int i = 0; i < 8; i++)
199 - {
200 - if(textures[i])
201 - {
202 - textures[i]->Release();
203 - textures[i] = NULL;
204 - }
205 - }
206 - if(d3d7dev)
207 - {
208 - d3d7dev->Release();
209 - d3d7dev = NULL;
210 - }
211 - if(d3d7)
212 - {
213 - d3d7->Release();
214 - d3d7dev = NULL;
215 - }
216 - if(ddsrender)
217 - {
218 - ddsrender->Release();
219 - ddsrender = NULL;
220 - }
221 - if(ddsurface)
222 - {
223 - ddsurface->Release();
224 - ddsurface = NULL;
225 - }
226 - if(zbuffer)
227 - {
228 - zbuffer->Release();
229 - zbuffer = NULL;
230 - }
231 - if(ddclipper)
232 - {
233 - ddclipper->Release();
234 - ddclipper = NULL;
235 - }
236 - if(ddinterface)
237 - {
238 - ddinterface->Release();
239 - ddinterface = NULL;
240 - }
241 - if(mesh)
242 - {
243 - free(mesh);
244 - mesh = NULL;
245 - }
246 - if(vertices)
247 - {
248 - free(vertices);
249 - vertices = NULL;
250 - }
251 - if(litvertices)
252 - {
253 - free(litvertices);
254 - litvertices = NULL;
255 - }
256 - if(colorvertices)
257 - {
258 - free(colorvertices);
259 - colorvertices = NULL;
260 - }
261 - PostQuitMessage(0);
262 - break;
263 - case WM_KEYDOWN:
264 - if(wParam == VK_ESCAPE) DestroyWindow(hWnd);
265 - break;
266 - case WM_APP:
267 - RunTestTimed3D(testnum);
268 - break;
269 - case WM_SIZE:
270 - paintwnd = false;
271 - case WM_PAINT:
272 - if(paintwnd) BeginPaint(hWnd,&paintstruct);
273 - if(!fullscreen)
274 - {
275 - p.x = 0;
276 - p.y = 0;
277 - ClientToScreen(hWnd,&p);
278 - GetClientRect(hWnd,&destrect);
279 - OffsetRect(&destrect,p.x,p.y);
280 - SetRect(&srcrect,0,0,width,height);
281 - if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
282 - }
283 - if(paintwnd) EndPaint(hWnd,&paintstruct);
284 - return 0;
285 - case WM_MOUSEMOVE:
286 - case WM_LBUTTONDOWN:
287 - case WM_LBUTTONUP:
288 - case WM_LBUTTONDBLCLK:
289 - case WM_RBUTTONDOWN:
290 - case WM_RBUTTONUP:
291 - case WM_RBUTTONDBLCLK:
292 - case WM_MBUTTONDOWN:
293 - case WM_MBUTTONUP:
294 - case WM_MBUTTONDBLCLK:
295 - case WM_MOUSEWHEEL:
296 - case WM_XBUTTONDOWN:
297 - case WM_XBUTTONUP:
298 - case WM_XBUTTONDBLCLK:
299 - case WM_MOUSEHWHEEL:
300 - if(RunTestMouse3D(testnum,Msg,wParam,lParam))
301 - {
302 - if(!fullscreen)
303 - {
304 - p.x = 0;
305 - p.y = 0;
306 - ClientToScreen(hWnd,&p);
307 - GetClientRect(hWnd,&destrect);
308 - OffsetRect(&destrect,p.x,p.y);
309 - SetRect(&srcrect,0,0,width,height);
310 - if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
311 - }
312 - }
313 - break;
314 - default:
315 - return DefWindowProc(hWnd,Msg,wParam,lParam);
316 - }
317 - return FALSE;
318 -}
319 -
320 -static int d3dtestnum;
321 -static int d3dver;
322 -static int ddver;
323 -
324 -bool RunTestMouse3D(int test, UINT Msg, WPARAM wParam, LPARAM lParam)
325 -{
326 - return false;
327 -}
328 -
329 -const TCHAR wndclassname3d[] = _T("D3DTestWndClass");
330 -
331 -static HRESULT WINAPI zcallback(DDPIXELFORMAT *ddpf, VOID *context)
332 -{
333 - if(ddpf->dwFlags == DDPF_ZBUFFER)
334 - {
335 - memcpy(context,ddpf,sizeof(DDPIXELFORMAT));
336 - return D3DENUMRET_CANCEL;
337 - }
338 - return D3DENUMRET_OK;
339 -}
340 -
341 -INT_PTR CALLBACK TexShader7Proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
342 -INT_PTR CALLBACK VertexShader7Proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
343 -
344 -void RunTest3D(int testnum, int width, int height, int bpp, int refresh, int backbuffers, int apiver,
345 - int filter, int msaa, double fps, bool fullscreen, bool resizable)
346 -{
347 - if(testnum == 2)
348 - {
349 - DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_TEXSHADER),NULL,TexShader7Proc);
350 - return;
351 - }
352 - if(testnum == 3)
353 - {
354 - DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_VERTEXSHADER),NULL,VertexShader7Proc);
355 - return;
356 - }
357 - DDSCAPS2 caps;
358 - DDSURFACEDESC2 ddsd;
359 - DDPIXELFORMAT ddpfz;
360 - BOOL done = false;
361 - ::testnum = testnum;
362 - randnum = (unsigned int)time(NULL);
363 - ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
364 - ZeroMemory(textures,8*sizeof(MultiDirectDrawSurface*));
365 - if(apiver >= 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
366 - else ddsd.dwSize = sizeof(DDSURFACEDESC);
367 - ::fullscreen = fullscreen;
368 - ::resizable = resizable;
369 - ::width = width;
370 - ::height = height;
371 - ::bpp = bpp;
372 - ::refresh = refresh;
373 - if(fullscreen)::backbuffers = backbuffers;
374 - else ::backbuffers = backbuffers = 0;
375 - ::fps = fps;
376 - d3dtestnum = testnum;
377 - d3dver = apiver;
378 - if(apiver == 3) ddver = 4;
379 - else ddver = apiver;
380 - HINSTANCE hinstance = (HINSTANCE)GetModuleHandle(NULL);
381 - WNDCLASSEX wc;
382 - MSG Msg;
383 - ZeroMemory(&wc,sizeof(WNDCLASS));
384 - wc.cbSize = sizeof(WNDCLASSEX);
385 - wc.style = CS_HREDRAW | CS_VREDRAW;
386 - wc.lpfnWndProc = D3DWndProc;
387 - wc.hInstance = hinstance;
388 - wc.hIcon = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_DXGL));
389 - wc.hIconSm = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_DXGLSM));
390 - if(testnum == 6) wc.hCursor = LoadCursor(NULL,IDC_CROSS);
391 - else wc.hCursor = LoadCursor(NULL,IDC_ARROW);
392 - wc.hbrBackground = NULL;
393 - wc.lpszClassName = wndclassname3d;
394 - if(!RegisterClassEx(&wc))
395 - {
396 - MessageBox(NULL,_T("Can not register window class"),_T("Error"),MB_ICONEXCLAMATION|MB_OK);
397 - return;
398 - }
399 - if(resizable)
400 - hWnd = CreateWindowEx(WS_EX_APPWINDOW,wndclassname3d,_T("D3D Test Window"),WS_OVERLAPPEDWINDOW,
401 - CW_USEDEFAULT,CW_USEDEFAULT,width,height,NULL,NULL,hinstance,NULL);
402 - else if(!fullscreen)
403 - hWnd = CreateWindowEx(WS_EX_APPWINDOW,wndclassname3d,_T("D3D Test Window"),WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
404 - CW_USEDEFAULT,CW_USEDEFAULT,width,height,NULL,NULL,hinstance,NULL);
405 - else hWnd = CreateWindowEx(0,wndclassname3d,_T("DDraw Test Window"),WS_POPUP,0,0,
406 - GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hinstance,NULL);
407 - DWORD err = GetLastError();
408 - ShowWindow(hWnd,SW_SHOWNORMAL);
409 - UpdateWindow(hWnd);
410 - RECT r1,r2;
411 - POINT p1;
412 - HRESULT error;
413 - ddinterface = new MultiDirectDraw(ddver,&error,NULL);
414 - if(fullscreen) error = ddinterface->SetCooperativeLevel(hWnd,DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN);
415 - else error = ddinterface->SetCooperativeLevel(hWnd,DDSCL_NORMAL);
416 - if(fullscreen) error = ddinterface->SetDisplayMode(width,height,bpp,refresh,0);
417 - else
418 - {
419 - GetClientRect(hWnd,&r1);
420 - GetWindowRect(hWnd,&r2);
421 - p1.x = (r2.right - r2.left) - r1.right;
422 - p1.y = (r2.bottom - r2.top) - r1.bottom;
423 - MoveWindow(hWnd,r2.left,r2.top,width+p1.x,height+p1.y,TRUE);
424 - }
425 - ddsd.dwFlags = DDSD_CAPS;
426 - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
427 - if(fullscreen)
428 - {
429 - if(backbuffers)ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
430 - ddsd.dwBackBufferCount = backbuffers;
431 - if(backbuffers) ddsd.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
432 - ddsd.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
433 - }
434 - error = ddinterface->CreateSurface(&ddsd,&ddsurface,NULL);
435 - if(!fullscreen)
436 - {
437 - error = ddinterface->CreateClipper(0,&ddclipper,NULL);
438 - error = ddclipper->SetHWnd(0,hWnd);
439 - error = ddsurface->SetClipper(ddclipper);
440 - ZeroMemory(&ddsd,sizeof(ddsd));
441 - if(apiver > 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
442 - else ddsd.dwSize = sizeof(DDSURFACEDESC);
443 - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
444 - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE;
445 - ddsd.dwWidth = width;
446 - ddsd.dwHeight = height;
447 - error = ddinterface->CreateSurface(&ddsd,&ddsrender,NULL);
448 - }
449 - else
450 - {
451 - if(backbuffers)
452 - {
453 - ZeroMemory(&caps,sizeof(DDSCAPS2));
454 - caps.dwCaps = DDSCAPS_BACKBUFFER;
455 - error = ddsurface->GetAttachedSurface(&caps,&ddsrender);
456 - }
457 - else
458 - {
459 - ddsrender = ddsurface;
460 - ddsrender->AddRef();
461 - }
462 - }
463 - error = ddinterface->QueryInterface(IID_IDirect3D7,(VOID**)&d3d7);
464 - error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice,zcallback,&ddpfz);
465 - error = ddsrender->GetSurfaceDesc(&ddsd);
466 - ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
467 - ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER|DDSCAPS_VIDEOMEMORY;
468 - memcpy(&ddsd.ddpfPixelFormat,&ddpfz,sizeof(DDPIXELFORMAT));
469 - error = ddinterface->CreateSurface(&ddsd,&zbuffer,NULL);
470 - error = ddsrender->AddAttachedSurface(zbuffer);
471 - error = d3d7->CreateDevice(IID_IDirect3DHALDevice,(LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(),&d3d7dev);
472 - if(error != D3D_OK)
473 - error = d3d7->CreateDevice(IID_IDirect3DRGBDevice,(LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(),&d3d7dev);
474 - ddsrender->GetSurfaceDesc(&ddsd);
475 - D3DVIEWPORT7 vp = {0,0,ddsd.dwWidth,ddsd.dwHeight,0.0f,1.0f};
476 - error = d3d7dev->SetViewport(&vp);
477 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_ZENABLE,TRUE);
478 - InitTest3D(testnum);
479 - if(!fullscreen) SendMessage(hWnd,WM_PAINT,0,0);
480 - if(testtypes[testnum] == 1)
481 - {
482 - while(!done)
483 - {
484 - if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
485 - {
486 - if(Msg.message == WM_PAINT) RunTestLooped3D(testnum);
487 - else if(Msg.message == WM_QUIT) done = TRUE;
488 - else
489 - {
490 - TranslateMessage(&Msg);
491 - DispatchMessage(&Msg);
492 - }
493 - }
494 - else
495 - {
496 - RunTestLooped3D(testnum);
497 - }
498 - }
499 - }
500 - else if(testtypes[testnum] == 0)
501 - {
502 - StartTimer(hWnd,WM_APP,fps);
503 - while(GetMessage(&Msg, NULL, 0, 0) > 0)
504 - {
505 - TranslateMessage(&Msg);
506 - DispatchMessage(&Msg);
507 - }
508 - }
509 - else
510 - {
511 - while(GetMessage(&Msg, NULL, 0, 0) > 0)
512 - {
513 - TranslateMessage(&Msg);
514 - DispatchMessage(&Msg);
515 - }
516 - }
517 - UnregisterClass(wndclassname3d,hinstance);
518 - StopTimer();
519 -}
520 -
521 -void MakeCube3D(float size, int detail)
522 -{
523 - if(detail < 2) return;
524 - D3DVECTOR normals[6];
525 - normals[0] = D3DVECTOR(0.0f,0.0f,-1.0f);
526 - normals[1] = D3DVECTOR(1.0f,0.0f,0.0f);
527 - normals[2] = D3DVECTOR(0.0f,0.0f,1.0f);
528 - normals[3] = D3DVECTOR(-1.0f,0.0f,0.0f);
529 - normals[4] = D3DVECTOR(0.0f,1.0f,0.0f);
530 - normals[5] = D3DVECTOR(0.0f,-1.0f,0.0f);
531 - int numfacevertices = detail*detail;
532 - D3DVECTOR *face = (D3DVECTOR*)malloc(numfacevertices*sizeof(D3DVECTOR));
533 - int numfaceindices = ((detail-1)*(detail-1))*6;
534 - WORD *faceindex = (WORD*)malloc(numfaceindices*sizeof(WORD));
535 - int ptr = 0;
536 - float fx,fy;
537 - // Generate points
538 - for(int y = 0; y < detail; y++)
539 - {
540 - fy = (((float)(y / (float)(detail-1)))-.5f)*size;
541 - for(int x = 0; x < detail; x++)
542 - {
543 - fx = (((float)(x / (float)(detail-1)))-.5f)*size;
544 - face[ptr] = D3DVECTOR(fx,fy,0);
545 - ptr++;
546 - }
547 - }
548 - // Generate triangle indices
549 - ptr = 0;
550 - for(int y = 0; y < (detail-1); y++)
551 - {
552 - for(int x = 0; x < (detail-1); x++)
553 - {
554 - faceindex[ptr++] = x + (detail*y);
555 - faceindex[ptr++] = x + (detail*(y+1));
556 - faceindex[ptr++] = (x+1) + (detail*y);
557 - faceindex[ptr++] = (x+1) + (detail*y);
558 - faceindex[ptr++] = x + (detail*(y+1));
559 - faceindex[ptr++] = (x+1) + (detail*(y+1));
560 - }
561 - }
562 - numpoints = (detail*detail)*6;
563 - numindices = ((detail-1)*(detail-1))*36;
564 - if(vertices) free(vertices);
565 - if(litvertices) free(litvertices);
566 - if(colorvertices) free(colorvertices);
567 - if(mesh) free(mesh);
568 - vertices = (D3DVERTEX*)malloc(numpoints*sizeof(D3DVERTEX));
569 - litvertices = (D3DLVERTEX*)malloc(numpoints*sizeof(D3DLVERTEX));
570 - colorvertices = (COLORVERTEX*)malloc(numpoints*sizeof(COLORVERTEX));
571 - mesh = (WORD*)malloc(numindices*sizeof(WORD));
572 - // Generate vertex list
573 - float u,v;
574 - D3DVECTOR pos;
575 - D3DVECTOR normal;
576 - // Front face
577 - ptr = 0;
578 - for(int y = 0; y < detail; y++)
579 - {
580 - for(int x = 0; x < detail; x++)
581 - {
582 - u = (float)x/(float)(detail-1);
583 - v = 1.f-((float)y/(float)(detail-1));
584 - ptr = x+(detail*y);
585 - pos = D3DVECTOR(face[ptr].x,face[ptr].y,-size/2.f);
586 - normal = D3DVECTOR(0,0,-1);
587 - vertices[ptr] = D3DVERTEX(pos,normal,u,v);
588 - litvertices[ptr] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
589 - colorvertices[ptr] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
590 - }
591 - }
592 - // Right face
593 - ptr = 0;
594 - for(int y = 0; y < detail; y++)
595 - {
596 - for(int x = 0; x < detail; x++)
597 - {
598 - u = (float)x/(float)(detail-1);
599 - v = 1.f-((float)y/(float)(detail-1));
600 - ptr = x+(detail*y);
601 - pos = D3DVECTOR(size/2.f,face[ptr].y,face[ptr].x);
602 - normal = D3DVECTOR(1,0,0);
603 - vertices[ptr+numfacevertices] = D3DVERTEX(pos,normal,u,v);
604 - litvertices[ptr+numfacevertices] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
605 - colorvertices[ptr+numfacevertices] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
606 - }
607 - }
608 - // Back face
609 - ptr = 0;
610 - for(int y = 0; y < detail; y++)
611 - {
612 - for(int x = 0; x < detail; x++)
613 - {
614 - u = (float)x/(float)(detail-1);
615 - v = 1.f-((float)y/(float)(detail-1));
616 - ptr = x+(detail*y);
617 - pos = D3DVECTOR(-face[ptr].x,face[ptr].y,size/2.f);
618 - normal = D3DVECTOR(0,0,1);
619 - vertices[ptr+(numfacevertices*2)] = D3DVERTEX(pos,normal,u,v);
620 - litvertices[ptr+(numfacevertices*2)] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
621 - colorvertices[ptr+(numfacevertices*2)] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
622 - }
623 - }
624 - // Left face
625 - ptr = 0;
626 - for(int y = 0; y < detail; y++)
627 - {
628 - for(int x = 0; x < detail; x++)
629 - {
630 - u = (float)x/(float)(detail-1);
631 - v = 1.f-((float)y/(float)(detail-1));
632 - ptr = x+(detail*y);
633 - pos = D3DVECTOR(-size/2.f,face[ptr].y,-face[ptr].x);
634 - normal = D3DVECTOR(-1,0,0);
635 - vertices[ptr+(numfacevertices*3)] = D3DVERTEX(pos,normal,u,v);
636 - litvertices[ptr+(numfacevertices*3)] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
637 - colorvertices[ptr+(numfacevertices*3)] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
638 - }
639 - }
640 - // Top face
641 - for(int y = 0; y < detail; y++)
642 - {
643 - for(int x = 0; x < detail; x++)
644 - {
645 - u = (float)x/(float)(detail-1);
646 - v = 1.f-((float)y/(float)(detail-1));
647 - ptr = x+(detail*y);
648 - pos = D3DVECTOR(face[ptr].x,size/2.f,face[ptr].y);
649 - normal = D3DVECTOR(0,1,0);
650 - vertices[ptr+(numfacevertices*4)] = D3DVERTEX(pos,normal,u,v);
651 - litvertices[ptr+(numfacevertices*4)] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
652 - colorvertices[ptr+(numfacevertices*4)] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
653 - }
654 - }
655 - // Bottom face
656 - for(int y = 0; y < detail; y++)
657 - {
658 - for(int x = 0; x < detail; x++)
659 - {
660 - u = (float)x/(float)(detail-1);
661 - v = 1.f-((float)y/(float)(detail-1));
662 - ptr = x+(detail*y);
663 - pos = D3DVECTOR(face[ptr].x,-size/2.f,-face[ptr].y);
664 - normal = D3DVECTOR(0,-1,0);
665 - vertices[ptr+(numfacevertices*5)] = D3DVERTEX(pos,normal,u,v);
666 - litvertices[ptr+(numfacevertices*5)] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
667 - colorvertices[ptr+(numfacevertices*5)] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
668 - }
669 - }
670 - free(face);
671 - // Generate index table
672 - ptr = 0;
673 - for(int i = 0; i < 6; i++)
674 - {
675 - for(int j = 0; j < numfaceindices; j++)
676 - mesh[ptr++] = faceindex[j]+(i*numfacevertices);
677 - }
678 - free(faceindex);
679 -}
680 -
681 -void SetVertexColor(D3DLVERTEX *start, COLORVERTEX *start_color, int count, DWORD color)
682 -{
683 - for(int i = 0; i < count; i++)
684 - {
685 - start[i].color = color;
686 - start_color[i].color = color;
687 - }
688 -}
689 -
690 -void SetVertexSpecular(D3DLVERTEX *start, COLORVERTEX *start_color, int count, DWORD color)
691 -{
692 - for(int i = 0; i < count; i++)
693 - {
694 - start[i].specular = color;
695 - start_color[i].specular = color;
696 - }
697 -}
698 -
699 -
700 -DDPIXELFORMAT texformats[256];
701 -int texformatindex = 0;
702 -
703 -void cleartexformats()
704 -{
705 - ZeroMemory(texformats,256*sizeof(DDPIXELFORMAT));
706 - texformatindex = 0;
707 -}
708 -
709 -HRESULT CALLBACK gettexformat(LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext)
710 -{
711 - memcpy(&texformats[texformatindex],lpDDPixFmt,sizeof(DDPIXELFORMAT));
712 - texformatindex++;
713 - if(texformatindex >= 256) return D3DENUMRET_CANCEL;
714 - return D3DENUMRET_OK;
715 -}
716 -
717 -static bool gentexture(const DDPIXELFORMAT format, MultiDirectDrawSurface **surface, int width, int height, int pattern)
718 -{
719 - DDSURFACEDESC2 ddsd;
720 - ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
721 - ddsd.dwSize = sizeof(DDSURFACEDESC2);
722 - ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_TEXTURESTAGE;
723 - ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
724 - ddsd.dwWidth = width;
725 - ddsd.dwHeight = height;
726 - ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
727 - ddsd.ddpfPixelFormat = format;
728 - HRESULT error = ddinterface->CreateSurface(&ddsd,surface,NULL);
729 - if(error != D3D_OK) return false;
730 - switch(pattern)
731 - {
732 - case 0:
733 - default:
734 - (*surface)->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
735 - DrawPalette(ddsd,(unsigned char *)ddsd.lpSurface);
736 - (*surface)->Unlock(NULL);
737 - }
738 - return true;
739 -}
740 -
741 -void MakeLights()
742 -{
743 - for(int i = 0; i < 8; i++)
744 - {
745 - lightenable[i] = FALSE;
746 - ZeroMemory(&lights[i],sizeof(D3DLIGHT7));
747 - lights[i].dcvDiffuse.r = lights[i].dcvDiffuse.g = lights[i].dcvDiffuse.b = 1;
748 - lights[i].dltType = D3DLIGHT_DIRECTIONAL;
749 - hexlightcolor[i].diffuse = 0xFFFFFF;
750 - }
751 - lightenable[0] = TRUE;
752 - lights[0].dvPosition = D3DVECTOR(-10,-10,-10);
753 - lights[1].dvPosition = D3DVECTOR(10,-10,-10);
754 - lights[2].dvPosition = D3DVECTOR(-10,10,-10);
755 - lights[3].dvPosition = D3DVECTOR(10,10,-10);
756 - lights[4].dvPosition = D3DVECTOR(-10,-10,10);
757 - lights[5].dvPosition = D3DVECTOR(10,-10,10);
758 - lights[6].dvPosition = D3DVECTOR(-10,10,10);
759 - lights[7].dvPosition = D3DVECTOR(10,10,10);
760 - lights[0].dvDirection = D3DVECTOR(1,1,1);
761 - lights[1].dvDirection = D3DVECTOR(-1,1,1);
762 - lights[2].dvDirection = D3DVECTOR(1,-1,1);
763 - lights[3].dvDirection = D3DVECTOR(-1,-1,1);
764 - lights[4].dvDirection = D3DVECTOR(1,1,-1);
765 - lights[5].dvDirection = D3DVECTOR(-1,1,-1);
766 - lights[6].dvDirection = D3DVECTOR(1,-1,-1);
767 - lights[7].dvDirection = D3DVECTOR(-1,-1,-1);
768 -}
769 -
770 -static const DDPIXELFORMAT fmt_rgba4444 = {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,16,0xF00,0xF0,0xF,0xF000};
771 -static const DDPIXELFORMAT fmt_rgba1555 = {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,16,0x7C00,0x3E0,0x1F,0x8000};
772 -static const DDPIXELFORMAT fmt_rgb565 = {sizeof(DDPIXELFORMAT),DDPF_RGB,0,16,0xF800,0x7E0,0x1F,0};
773 -static const DDPIXELFORMAT fmt_rgba8888 = {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,32,0xFF0000,0xFF00,0xFF,0xFF000000};
774 -
775 -void InitTest3D(int test)
776 -{
777 - HRESULT error;
778 - D3DMATRIX matWorld;
779 - D3DMATRIX matView;
780 - D3DMATRIX matProj;
781 - D3DMATRIX mat;
782 - bgcolor = 0;
783 - switch(test)
784 - {
785 - case 0:
786 - MakeCube3D(5,2);
787 - ZeroMemory(&material,sizeof(D3DMATERIAL7));
788 - material.ambient.r = 0.5f;
789 - material.ambient.g = 0.5f;
790 - material.ambient.b = 0.0f;
791 - material.diffuse.r = 1.0f;
792 - material.diffuse.g = 1.0f;
793 - material.diffuse.b = 1.0f;
794 - error = d3d7dev->SetMaterial(&material);
795 - error = d3d7dev->LightEnable(0,TRUE);
796 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);
797 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0x7f7f7f7f);
798 - mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
799 - mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
800 - mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
801 - mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
802 - matWorld = mat;
803 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD,&matWorld);
804 - matView = mat;
805 - matView._43 = 10.0f;
806 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_VIEW,&matView);
807 - matProj = mat;
808 - matProj._11 = 2.0f;
809 - matProj._22 = 2.0f;
810 - matProj._34 = 1.0f;
811 - matProj._43 = -1.0f;
812 - matProj._44 = 0.0f;
813 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION,&matProj);
814 - ZeroMemory(&lights[0],sizeof(D3DLIGHT7));
815 - lights[0].dltType = D3DLIGHT_DIRECTIONAL;
816 - lights[0].dcvDiffuse.r = 1;
817 - lights[0].dcvDiffuse.g = 0;
818 - lights[0].dcvDiffuse.b = 1;
819 - lights[0].dvDirection = D3DVECTOR(5,5,5);
820 - lights[0].dvRange = D3DLIGHT_RANGE_MAX;
821 - lights[0].dvAttenuation1 = 0.4f;
822 - error = d3d7dev->SetLight(0,&lights[0]);
823 - break;
824 - case 1:
825 - MakeCube3D(5,2);
826 - cleartexformats();
827 - d3d7dev->EnumTextureFormats(gettexformat,NULL);
828 - gentexture(fmt_rgba4444,&textures[0],256,256,0);
829 - gentexture(fmt_rgba1555,&textures[1],256,256,0);
830 - gentexture(fmt_rgb565,&textures[2],256,256,0);
831 - gentexture(fmt_rgba8888,&textures[3],256,256,0);
832 - ZeroMemory(&material,sizeof(D3DMATERIAL7));
833 - material.ambient.r = 1.0f;
834 - material.ambient.g = 1.0f;
835 - material.ambient.b = 1.0f;
836 - material.diffuse.r = 1.0f;
837 - material.diffuse.g = 1.0f;
838 - material.diffuse.b = 1.0f;
839 - error = d3d7dev->SetMaterial(&material);
840 - error = d3d7dev->LightEnable(0,TRUE);
841 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);
842 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0xFFFFFFFF);
843 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_CULLMODE,D3DCULL_CW);
844 - mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
845 - mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
846 - mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
847 - mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
848 - matWorld = mat;
849 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD,&matWorld);
850 - matView = mat;
851 - matView._43 = 10.0f;
852 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_VIEW,&matView);
853 - matProj = mat;
854 - matProj._11 = 2.0f;
855 - matProj._22 = 2.0f;
856 - matProj._34 = 1.0f;
857 - matProj._43 = -1.0f;
858 - matProj._44 = 0.0f;
859 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION,&matProj);
860 - ZeroMemory(&lights[0],sizeof(D3DLIGHT7));
861 - lights[0].dltType = D3DLIGHT_DIRECTIONAL;
862 - lights[0].dcvDiffuse.r = 1;
863 - lights[0].dcvDiffuse.g = 0;
864 - lights[0].dcvDiffuse.b = 1;
865 - lights[0].dvDirection = D3DVECTOR(5,5,5);
866 - lights[0].dvRange = D3DLIGHT_RANGE_MAX;
867 - lights[0].dvAttenuation1 = 0.4f;
868 - error = d3d7dev->SetLight(0,&lights[0]);
869 - break;
870 - case 3:
871 - ZeroMemory(lights,8*sizeof(D3DLIGHT7));
872 - MakeLights();
873 - case 2:
874 - MakeCube3D(5,8);
875 - ZeroMemory(&material,sizeof(D3DMATERIAL7));
876 - material.ambient.r = 1.0f;
877 - material.ambient.g = 1.0f;
878 - material.ambient.b = 1.0f;
879 - material.ambient.a = 1.0f;
880 - material.diffuse.r = 1.0f;
881 - material.diffuse.g = 1.0f;
882 - material.diffuse.b = 1.0f;
883 - material.diffuse.a = 1.0f;
884 - error = d3d7dev->SetMaterial(&material);
885 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
886 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0xffffffff);
887 - mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
888 - mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
889 - mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
890 - mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
891 - matWorld = mat;
892 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD,&matWorld);
893 - matView = mat;
894 - matView._43 = 10.0f;
895 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_VIEW,&matView);
896 - matProj = mat;
897 - matProj._11 = 2.0f;
898 - matProj._22 = 2.0f;
899 - matProj._34 = 1.0f;
900 - matProj._43 = -1.0f;
901 - matProj._44 = 0.0f;
902 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION,&matProj);
903 - texshaderstate = defaulttexshaderstate;
904 - break;
905 - default:
906 - break;
907 - }
908 -}
909 -
910 -void RunTestTimed3D(int test)
911 -{
912 - if(!d3d7dev) return;
913 - POINT p;
914 - RECT srcrect,destrect;
915 - HRESULT error;
916 - D3DMATRIX mat;
917 - DDSURFACEDESC2 ddsd;
918 - ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
919 - if(d3dver >= 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
920 - else ddsd.dwSize = sizeof(DDSURFACEDESC);
921 - error = d3d7dev->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,bgcolor,1.0,0);
922 - float time = (float)clock() / (float)CLOCKS_PER_SEC;
923 - switch(test)
924 - {
925 - case 0:
926 - mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
927 - mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
928 - mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
929 - mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
930 - mat._11 = (FLOAT)cos( (float)time );
931 - mat._33 = (FLOAT)cos( (float)time );
932 - mat._13 = -(FLOAT)sin( (float)time );
933 - mat._31 = (FLOAT)sin( (float)time );
934 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
935 - error = d3d7dev->BeginScene();
936 - error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,numpoints,mesh,numindices,0);
937 - error = d3d7dev->EndScene();
938 - break;
939 - case 1:
940 - mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
941 - mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
942 - mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
943 - mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
944 - mat._11 = (FLOAT)cos( (float)time );
945 - mat._33 = (FLOAT)cos( (float)time );
946 - mat._13 = -(FLOAT)sin( (float)time );
947 - mat._31 = (FLOAT)sin( (float)time );
948 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
949 - error = d3d7dev->BeginScene();
950 - error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[0]->GetSurface());
951 - error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices,4,0);
952 - error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[1]->GetSurface());
953 - error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+4,4,0);
954 - error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[2]->GetSurface());
955 - error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+8,4,0);
956 - error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[3]->GetSurface());
957 - error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+12,4,0);
958 - error = d3d7dev->EndScene();
959 - break;
960 - case 2:
961 - mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
962 - mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
963 - mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
964 - mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
965 - mat._11 = (FLOAT)cos( (float)time );
966 - mat._33 = (FLOAT)cos( (float)time );
967 - mat._13 = -(FLOAT)sin( (float)time );
968 - mat._31 = (FLOAT)sin( (float)time );
969 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
970 - error = d3d7dev->BeginScene();
971 - error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_LVERTEX,litvertices,numpoints,mesh,numindices,0);
972 - error = d3d7dev->EndScene();
973 - break;
974 - case 3:
975 - mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
976 - mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
977 - mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
978 - mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
979 - mat._11 = (FLOAT)cos( (float)time );
980 - mat._33 = (FLOAT)cos( (float)time );
981 - mat._13 = -(FLOAT)sin( (float)time );
982 - mat._31 = (FLOAT)sin( (float)time );
983 - error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
984 - error = d3d7dev->BeginScene();
985 - error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,FVF_COLORVERTEX,colorvertices,numpoints,mesh,numindices,0);
986 - error = d3d7dev->EndScene();
987 - break;
988 - default:
989 - break;
990 - }
991 - if(fullscreen)
992 - {
993 - if(backbuffers) ddsurface->Flip(NULL,DDFLIP_WAIT);
994 - }
995 - else
996 - {
997 - p.x = 0;
998 - p.y = 0;
999 - ClientToScreen(hWnd,&p);
1000 - GetClientRect(hWnd,&destrect);
1001 - OffsetRect(&destrect,p.x,p.y);
1002 - SetRect(&srcrect,0,0,width,height);
1003 - if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
1004 - }
1005 -}
1006 -
1007 -void RunTestLooped3D(int test)
1008 -{
1009 -}
1010 -
1011 -void PopulateArgCombo(HWND hWnd)
1012 -{
1013 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Diffuse"));
1014 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Current"));
1015 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Texture"));
1016 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Factor"));
1017 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Specular"));
1018 -}
1019 -
1020 -void PopulateOpCombo(HWND hWnd, bool color)
1021 -{
1022 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Disable"));
1023 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Select Arg 1"));
1024 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Select Arg 2"));
1025 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Modulate"));
1026 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Modulate 2x"));
1027 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Modulate 4x"));
1028 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Add"));
1029 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Add Signed"));
1030 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Add Signed 2x"));
1031 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Subtract"));
1032 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Add Smooth"));
1033 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Blend Diffuse Alpha"));
1034 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Blend Texture Alpha"));
1035 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Blend Factor Alpha"));
1036 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Blend Texture Alpha PM"));
1037 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Blend Current Alpha"));
1038 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Premodulate"));
1039 - if(color)
1040 - {
1041 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Modulate Alpha Add Color"));
1042 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Modulate Color Add Alpha"));
1043 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Modulate Inv. Alpha Add Color"));
1044 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Modulate Inv. Color Add Alpha"));
1045 - }
1046 - else
1047 - {
1048 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("(invalid)"));
1049 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("(invalid)"));
1050 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("(invalid)"));
1051 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("(invalid)"));
1052 - }
1053 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Bump Env. Map"));
1054 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Bump Env. Map Luminance"));
1055 - if(color) SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Dot Product3"));
1056 -}
1057 -
1058 -void PopulateBlendCombo(HWND hWnd, bool src)
1059 -{
1060 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Zero"));
1061 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("One"));
1062 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Source Color"));
1063 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Inv. Src. Color"));
1064 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Source Alpha"));
1065 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Inv. Src. Alpha"));
1066 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Dest. Alpha"));
1067 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Inv. Dest. Alpha"));
1068 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Dest. Color"));
1069 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Inv. Dest. Color"));
1070 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Src. Alpha Sat."));
1071 - if(src)
1072 - {
1073 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Both Src. Alpha"));
1074 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Both Inv. Src. Alpha"));
1075 - }
1076 -}
1077 -
1078 -void PopulateCompareCombo(HWND hWnd)
1079 -{
1080 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Never"));
1081 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Less"));
1082 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Equal"));
1083 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Less or Equal"));
1084 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Greater"));
1085 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Not Equal"));
1086 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Greater or Equal"));
1087 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Always"));
1088 -}
1089 -
1090 -void PopulateFogCombo(HWND hWnd)
1091 -{
1092 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("None"));
1093 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Exponential"));
1094 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Exp. Squared"));
1095 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Linear"));
1096 -}
1097 -
1098 -void PopulateSourceCombo(HWND hWnd)
1099 -{
1100 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Material"));
1101 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Color 1"));
1102 - SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Color 2"));
1103 -}
1104 -
1105 -void strupper(TCHAR *str)
1106 -{
1107 - TCHAR *ptr = str;
1108 - while(*ptr != 0)
1109 - {
1110 - *ptr = _totupper(*ptr);
1111 - ptr++;
1112 - }
1113 -}
1114 -
1115 -void paddwordzeroes(TCHAR *str)
1116 -{
1117 - TCHAR str2[16];
1118 - str2[0] = 0;
1119 - int len = _tcslen(str);
1120 - if(len < 8)
1121 - {
1122 - for(int i = 0; i < 8-len; i++)
1123 - _tcscat(str2,_T("0"));
1124 - _tcscat(str2,str);
1125 - _tcscpy(str,str2);
1126 - }
1127 -}
1128 -
1129 -HRESULT CALLBACK SelectTextureFormatCallback(LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext)
1130 -{
1131 - if(lpDDPixFmt->dwFlags & (DDPF_LUMINANCE|DDPF_BUMPLUMINANCE|DDPF_BUMPDUDV)) return D3DENUMRET_OK;
1132 - if(lpDDPixFmt->dwFourCC != 0) return D3DENUMRET_OK;
1133 - if(!(lpDDPixFmt->dwFlags & DDPF_ALPHAPIXELS)) return D3DENUMRET_OK;
1134 - if(lpDDPixFmt->dwRGBBitCount < 32) return D3DENUMRET_OK;
1135 - memcpy(lpContext,lpDDPixFmt,sizeof(DDPIXELFORMAT));
1136 - return D3DENUMRET_CANCEL;
1137 -}
1138 -
1139 -void CreateSurfaceFromBitmap(MultiDirectDrawSurface **surface, DDSURFACEDESC2 *ddsd, HDC hdc, int width, int height)
1140 -{
1141 - ddinterface->CreateSurface(ddsd,surface,NULL);
1142 - HDC surfacedc;
1143 - if(surface)
1144 - {
1145 - (*surface)->GetDC(&surfacedc);
1146 - BitBlt(surfacedc,0,0,width,height,hdc,0,0,SRCCOPY);
1147 - (*surface)->ReleaseDC(surfacedc);
1148 - }
1149 -}
1150 -
1151 -void SelectTexture(MultiDirectDrawSurface **surface, int type, DWORD colorkey, bool haskey, LPCTSTR file)
1152 -{
1153 - DDSURFACEDESC2 ddsd;
1154 - ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
1155 - ddsd.dwSize = sizeof(DDSURFACEDESC2);
1156 - BITMAPV4HEADER bi;
1157 - HBITMAP bitmap;
1158 - HDC hdc;
1159 - HDC hmemdc;
1160 - HBITMAP holdbmp;
1161 - HICON icon;
1162 - VOID *bmpbits;
1163 - ZeroMemory(&bi,sizeof(BITMAPV4HEADER));
1164 - bi.bV4Size = sizeof(BITMAPV4HEADER);
1165 - bi.bV4Planes = 1;
1166 - bi.bV4BitCount = 32;
1167 - bi.bV4V4Compression = BI_BITFIELDS;
1168 - bi.bV4RedMask = 0x00FF0000;
1169 - bi.bV4GreenMask = 0x0000FF00;
1170 - bi.bV4BlueMask = 0x000000FF;
1171 - bi.bV4AlphaMask = 0xFF000000;
1172 - d3d7dev->EnumTextureFormats(SelectTextureFormatCallback,&ddsd.ddpfPixelFormat);
1173 - ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1174 - ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT|DDSD_TEXTURESTAGE;
1175 - DDCOLORKEY ckey;
1176 - ckey.dwColorSpaceHighValue = ckey.dwColorSpaceLowValue = colorkey;
1177 - if(haskey) ddsd.dwFlags |= DDSD_CKSRCBLT;
1178 - if(*surface)
1179 - {
1180 - d3d7dev->SetTexture(texshaderstate.currentstage,NULL);
1181 - (*surface)->Release();
1182 - *surface = NULL;
1183 - }
1184 - switch(type)
1185 - {
1186 - case 0:
1187 - default:
1188 - break;
1189 - case 1:
1190 - break;
1191 - case 2:
1192 - hdc = GetDC(NULL);
1193 - bi.bV4Width = ddsd.dwWidth = bi.bV4Height = ddsd.dwHeight = 16;
1194 - bitmap = CreateDIBSection(hdc,(BITMAPINFO*)&bi,DIB_RGB_COLORS,&bmpbits,NULL,0);
1195 - hmemdc = CreateCompatibleDC(hdc);
1196 - ReleaseDC(NULL,hdc);
1197 - holdbmp = (HBITMAP)SelectObject(hmemdc,bitmap);
1198 - icon = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_DXGL),IMAGE_ICON,16,16,0);
1199 - DrawIconEx(hmemdc,0,0,icon,16,16,0,NULL,DI_NORMAL);
1200 - CreateSurfaceFromBitmap(surface,&ddsd,hmemdc,16,16);
1201 - SelectObject(hmemdc,holdbmp);
1202 - DeleteDC(hmemdc);
1203 - DeleteObject(bitmap);
1204 - if(*surface && haskey) (*surface)->SetColorKey(DDCKEY_SRCBLT,&ckey);
1205 - if(*surface) d3d7dev->SetTexture(texshaderstate.currentstage,(LPDIRECTDRAWSURFACE7)(*surface)->GetSurface());
1206 - break;
1207 - case 3:
1208 - hdc = GetDC(NULL);
1209 - bi.bV4Width = ddsd.dwWidth = bi.bV4Height = ddsd.dwHeight = 256;
1210 - bitmap = CreateDIBSection(hdc,(BITMAPINFO*)&bi,DIB_RGB_COLORS,&bmpbits,NULL,0);
1211 - hmemdc = CreateCompatibleDC(hdc);
1212 - ReleaseDC(NULL,hdc);
1213 - holdbmp = (HBITMAP)SelectObject(hmemdc,bitmap);
1214 - icon = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_DXGL),IMAGE_ICON,256,256,0);
1215 - DrawIconEx(hmemdc,0,0,icon,256,256,0,NULL,DI_NORMAL);
1216 - CreateSurfaceFromBitmap(surface,&ddsd,hmemdc,256,256);
1217 - SelectObject(hmemdc,holdbmp);
1218 - DeleteDC(hmemdc);
1219 - DeleteObject(bitmap);
1220 - if(*surface && haskey) (*surface)->SetColorKey(DDCKEY_SRCBLT,&ckey);
1221 - if(*surface) d3d7dev->SetTexture(texshaderstate.currentstage,(LPDIRECTDRAWSURFACE7)(*surface)->GetSurface());
1222 - break;
1223 - case 4:
1224 - break;
1225 - }
1226 -}
1227 -
1228 -void SetShaderArg(HWND hWnd, UINT dropdown, UINT checkalpha, UINT checkinv, DWORD *texarg)
1229 -{
1230 - DWORD arg = SendDlgItemMessage(hWnd,dropdown,CB_GETCURSEL,0,0);
1231 - if(SendDlgItemMessage(hWnd,checkalpha,BM_GETCHECK,0,0) == BST_CHECKED)
1232 - arg |= D3DTA_ALPHAREPLICATE;
1233 - if(SendDlgItemMessage(hWnd,checkinv,BM_GETCHECK,0,0) == BST_CHECKED)
1234 - arg |= D3DTA_COMPLEMENT;
1235 - *texarg = arg;
1236 -}
1237 -
1238 -INT_PTR CALLBACK TexShader7Proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
1239 -{
1240 - HRESULT error;
1241 - D3DVIEWPORT7 vp;
1242 - HWND hDisplay;
1243 - int number;
1244 - float f;
1245 - TCHAR tmpstring[MAX_PATH+1];
1246 - switch(Msg)
1247 - {
1248 - case WM_INITDIALOG:
1249 - RECT r;
1250 - DDSCAPS2 caps;
1251 - DDSURFACEDESC2 ddsd;
1252 - DDPIXELFORMAT ddpfz;
1253 - testnum = 2;
1254 - ddinterface = new MultiDirectDraw(7,&error,NULL);
1255 - hDisplay = GetDlgItem(hWnd,IDC_DISPLAY);
1256 - ::hWnd = hDisplay;
1257 - error = ddinterface->SetCooperativeLevel(hDisplay,DDSCL_NORMAL);
1258 - ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
1259 - ddsd.dwSize = sizeof(DDSURFACEDESC2);
1260 - ddsd.dwFlags = DDSD_CAPS;
1261 - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1262 - error = ddinterface->CreateSurface(&ddsd,&ddsurface,NULL);
1263 - error = ddinterface->CreateClipper(0,&ddclipper,NULL);
1264 - error = ddclipper->SetHWnd(0,hDisplay);
1265 - error = ddsurface->SetClipper(ddclipper);
1266 - ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
1267 - ddsd.dwSize = sizeof(DDSURFACEDESC2);
1268 - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1269 - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE;
1270 - GetClientRect(hDisplay,&r);
1271 - ddsd.dwWidth = r.right;
1272 - ddsd.dwHeight = r.bottom;
1273 - error = ddinterface->CreateSurface(&ddsd,&ddsrender,NULL);
1274 - error = ddinterface->QueryInterface(IID_IDirect3D7,(VOID**)&d3d7);
1275 - error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice,zcallback,&ddpfz);
1276 - error = ddsrender->GetSurfaceDesc(&ddsd);
1277 - ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
1278 - ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER|DDSCAPS_VIDEOMEMORY;
1279 - memcpy(&ddsd.ddpfPixelFormat,&ddpfz,sizeof(DDPIXELFORMAT));
1280 - error = ddinterface->CreateSurface(&ddsd,&zbuffer,NULL);
1281 - error = ddsrender->AddAttachedSurface(zbuffer);
1282 - error = d3d7->CreateDevice(IID_IDirect3DHALDevice,(LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(),&d3d7dev);
1283 - if(error != D3D_OK)
1284 - error = d3d7->CreateDevice(IID_IDirect3DRGBDevice,(LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(),&d3d7dev);
1285 - ddsrender->GetSurfaceDesc(&ddsd);
1286 - vp.dvMaxZ = 1.0f;
1287 - vp.dvMinZ = 0.0f;
1288 - vp.dwX = vp.dwY = 0;
1289 - vp.dwWidth = ddsd.dwWidth;
1290 - vp.dwHeight = ddsd.dwHeight;
1291 - error = d3d7dev->SetViewport(&vp);
1292 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_ZENABLE,TRUE);
1293 - InitTest3D(2);
1294 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_ADDSTRING,0,(LPARAM)_T("None"));
1295 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_ADDSTRING,0,(LPARAM)_T("Gradients"));
1296 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_ADDSTRING,0,(LPARAM)_T("DXGL logo (small)"));
1297 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_ADDSTRING,0,(LPARAM)_T("DXGL logo (large)"));
1298 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_ADDSTRING,0,(LPARAM)_T("Texture file"));
1299 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_SETCURSEL,0,0);
1300 - SendDlgItemMessage(hWnd,IDC_TEXCOLORKEY,WM_SETTEXT,0,(LPARAM)_T(""));
1301 - PopulateArgCombo(GetDlgItem(hWnd,IDC_CARG1));
1302 - PopulateArgCombo(GetDlgItem(hWnd,IDC_CARG2));
1303 - PopulateArgCombo(GetDlgItem(hWnd,IDC_AARG1));
1304 - PopulateArgCombo(GetDlgItem(hWnd,IDC_AARG2));
1305 - SendDlgItemMessage(hWnd,IDC_CARG1,CB_SETCURSEL,D3DTA_TEXTURE,0);
1306 - SendDlgItemMessage(hWnd,IDC_CARG2,CB_SETCURSEL,D3DTA_CURRENT,0);
1307 - SendDlgItemMessage(hWnd,IDC_AARG1,CB_SETCURSEL,D3DTA_TEXTURE,0);
1308 - SendDlgItemMessage(hWnd,IDC_AARG2,CB_SETCURSEL,D3DTA_CURRENT,0);
1309 - PopulateOpCombo(GetDlgItem(hWnd,IDC_COLOROP),true);
1310 - PopulateOpCombo(GetDlgItem(hWnd,IDC_ALPHAOP),false);
1311 - SendDlgItemMessage(hWnd,IDC_COLOROP,CB_SETCURSEL,D3DTOP_MODULATE-1,0);
1312 - SendDlgItemMessage(hWnd,IDC_ALPHAOP,CB_SETCURSEL,D3DTOP_SELECTARG1-1,0);
1313 - SendDlgItemMessage(hWnd,IDC_DIFFUSE,WM_SETTEXT,0,(LPARAM)_T("FFFFFFFF"));
1314 - SendDlgItemMessage(hWnd,IDC_SPECULAR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1315 - SendDlgItemMessage(hWnd,IDC_FACTOR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1316 - SendDlgItemMessage(hWnd,IDC_FOGCOLOR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1317 - SendDlgItemMessage(hWnd,IDC_BGCOLOR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1318 - PopulateBlendCombo(GetDlgItem(hWnd,IDC_SRCBLEND),true);
1319 - PopulateBlendCombo(GetDlgItem(hWnd,IDC_DESTBLEND),true);
1320 - SendDlgItemMessage(hWnd,IDC_SRCBLEND,CB_SETCURSEL,D3DBLEND_ONE-1,0);
1321 - SendDlgItemMessage(hWnd,IDC_DESTBLEND,CB_SETCURSEL,D3DBLEND_ZERO-1,0);
1322 - PopulateCompareCombo(GetDlgItem(hWnd,IDC_ALPHAFUNC));
1323 - SendDlgItemMessage(hWnd,IDC_ALPHAFUNC,CB_SETCURSEL,D3DCMP_ALWAYS-1,0);
1324 - PopulateFogCombo(GetDlgItem(hWnd,IDC_VERTEXFOGMODE));
1325 - PopulateFogCombo(GetDlgItem(hWnd,IDC_PIXELFOGMODE));
1326 - SendDlgItemMessage(hWnd,IDC_VERTEXFOGMODE,CB_SETCURSEL,D3DFOG_NONE,0);
1327 - SendDlgItemMessage(hWnd,IDC_PIXELFOGMODE,CB_SETCURSEL,D3DFOG_NONE,0);
1328 - SendDlgItemMessage(hWnd,IDC_FOGSTART,WM_SETTEXT,0,(LPARAM)_T("0.0"));
1329 - SendDlgItemMessage(hWnd,IDC_FOGEND,WM_SETTEXT,0,(LPARAM)_T("1.0"));
1330 - SendDlgItemMessage(hWnd,IDC_FOGDENSITY,WM_SETTEXT,0,(LPARAM)_T("1.0"));
1331 - SendDlgItemMessage(hWnd,IDC_SPINSTAGE,UDM_SETRANGE32,0,7);
1332 - SendDlgItemMessage(hWnd,IDC_SPINALPHAREF,UDM_SETRANGE32,0,255);
1333 - ::width = ddsd.dwWidth;
1334 - ::height = ddsd.dwHeight;
1335 - StartTimer(hWnd,WM_APP,60);
1336 - break;
1337 - case WM_COMMAND:
1338 - switch(LOWORD(wParam))
1339 - {
1340 - case IDC_TEXSTAGE:
1341 - if(HIWORD(wParam) == EN_CHANGE)
1342 - {
1343 - SendDlgItemMessage(hWnd,IDC_TEXSTAGE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1344 - number = _ttoi(tmpstring);
1345 - if(number < 0) SendDlgItemMessage(hWnd,IDC_TEXSTAGE,WM_SETTEXT,0,(LPARAM)_T("0"));
1346 - if(number > 7) SendDlgItemMessage(hWnd,IDC_TEXSTAGE,WM_SETTEXT,0,(LPARAM)_T("7"));
1347 - if(number < 0) number = 0;
1348 - if(number > 7) number = 7;
1349 - texshaderstate.currentstage = number;
1350 - _itot(texshaderstate.texstages[number].keycolor,tmpstring,16);
1351 - strupper(tmpstring);
1352 - paddwordzeroes(tmpstring);
1353 - if(texshaderstate.texstages[number].colorkey == FALSE) tmpstring[0] = 0;
1354 - SendDlgItemMessage(hWnd,IDC_TEXCOLORKEY,WM_SETTEXT,0,(LPARAM)tmpstring);
1355 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_SETCURSEL,texshaderstate.texstages[number].texturetype,0);
1356 - SendDlgItemMessage(hWnd,IDC_TEXTUREFILE,WM_SETTEXT,0,(LPARAM)texshaderstate.texstages[number].texturefile);
1357 - SendDlgItemMessage(hWnd,IDC_CARG1,CB_SETCURSEL,texshaderstate.texstages[number].colorarg1 & D3DTA_SELECTMASK,0);
1358 - SendDlgItemMessage(hWnd,IDC_CARG2,CB_SETCURSEL,texshaderstate.texstages[number].colorarg2 & D3DTA_SELECTMASK,0);
1359 - SendDlgItemMessage(hWnd,IDC_AARG1,CB_SETCURSEL,texshaderstate.texstages[number].alphaarg1 & D3DTA_SELECTMASK,0);
1360 - SendDlgItemMessage(hWnd,IDC_AARG2,CB_SETCURSEL,texshaderstate.texstages[number].alphaarg2 & D3DTA_SELECTMASK,0);
1361 - if(texshaderstate.texstages[number].colorarg1 & D3DTA_ALPHAREPLICATE)
1362 - SendDlgItemMessage(hWnd,IDC_CARG1A,BM_SETCHECK,BST_CHECKED,0);
1363 - else SendDlgItemMessage(hWnd,IDC_CARG1A,BM_SETCHECK,BST_UNCHECKED,0);
1364 - if(texshaderstate.texstages[number].colorarg2 & D3DTA_ALPHAREPLICATE)
1365 - SendDlgItemMessage(hWnd,IDC_CARG2A,BM_SETCHECK,BST_CHECKED,0);
1366 - else SendDlgItemMessage(hWnd,IDC_CARG2A,BM_SETCHECK,BST_UNCHECKED,0);
1367 - if(texshaderstate.texstages[number].alphaarg1 & D3DTA_ALPHAREPLICATE)
1368 - SendDlgItemMessage(hWnd,IDC_AARG1A,BM_SETCHECK,BST_CHECKED,0);
1369 - else SendDlgItemMessage(hWnd,IDC_AARG1A,BM_SETCHECK,BST_UNCHECKED,0);
1370 - if(texshaderstate.texstages[number].alphaarg2 & D3DTA_ALPHAREPLICATE)
1371 - SendDlgItemMessage(hWnd,IDC_AARG2A,BM_SETCHECK,BST_CHECKED,0);
1372 - else SendDlgItemMessage(hWnd,IDC_AARG2A,BM_SETCHECK,BST_UNCHECKED,0);
1373 - if(texshaderstate.texstages[number].colorarg1 & D3DTA_COMPLEMENT)
1374 - SendDlgItemMessage(hWnd,IDC_CARG1INV,BM_SETCHECK,BST_CHECKED,0);
1375 - else SendDlgItemMessage(hWnd,IDC_CARG1INV,BM_SETCHECK,BST_UNCHECKED,0);
1376 - if(texshaderstate.texstages[number].colorarg2 & D3DTA_COMPLEMENT)
1377 - SendDlgItemMessage(hWnd,IDC_CARG2INV,BM_SETCHECK,BST_CHECKED,0);
1378 - else SendDlgItemMessage(hWnd,IDC_CARG2INV,BM_SETCHECK,BST_UNCHECKED,0);
1379 - if(texshaderstate.texstages[number].alphaarg1 & D3DTA_COMPLEMENT)
1380 - SendDlgItemMessage(hWnd,IDC_AARG1INV,BM_SETCHECK,BST_CHECKED,0);
1381 - else SendDlgItemMessage(hWnd,IDC_AARG1INV,BM_SETCHECK,BST_UNCHECKED,0);
1382 - if(texshaderstate.texstages[number].alphaarg2 & D3DTA_COMPLEMENT)
1383 - SendDlgItemMessage(hWnd,IDC_AARG2INV,BM_SETCHECK,BST_CHECKED,0);
1384 - else SendDlgItemMessage(hWnd,IDC_AARG2INV,BM_SETCHECK,BST_UNCHECKED,0);
1385 - SendDlgItemMessage(hWnd,IDC_COLOROP,CB_SETCURSEL,texshaderstate.texstages[number].colorop-1,0);
1386 - SendDlgItemMessage(hWnd,IDC_ALPHAOP,CB_SETCURSEL,texshaderstate.texstages[number].alphaop-1,0);
1387 - }
1388 - break;
1389 - case IDC_TEXTURE:
1390 - if(HIWORD(wParam) == CBN_SELCHANGE)
1391 - {
1392 - number = texshaderstate.currentstage;
1393 - texshaderstate.texstages[number].texturetype =
1394 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_GETCURSEL,0,0);
1395 - SelectTexture(&texshaderstate.texstages[number].texture,texshaderstate.texstages[number].texturetype,
1396 - texshaderstate.texstages[number].keycolor, texshaderstate.texstages[number].colorkey,
1397 - texshaderstate.texstages[number].texturefile);
1398 - }
1399 - break;
1400 - case IDC_TEXTUREFILE:
1401 - if(HIWORD(wParam) == EN_KILLFOCUS)
1402 - {
1403 - number = texshaderstate.currentstage;
1404 - SendDlgItemMessage(hWnd,IDC_TEXTUREFILE,WM_GETTEXT,MAX_PATH+1,
1405 - (LPARAM)texshaderstate.texstages[number].texturefile);
1406 - SelectTexture(&texshaderstate.texstages[number].texture,texshaderstate.texstages[number].texturetype,
1407 - texshaderstate.texstages[number].keycolor, texshaderstate.texstages[number].colorkey,
1408 - texshaderstate.texstages[number].texturefile);
1409 - }
1410 - break;
1411 - case IDC_CARG1:
1412 - if(HIWORD(wParam) == CBN_SELCHANGE)
1413 - {
1414 - number = texshaderstate.currentstage;
1415 - SetShaderArg(hWnd,IDC_CARG1,IDC_CARG1A,IDC_CARG1INV,&texshaderstate.texstages[number].colorarg1);
1416 - d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG1,texshaderstate.texstages[number].colorarg1);
1417 - }
1418 - break;
1419 - case IDC_CARG1A:
1420 - case IDC_CARG1INV:
1421 - if(HIWORD(wParam) == BN_CLICKED)
1422 - {
1423 - number = texshaderstate.currentstage;
1424 - SetShaderArg(hWnd,IDC_CARG1,IDC_CARG1A,IDC_CARG1INV,&texshaderstate.texstages[number].colorarg2);
1425 - d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG1,texshaderstate.texstages[number].colorarg2);
1426 - }
1427 - break;
1428 - case IDC_CARG2:
1429 - if(HIWORD(wParam) == CBN_SELCHANGE)
1430 - {
1431 - number = texshaderstate.currentstage;
1432 - SetShaderArg(hWnd,IDC_CARG2,IDC_CARG2A,IDC_CARG2INV,&texshaderstate.texstages[number].colorarg2);
1433 - d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG2,texshaderstate.texstages[number].colorarg2);
1434 - }
1435 - break;
1436 - case IDC_CARG2A:
1437 - case IDC_CARG2INV:
1438 - if(HIWORD(wParam) == BN_CLICKED)
1439 - {
1440 - number = texshaderstate.currentstage;
1441 - SetShaderArg(hWnd,IDC_CARG2,IDC_CARG2A,IDC_CARG2INV,&texshaderstate.texstages[number].colorarg1);
1442 - d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG2,texshaderstate.texstages[number].colorarg1);
1443 - }
1444 - break;
1445 - case IDC_AARG1:
1446 - if(HIWORD(wParam) == CBN_SELCHANGE)
1447 - {
1448 - number = texshaderstate.currentstage;
1449 - SetShaderArg(hWnd,IDC_AARG1,IDC_AARG1A,IDC_AARG1INV,&texshaderstate.texstages[number].alphaarg1);
1450 - d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG1,texshaderstate.texstages[number].alphaarg1);
1451 - }
1452 - break;
1453 - case IDC_AARG1A:
1454 - case IDC_AARG1INV:
1455 - if(HIWORD(wParam) == BN_CLICKED)
1456 - {
1457 - number = texshaderstate.currentstage;
1458 - SetShaderArg(hWnd,IDC_AARG1,IDC_AARG1A,IDC_AARG1INV,&texshaderstate.texstages[number].alphaarg1);
1459 - d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG1,texshaderstate.texstages[number].alphaarg1);
1460 - }
1461 - break;
1462 - case IDC_AARG2:
1463 - if(HIWORD(wParam) == CBN_SELCHANGE)
1464 - {
1465 - number = texshaderstate.currentstage;
1466 - SetShaderArg(hWnd,IDC_AARG2,IDC_AARG2A,IDC_AARG2INV,&texshaderstate.texstages[number].alphaarg2);
1467 - d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG2,texshaderstate.texstages[number].alphaarg2);
1468 - }
1469 - break;
1470 - case IDC_AARG2A:
1471 - case IDC_AARG2INV:
1472 - if(HIWORD(wParam) == BN_CLICKED)
1473 - {
1474 - number = texshaderstate.currentstage;
1475 - SetShaderArg(hWnd,IDC_AARG2,IDC_AARG2A,IDC_AARG2INV,&texshaderstate.texstages[number].alphaarg2);
1476 - d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG2,texshaderstate.texstages[number].alphaarg2);
1477 - }
1478 - break;
1479 - case IDC_COLOROP:
1480 - if(HIWORD(wParam) == CBN_SELCHANGE)
1481 - {
1482 - number = texshaderstate.currentstage;
1483 - texshaderstate.texstages[number].colorop = (D3DTEXTUREOP)(SendDlgItemMessage(hWnd,IDC_COLOROP,CB_GETCURSEL,0,0)+1);
1484 - d3d7dev->SetTextureStageState(number,D3DTSS_COLOROP,texshaderstate.texstages[number].colorop);
1485 - }
1486 - break;
1487 - case IDC_ALPHAOP:
1488 - if(HIWORD(wParam) == CBN_SELCHANGE)
1489 - {
1490 - number = texshaderstate.currentstage;
1491 - texshaderstate.texstages[number].alphaop = (D3DTEXTUREOP)(SendDlgItemMessage(hWnd,IDC_ALPHAOP,CB_GETCURSEL,0,0)+1);
1492 - d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAOP,texshaderstate.texstages[number].alphaop);
1493 - }
1494 - break;
1495 - case IDC_BGCOLOR:
1496 - if(HIWORD(wParam) == EN_CHANGE)
1497 - {
1498 - SendDlgItemMessage(hWnd,IDC_BGCOLOR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1499 - if(!_stscanf(tmpstring,_T("%x"),&bgcolor)) bgcolor = 0;
1500 - }
1501 - break;
1502 - case IDC_DIFFUSE:
1503 - if(HIWORD(wParam) == EN_CHANGE)
1504 - {
1505 - SendDlgItemMessage(hWnd,IDC_DIFFUSE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1506 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
1507 - SetVertexColor(litvertices,colorvertices,numpoints,number);
1508 - }
1509 - break;
1510 - case IDC_SPECULAR:
1511 - if(HIWORD(wParam) == EN_CHANGE)
1512 - {
1513 - SendDlgItemMessage(hWnd,IDC_SPECULAR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1514 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
1515 - SetVertexSpecular(litvertices,colorvertices,numpoints,number);
1516 - }
1517 - break;
1518 - case IDC_FACTOR:
1519 - if(HIWORD(wParam) == EN_CHANGE)
1520 - {
1521 - SendDlgItemMessage(hWnd,IDC_FACTOR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1522 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
1523 - d3d7dev->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR,number);
1524 - }
1525 - break;
1526 - case IDC_FOGCOLOR:
1527 - if(HIWORD(wParam) == EN_CHANGE)
1528 - {
1529 - SendDlgItemMessage(hWnd,IDC_FOGCOLOR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1530 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
1531 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGCOLOR,number);
1532 - }
1533 - break;
1534 - case IDC_TEXCOLORKEY:
1535 - if(HIWORD(wParam) == EN_CHANGE)
1536 - {
1537 - SendDlgItemMessage(hWnd,IDC_TEXCOLORKEY,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1538 - number = texshaderstate.currentstage;
1539 - if(tmpstring[0] == 0)
1540 - {
1541 - texshaderstate.texstages[number].colorkey = FALSE;
1542 - texshaderstate.texstages[number].keycolor = 0;
1543 - }
1544 - else
1545 - {
1546 - texshaderstate.texstages[number].colorkey = TRUE;
1547 - if(!_stscanf(tmpstring,_T("%x"),&texshaderstate.texstages[number].keycolor))
1548 - texshaderstate.texstages[number].keycolor = 0;
1549 - }
1550 - SelectTexture(&texshaderstate.texstages[number].texture,texshaderstate.texstages[number].texturetype,
1551 - texshaderstate.texstages[number].keycolor, texshaderstate.texstages[number].colorkey,
1552 - texshaderstate.texstages[number].texturefile);
1553 - }
1554 - case IDC_ALPHABLEND:
1555 - if(HIWORD(wParam) == BN_CLICKED)
1556 - {
1557 - if(SendDlgItemMessage(hWnd,IDC_ALPHABLEND,BM_GETCHECK,0,0) == BST_CHECKED)
1558 - d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);
1559 - else d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,FALSE);
1560 - }
1561 - break;
1562 - case IDC_SRCBLEND:
1563 - if(HIWORD(wParam) == CBN_SELCHANGE)
1564 - {
1565 - d3d7dev->SetRenderState(D3DRENDERSTATE_SRCBLEND,SendDlgItemMessage(hWnd,
1566 - IDC_SRCBLEND,CB_GETCURSEL,0,0)+1);
1567 - }
1568 - case IDC_DESTBLEND:
1569 - if(HIWORD(wParam) == CBN_SELCHANGE)
1570 - {
1571 - d3d7dev->SetRenderState(D3DRENDERSTATE_DESTBLEND,SendDlgItemMessage(hWnd,
1572 - IDC_DESTBLEND,CB_GETCURSEL,0,0)+1);
1573 - }
1574 - break;
1575 - case IDC_ALPHATEST:
1576 - if(HIWORD(wParam) == BN_CLICKED)
1577 - {
1578 - if(SendDlgItemMessage(hWnd,IDC_ALPHATEST,BM_GETCHECK,0,0) == BST_CHECKED)
1579 - d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,TRUE);
1580 - else d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,FALSE);
1581 - }
1582 - case IDC_ALPHAFUNC:
1583 - if(HIWORD(wParam) == CBN_SELCHANGE)
1584 - {
1585 - d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHAFUNC,SendDlgItemMessage(hWnd,
1586 - IDC_ALPHAFUNC,CB_GETCURSEL,0,0)+1);
1587 - }
1588 - break;
1589 - case IDC_ALPHAREF:
1590 - if(HIWORD(wParam) == EN_CHANGE)
1591 - {
1592 - SendDlgItemMessage(hWnd,IDC_ALPHAREF,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1593 - number = _ttoi(tmpstring);
1594 - if(number < 0) SendDlgItemMessage(hWnd,IDC_ALPHAREF,WM_SETTEXT,0,(LPARAM)_T("0"));
1595 - if(number > 255) SendDlgItemMessage(hWnd,IDC_ALPHAREF,WM_SETTEXT,0,(LPARAM)_T("255"));
1596 - if(number < 0) number = 0;
1597 - if(number > 255) number = 255;
1598 - if(d3d7dev) d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHAREF,number);
1599 - }
1600 - case IDC_COLORKEY:
1601 - if(HIWORD(wParam) == BN_CLICKED)
1602 - {
1603 - if(SendDlgItemMessage(hWnd,IDC_COLORKEY,BM_GETCHECK,0,0) == BST_CHECKED)
1604 - d3d7dev->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE,TRUE);
1605 - else d3d7dev->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE,FALSE);
1606 - }
1607 - break;
1608 - case IDC_FOGENABLE:
1609 - if(HIWORD(wParam) == BN_CLICKED)
1610 - {
1611 - if(SendDlgItemMessage(hWnd,IDC_FOGENABLE,BM_GETCHECK,0,0) == BST_CHECKED)
1612 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE,TRUE);
1613 - else d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE,FALSE);
1614 - }
1615 - break;
1616 - case IDC_VERTEXFOGMODE:
1617 - if(HIWORD(wParam) == CBN_SELCHANGE)
1618 - {
1619 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE,SendDlgItemMessage(hWnd,
1620 - IDC_VERTEXFOGMODE,CB_GETCURSEL,0,0));
1621 - }
1622 - break;
1623 - case IDC_PIXELFOGMODE:
1624 - if(HIWORD(wParam) == CBN_SELCHANGE)
1625 - {
1626 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE,SendDlgItemMessage(hWnd,
1627 - IDC_PIXELFOGMODE,CB_GETCURSEL,0,0));
1628 - }
1629 - break;
1630 - case IDC_FOGSTART:
1631 - if(HIWORD(wParam) == EN_CHANGE)
1632 - {
1633 - SendDlgItemMessage(hWnd,IDC_FOGSTART,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1634 - f = (float)_ttof(tmpstring);
1635 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGSTART, *((LPDWORD)(&f)));
1636 - }
1637 - break;
1638 - case IDC_FOGEND:
1639 - if(HIWORD(wParam) == EN_CHANGE)
1640 - {
1641 - SendDlgItemMessage(hWnd,IDC_FOGEND,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1642 - f = (float)_ttof(tmpstring);
1643 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGEND, *((LPDWORD)(&f)));
1644 - }
1645 - break;
1646 - case IDC_FOGDENSITY:
1647 - if(HIWORD(wParam) == EN_CHANGE)
1648 - {
1649 - SendDlgItemMessage(hWnd,IDC_FOGDENSITY,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1650 - f = (float)_ttof(tmpstring);
1651 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGDENSITY, *((LPDWORD)(&f)));
1652 - }
1653 - break;
1654 - default:
1655 - return FALSE;
1656 - }
1657 - break;
1658 - case WM_CLOSE:
1659 - if(d3d7dev)
1660 - {
1661 - d3d7dev->Release();
1662 - d3d7dev = NULL;
1663 - }
1664 - if(d3d7)
1665 - {
1666 - d3d7->Release();
1667 - d3d7dev = NULL;
1668 - }
1669 - if(ddsrender)
1670 - {
1671 - ddsrender->Release();
1672 - ddsrender = NULL;
1673 - }
1674 - if(ddsurface)
1675 - {
1676 - ddsurface->Release();
1677 - ddsurface = NULL;
1678 - }
1679 - if(zbuffer)
1680 - {
1681 - zbuffer->Release();
1682 - zbuffer = NULL;
1683 - }
1684 - if(ddclipper)
1685 - {
1686 - ddclipper->Release();
1687 - ddclipper = NULL;
1688 - }
1689 - if(ddinterface)
1690 - {
1691 - ddinterface->Release();
1692 - ddinterface = NULL;
1693 - }
1694 - if(mesh)
1695 - {
1696 - free(mesh);
1697 - mesh = NULL;
1698 - }
1699 - if(vertices)
1700 - {
1701 - free(vertices);
1702 - vertices = NULL;
1703 - }
1704 - if(litvertices)
1705 - {
1706 - free(litvertices);
1707 - litvertices = NULL;
1708 - }
1709 - if(colorvertices)
1710 - {
1711 - free(colorvertices);
1712 - colorvertices = NULL;
1713 - }
1714 - EndDialog(hWnd,IDCANCEL);
1715 - break;
1716 - case WM_APP:
1717 - RunTestTimed3D(testnum);
1718 - break;
1719 - default:
1720 - return FALSE;
1721 - }
1722 - return TRUE;
1723 -
1724 -
1725 -}
1726 -
1727 -INT_PTR CALLBACK VertexShader7Proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
1728 -{
1729 - HRESULT error;
1730 - D3DVIEWPORT7 vp;
1731 - HWND hDisplay;
1732 - int number;
1733 - float f;
1734 - TCHAR tmpstring[MAX_PATH+1];
1735 - switch(Msg)
1736 - {
1737 - case WM_INITDIALOG:
1738 - RECT r;
1739 - DDSCAPS2 caps;
1740 - DDSURFACEDESC2 ddsd;
1741 - DDPIXELFORMAT ddpfz;
1742 - testnum = 3;
1743 - ddinterface = new MultiDirectDraw(7,&error,NULL);
1744 - hDisplay = GetDlgItem(hWnd,IDC_DISPLAY);
1745 - ::hWnd = hDisplay;
1746 - error = ddinterface->SetCooperativeLevel(hDisplay,DDSCL_NORMAL);
1747 - ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
1748 - ddsd.dwSize = sizeof(DDSURFACEDESC2);
1749 - ddsd.dwFlags = DDSD_CAPS;
1750 - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1751 - error = ddinterface->CreateSurface(&ddsd,&ddsurface,NULL);
1752 - error = ddinterface->CreateClipper(0,&ddclipper,NULL);
1753 - error = ddclipper->SetHWnd(0,hDisplay);
1754 - error = ddsurface->SetClipper(ddclipper);
1755 - ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
1756 - ddsd.dwSize = sizeof(DDSURFACEDESC2);
1757 - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1758 - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE;
1759 - GetClientRect(hDisplay,&r);
1760 - ddsd.dwWidth = r.right;
1761 - ddsd.dwHeight = r.bottom;
1762 - error = ddinterface->CreateSurface(&ddsd,&ddsrender,NULL);
1763 - error = ddinterface->QueryInterface(IID_IDirect3D7,(VOID**)&d3d7);
1764 - error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice,zcallback,&ddpfz);
1765 - error = ddsrender->GetSurfaceDesc(&ddsd);
1766 - ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
1767 - ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER|DDSCAPS_VIDEOMEMORY;
1768 - memcpy(&ddsd.ddpfPixelFormat,&ddpfz,sizeof(DDPIXELFORMAT));
1769 - error = ddinterface->CreateSurface(&ddsd,&zbuffer,NULL);
1770 - error = ddsrender->AddAttachedSurface(zbuffer);
1771 - error = d3d7->CreateDevice(IID_IDirect3DHALDevice,(LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(),&d3d7dev);
1772 - if(error != D3D_OK)
1773 - error = d3d7->CreateDevice(IID_IDirect3DRGBDevice,(LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(),&d3d7dev);
1774 - ddsrender->GetSurfaceDesc(&ddsd);
1775 - vp.dvMaxZ = 1.0f;
1776 - vp.dvMinZ = 0.0f;
1777 - vp.dwX = vp.dwY = 0;
1778 - vp.dwWidth = ddsd.dwWidth;
1779 - vp.dwHeight = ddsd.dwHeight;
1780 - error = d3d7dev->SetViewport(&vp);
1781 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_ZENABLE,TRUE);
1782 - InitTest3D(3);
1783 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_ADDSTRING,0,(LPARAM)_T("None"));
1784 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_ADDSTRING,0,(LPARAM)_T("Gradients"));
1785 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_ADDSTRING,0,(LPARAM)_T("DXGL logo (small)"));
1786 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_ADDSTRING,0,(LPARAM)_T("DXGL logo (large)"));
1787 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_ADDSTRING,0,(LPARAM)_T("Texture file"));
1788 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_SETCURSEL,0,0);
1789 - SendDlgItemMessage(hWnd,IDC_DIFFUSE,WM_SETTEXT,0,(LPARAM)_T("FFFFFFFF"));
1790 - SendDlgItemMessage(hWnd,IDC_SPECULAR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1791 - SendDlgItemMessage(hWnd,IDC_FACTOR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1792 - SendDlgItemMessage(hWnd,IDC_FOGCOLOR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1793 - SendDlgItemMessage(hWnd,IDC_BGCOLOR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1794 - SendDlgItemMessage(hWnd,IDC_AMBIENT,WM_SETTEXT,0,(LPARAM)_T("FFFFFFFF"));
1795 - SendDlgItemMessage(hWnd,IDC_EMISSIVE,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1796 - SendDlgItemMessage(hWnd,IDC_MATAMBIENT,WM_SETTEXT,0,(LPARAM)_T("FFFFFFFF"));
1797 - SendDlgItemMessage(hWnd,IDC_MATDIFFUSE,WM_SETTEXT,0,(LPARAM)_T("FFFFFFFF"));
1798 - SendDlgItemMessage(hWnd,IDC_MATSPECULAR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1799 - PopulateFogCombo(GetDlgItem(hWnd,IDC_VERTEXFOGMODE));
1800 - PopulateFogCombo(GetDlgItem(hWnd,IDC_PIXELFOGMODE));
1801 - SendDlgItemMessage(hWnd,IDC_VERTEXFOGMODE,CB_SETCURSEL,D3DFOG_NONE,0);
1802 - SendDlgItemMessage(hWnd,IDC_PIXELFOGMODE,CB_SETCURSEL,D3DFOG_NONE,0);
1803 - SendDlgItemMessage(hWnd,IDC_FOGSTART,WM_SETTEXT,0,(LPARAM)_T("0.0"));
1804 - SendDlgItemMessage(hWnd,IDC_FOGEND,WM_SETTEXT,0,(LPARAM)_T("1.0"));
1805 - SendDlgItemMessage(hWnd,IDC_FOGDENSITY,WM_SETTEXT,0,(LPARAM)_T("1.0"));
1806 - SendDlgItemMessage(hWnd,IDC_FILLMODE,CB_ADDSTRING,0,(LPARAM)_T("Points"));
1807 - SendDlgItemMessage(hWnd,IDC_FILLMODE,CB_ADDSTRING,0,(LPARAM)_T("Wireframe"));
1808 - SendDlgItemMessage(hWnd,IDC_FILLMODE,CB_ADDSTRING,0,(LPARAM)_T("Solid"));
1809 - SendDlgItemMessage(hWnd,IDC_FILLMODE,CB_SETCURSEL,2,0);
1810 - SendDlgItemMessage(hWnd,IDC_SHADEMODE,CB_ADDSTRING,0,(LPARAM)_T("Flat"));
1811 - SendDlgItemMessage(hWnd,IDC_SHADEMODE,CB_ADDSTRING,0,(LPARAM)_T("Gouraud"));
1812 - SendDlgItemMessage(hWnd,IDC_SHADEMODE,CB_ADDSTRING,0,(LPARAM)_T("Phong"));
1813 - SendDlgItemMessage(hWnd,IDC_SHADEMODE,CB_SETCURSEL,1,0);
1814 - SendDlgItemMessage(hWnd,IDC_CULLMODE,CB_ADDSTRING,0,(LPARAM)_T("None"));
1815 - SendDlgItemMessage(hWnd,IDC_CULLMODE,CB_ADDSTRING,0,(LPARAM)_T("CW"));
1816 - SendDlgItemMessage(hWnd,IDC_CULLMODE,CB_ADDSTRING,0,(LPARAM)_T("CCW"));
1817 - SendDlgItemMessage(hWnd,IDC_CULLMODE,CB_SETCURSEL,2,0);
1818 - SendDlgItemMessage(hWnd,IDC_VERTEXCOLOR,BM_SETCHECK,BST_CHECKED,0);
1819 - PopulateSourceCombo(GetDlgItem(hWnd,IDC_DIFFUSESOURCE));
1820 - PopulateSourceCombo(GetDlgItem(hWnd,IDC_SPECULARSOURCE));
1821 - PopulateSourceCombo(GetDlgItem(hWnd,IDC_AMBIENTSOURCE));
1822 - PopulateSourceCombo(GetDlgItem(hWnd,IDC_EMISSIVESOURCE));
1823 - SendDlgItemMessage(hWnd,IDC_DIFFUSESOURCE,CB_SETCURSEL,D3DMCS_COLOR1,0);
1824 - SendDlgItemMessage(hWnd,IDC_SPECULARSOURCE,CB_SETCURSEL,D3DMCS_COLOR2,0);
1825 - SendDlgItemMessage(hWnd,IDC_AMBIENTSOURCE,CB_SETCURSEL,D3DMCS_MATERIAL,0);
1826 - SendDlgItemMessage(hWnd,IDC_EMISSIVESOURCE,CB_SETCURSEL,D3DMCS_MATERIAL,0);
1827 - SendDlgItemMessage(hWnd,IDC_SPINDETAIL,UDM_SETRANGE32,2,64);
1828 - SendDlgItemMessage(hWnd,IDC_SPINDETAIL,UDM_SETPOS32,0,8);
1829 - SendDlgItemMessage(hWnd,IDC_SPINLIGHT,UDM_SETRANGE32,0,7);
1830 - SendDlgItemMessage(hWnd,IDC_LIGHTDIFFUSE,WM_SETTEXT,0,(LPARAM)_T("00FFFFFF"));
1831 - SendDlgItemMessage(hWnd,IDC_LIGHTAMBIENT,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1832 - SendDlgItemMessage(hWnd,IDC_LIGHTSPECULAR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
1833 - SendDlgItemMessage(hWnd,IDC_LIGHTRANGE,WM_SETTEXT,0,(LPARAM)_T("0"));
1834 - SendDlgItemMessage(hWnd,IDC_LIGHTFALLOFF,WM_SETTEXT,0,(LPARAM)_T("0"));
1835 - SendDlgItemMessage(hWnd,IDC_LIGHTTHETA,WM_SETTEXT,0,(LPARAM)_T("0"));
1836 - SendDlgItemMessage(hWnd,IDC_LIGHTPHI,WM_SETTEXT,0,(LPARAM)_T("0"));
1837 - SendDlgItemMessage(hWnd,IDC_LIGHTATTEN0,WM_SETTEXT,0,(LPARAM)_T("0"));
1838 - SendDlgItemMessage(hWnd,IDC_LIGHTATTEN1,WM_SETTEXT,0,(LPARAM)_T("0"));
1839 - SendDlgItemMessage(hWnd,IDC_LIGHTATTEN2,WM_SETTEXT,0,(LPARAM)_T("0"));
1840 - SendDlgItemMessage(hWnd,IDC_POWER,WM_SETTEXT,0,(LPARAM)_T("0"));
1841 - SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_ADDSTRING,0,(LPARAM)_T("Point"));
1842 - SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_ADDSTRING,0,(LPARAM)_T("Spot"));
1843 - SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_ADDSTRING,0,(LPARAM)_T("Directional"));
1844 - SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_ADDSTRING,0,(LPARAM)_T("Parallel Point"));
1845 - SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_ADDSTRING,0,(LPARAM)_T("GL Spot"));
1846 - SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_SETCURSEL,D3DLIGHT_DIRECTIONAL-1,0);
1847 - SendDlgItemMessage(hWnd,IDC_LIGHTENABLED,BM_SETCHECK,BST_CHECKED,0);
1848 - ::width = ddsd.dwWidth;
1849 - ::height = ddsd.dwHeight;
1850 - vertexshaderstate.texture = NULL;
1851 - vertexshaderstate.texturefile[0] = 0;
1852 - vertexshaderstate.texturetype = 0;
1853 - vertexshaderstate.currentlight = 0;
1854 - StartTimer(hWnd,WM_APP,60);
1855 - break;
1856 - case WM_COMMAND:
1857 - switch(LOWORD(wParam))
1858 - {
1859 - case IDC_TEXTURE:
1860 - if(HIWORD(wParam) == CBN_SELCHANGE)
1861 - {
1862 - number = texshaderstate.currentstage;
1863 - vertexshaderstate.texturetype =
1864 - SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_GETCURSEL,0,0);
1865 - SelectTexture(&vertexshaderstate.texture,vertexshaderstate.texturetype,
1866 - 0, FALSE,vertexshaderstate.texturefile);
1867 - if((vertexshaderstate.texturetype == 2) || (vertexshaderstate.texturetype == 3))
1868 - d3d7dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_BLENDTEXTUREALPHAPM);
1869 - else d3d7dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
1870 - }
1871 - break;
1872 - case IDC_TEXTUREFILE:
1873 - if(HIWORD(wParam) == EN_KILLFOCUS)
1874 - {
1875 - number = texshaderstate.currentstage;
1876 - SendDlgItemMessage(hWnd,IDC_TEXTUREFILE,WM_GETTEXT,MAX_PATH+1,
1877 - (LPARAM)vertexshaderstate.texturefile);
1878 - SelectTexture(&vertexshaderstate.texture,vertexshaderstate.texturetype,
1879 - 0, FALSE,vertexshaderstate.texturefile);
1880 - }
1881 - break;
1882 - case IDC_FOGENABLE:
1883 - if(HIWORD(wParam) == BN_CLICKED)
1884 - {
1885 - if(SendDlgItemMessage(hWnd,IDC_FOGENABLE,BM_GETCHECK,0,0) == BST_CHECKED)
1886 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE,TRUE);
1887 - else d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE,FALSE);
1888 - }
1889 - break;
1890 - case IDC_VERTEXFOGMODE:
1891 - if(HIWORD(wParam) == CBN_SELCHANGE)
1892 - {
1893 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE,SendDlgItemMessage(hWnd,
1894 - IDC_VERTEXFOGMODE,CB_GETCURSEL,0,0));
1895 - }
1896 - break;
1897 - case IDC_PIXELFOGMODE:
1898 - if(HIWORD(wParam) == CBN_SELCHANGE)
1899 - {
1900 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE,SendDlgItemMessage(hWnd,
1901 - IDC_PIXELFOGMODE,CB_GETCURSEL,0,0));
1902 - }
1903 - break;
1904 - case IDC_FOGSTART:
1905 - if(HIWORD(wParam) == EN_CHANGE)
1906 - {
1907 - SendDlgItemMessage(hWnd,IDC_FOGSTART,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1908 - f = (float)_ttof(tmpstring);
1909 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGSTART, *((LPDWORD)(&f)));
1910 - }
1911 - break;
1912 - case IDC_FOGEND:
1913 - if(HIWORD(wParam) == EN_CHANGE)
1914 - {
1915 - SendDlgItemMessage(hWnd,IDC_FOGEND,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1916 - f = (float)_ttof(tmpstring);
1917 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGEND, *((LPDWORD)(&f)));
1918 - }
1919 - break;
1920 - case IDC_FOGDENSITY:
1921 - if(HIWORD(wParam) == EN_CHANGE)
1922 - {
1923 - SendDlgItemMessage(hWnd,IDC_FOGDENSITY,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1924 - f = (float)_ttof(tmpstring);
1925 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGDENSITY, *((LPDWORD)(&f)));
1926 - }
1927 - break;
1928 - case IDC_RANGEBASEDFOG:
1929 - if(HIWORD(wParam) == BN_CLICKED)
1930 - {
1931 - if(SendDlgItemMessage(hWnd,IDC_RANGEBASEDFOG,BM_GETCHECK,0,0) == BST_CHECKED)
1932 - d3d7dev->SetRenderState(D3DRENDERSTATE_RANGEFOGENABLE,TRUE);
1933 - else d3d7dev->SetRenderState(D3DRENDERSTATE_RANGEFOGENABLE,FALSE);
1934 - }
1935 - break;
1936 - case IDC_FILLMODE:
1937 - if(HIWORD(wParam) == CBN_SELCHANGE)
1938 - {
1939 - d3d7dev->SetRenderState(D3DRENDERSTATE_FILLMODE,SendDlgItemMessage(hWnd,
1940 - IDC_FILLMODE,CB_GETCURSEL,0,0)+1);
1941 - }
1942 - break;
1943 - case IDC_SHADEMODE:
1944 - if(HIWORD(wParam) == CBN_SELCHANGE)
1945 - {
1946 - d3d7dev->SetRenderState(D3DRENDERSTATE_SHADEMODE,SendDlgItemMessage(hWnd,
1947 - IDC_SHADEMODE,CB_GETCURSEL,0,0)+1);
1948 - }
1949 - break;
1950 - case IDC_CULLMODE:
1951 - if(HIWORD(wParam) == CBN_SELCHANGE)
1952 - {
1953 - d3d7dev->SetRenderState(D3DRENDERSTATE_CULLMODE,SendDlgItemMessage(hWnd,
1954 - IDC_CULLMODE,CB_GETCURSEL,0,0)+1);
1955 - }
1956 - break;
1957 - case IDC_DIFFUSE:
1958 - if(HIWORD(wParam) == EN_CHANGE)
1959 - {
1960 - SendDlgItemMessage(hWnd,IDC_DIFFUSE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1961 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
1962 - SetVertexColor(litvertices,colorvertices,numpoints,number);
1963 - }
1964 - break;
1965 - case IDC_SPECULAR:
1966 - if(HIWORD(wParam) == EN_CHANGE)
1967 - {
1968 - SendDlgItemMessage(hWnd,IDC_SPECULAR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1969 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
1970 - SetVertexSpecular(litvertices,colorvertices,numpoints,number);
1971 - }
1972 - break;
1973 - case IDC_FACTOR:
1974 - if(HIWORD(wParam) == EN_CHANGE)
1975 - {
1976 - SendDlgItemMessage(hWnd,IDC_FACTOR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1977 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
1978 - d3d7dev->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR,number);
1979 - }
1980 - break;
1981 - case IDC_FOGCOLOR:
1982 - if(HIWORD(wParam) == EN_CHANGE)
1983 - {
1984 - SendDlgItemMessage(hWnd,IDC_FOGCOLOR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1985 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
1986 - d3d7dev->SetRenderState(D3DRENDERSTATE_FOGCOLOR,number);
1987 - }
1988 - break;
1989 - case IDC_BGCOLOR:
1990 - if(HIWORD(wParam) == EN_CHANGE)
1991 - {
1992 - SendDlgItemMessage(hWnd,IDC_BGCOLOR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1993 - if(!_stscanf(tmpstring,_T("%x"),&bgcolor)) bgcolor = 0;
1994 - }
1995 - break;
1996 - case IDC_AMBIENT:
1997 - {
1998 - SendDlgItemMessage(hWnd,IDC_AMBIENT,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
1999 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
2000 - d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT,number);
2001 - }
2002 - break;
2003 - case IDC_EMISSIVE:
2004 - if(HIWORD(wParam) == EN_CHANGE)
2005 - {
2006 - SendDlgItemMessage(hWnd,IDC_EMISSIVE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
2007 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
2008 - material.emissive.b = (float)(number & 255) / 255.0;
2009 - material.emissive.g = (float)((number>>8) & 255) / 255.0;
2010 - material.emissive.r = (float)((number>>16) & 255) / 255.0;
2011 - material.emissive.a = (float)((number>>24) & 255) / 255.0;
2012 - d3d7dev->SetMaterial(&material);
2013 - }
2014 - break;
2015 - case IDC_MATAMBIENT:
2016 - if(HIWORD(wParam) == EN_CHANGE)
2017 - {
2018 - SendDlgItemMessage(hWnd,IDC_MATAMBIENT,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
2019 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
2020 - material.ambient.b = (float)(number & 255) / 255.0;
2021 - material.ambient.g = (float)((number>>8) & 255) / 255.0;
2022 - material.ambient.r = (float)((number>>16) & 255) / 255.0;
2023 - material.ambient.a = (float)((number>>24) & 255) / 255.0;
2024 - d3d7dev->SetMaterial(&material);
2025 - }
2026 - break;
2027 - case IDC_MATDIFFUSE:
2028 - if(HIWORD(wParam) == EN_CHANGE)
2029 - {
2030 - SendDlgItemMessage(hWnd,IDC_MATDIFFUSE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
2031 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
2032 - material.diffuse.b = (float)(number & 255) / 255.0;
2033 - material.diffuse.g = (float)((number>>8) & 255) / 255.0;
2034 - material.diffuse.r = (float)((number>>16) & 255) / 255.0;
2035 - material.diffuse.a = (float)((number>>24) & 255) / 255.0;
2036 - d3d7dev->SetMaterial(&material);
2037 - }
2038 - break;
2039 - case IDC_MATSPECULAR:
2040 - if(HIWORD(wParam) == EN_CHANGE)
2041 - {
2042 - SendDlgItemMessage(hWnd,IDC_MATSPECULAR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
2043 - if(!_stscanf(tmpstring,_T("%x"),&number)) number = 0;
2044 - material.specular.b = (float)(number & 255) / 255.0;
2045 - material.specular.g = (float)((number>>8) & 255) / 255.0;
2046 - material.specular.r = (float)((number>>16) & 255) / 255.0;
2047 - material.specular.a = (float)((number>>24) & 255) / 255.0;
2048 - d3d7dev->SetMaterial(&material);
2049 - }
2050 - break;
2051 - case IDC_POWER:
2052 - if(HIWORD(wParam) == EN_CHANGE)
2053 - {
2054 - SendDlgItemMessage(hWnd,IDC_POWER,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
2055 - material.power = (float)_ttof(tmpstring);
2056 - d3d7dev->SetMaterial(&material);
2057 - }
2058 - break;
2059 - case IDC_ENABLELIGHT:
2060 - if(HIWORD(wParam) == BN_CLICKED)
2061 - {
2062 - if(SendDlgItemMessage(hWnd,IDC_ENABLELIGHT,BM_GETCHECK,0,0) == BST_CHECKED)
2063 - {
2064 - d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING,TRUE);
2065 - for(int i = 0; i < 8; i++)
2066 - {
2067 - d3d7dev->SetLight(i,&lights[i]);
2068 - d3d7dev->LightEnable(i,lightenable[i]);
2069 - }
2070 - }
2071 - else d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING,FALSE);
2072 - }
2073 - break;
2074 - case IDC_VERTEXCOLOR:
2075 - if(HIWORD(wParam) == BN_CLICKED)
2076 - {
2077 - if(SendDlgItemMessage(hWnd,IDC_VERTEXCOLOR,BM_GETCHECK,0,0) == BST_CHECKED)
2078 - d3d7dev->SetRenderState(D3DRENDERSTATE_COLORVERTEX,TRUE);
2079 - else d3d7dev->SetRenderState(D3DRENDERSTATE_COLORVERTEX,FALSE);
2080 - }
2081 - break;
2082 - case IDC_DETAIL:
2083 - if(HIWORD(wParam) == EN_CHANGE)
2084 - {
2085 - SendDlgItemMessage(hWnd,IDC_DETAIL,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
2086 - number = _ttoi(tmpstring);
2087 - if(number < 2) SendDlgItemMessage(hWnd,IDC_DETAIL,WM_SETTEXT,0,(LPARAM)_T("2"));
2088 - if(number > 64) SendDlgItemMessage(hWnd,IDC_DETAIL,WM_SETTEXT,0,(LPARAM)_T("64"));
2089 - MakeCube3D(5,number);
2090 - }
2091 - break;
2092 - case IDC_DIFFUSESOURCE:
2093 - if(HIWORD(wParam) == CBN_SELCHANGE)
2094 - {
2095 - d3d7dev->SetRenderState(D3DRENDERSTATE_DIFFUSEMATERIALSOURCE,SendDlgItemMessage(hWnd,
2096 - IDC_DIFFUSESOURCE,CB_GETCURSEL,0,0));
2097 - }
2098 - break;
2099 - case IDC_SPECULARSOURCE:
2100 - if(HIWORD(wParam) == CBN_SELCHANGE)
2101 - {
2102 - d3d7dev->SetRenderState(D3DRENDERSTATE_SPECULARMATERIALSOURCE,SendDlgItemMessage(hWnd,
2103 - IDC_SPECULARSOURCE,CB_GETCURSEL,0,0));
2104 - }
2105 - break;
2106 - case IDC_AMBIENTSOURCE:
2107 - if(HIWORD(wParam) == CBN_SELCHANGE)
2108 - {
2109 - d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE,SendDlgItemMessage(hWnd,
2110 - IDC_AMBIENTSOURCE,CB_GETCURSEL,0,0));
2111 - }
2112 - break;
2113 - case IDC_EMISSIVESOURCE:
2114 - if(HIWORD(wParam) == CBN_SELCHANGE)
2115 - {
2116 - d3d7dev->SetRenderState(D3DRENDERSTATE_EMISSIVEMATERIALSOURCE,SendDlgItemMessage(hWnd,
2117 - IDC_EMISSIVESOURCE,CB_GETCURSEL,0,0));
2118 - }
2119 - break;
2120 - case IDC_LIGHTNUMBER:
2121 - if(HIWORD(wParam) == EN_CHANGE)
2122 - {
2123 - SendDlgItemMessage(hWnd,IDC_LIGHTNUMBER,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
2124 - number = _ttoi(tmpstring);
2125 - if(number < 0) SendDlgItemMessage(hWnd,IDC_LIGHTNUMBER,WM_SETTEXT,0,(LPARAM)_T("0"));
2126 - if(number > 7) SendDlgItemMessage(hWnd,IDC_LIGHTNUMBER,WM_SETTEXT,0,(LPARAM)_T("7"));
2127 - vertexshaderstate.currentlight = number;
2128 - _itot(hexlightcolor[vertexshaderstate.currentlight].ambient,tmpstring,16);
2129 - strupper(tmpstring); paddwordzeroes(tmpstring);
2130 - SendDlgItemMessage(hWnd,IDC_LIGHTAMBIENT,WM_SETTEXT,0,(LPARAM)tmpstring);
2131 - _itot(hexlightcolor[vertexshaderstate.currentlight].diffuse,tmpstring,16);
2132 - strupper(tmpstring); paddwordzeroes(tmpstring);
2133 - SendDlgItemMessage(hWnd,IDC_LIGHTDIFFUSE,WM_SETTEXT,0,(LPARAM)tmpstring);
2134 - _itot(hexlightcolor[vertexshaderstate.currentlight].specular,tmpstring,16);
2135 - strupper(tmpstring); paddwordzeroes(tmpstring);
2136 - SendDlgItemMessage(hWnd,IDC_LIGHTSPECULAR,WM_SETTEXT,0,(LPARAM)tmpstring);
2137 - SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_SETCURSEL,lights[vertexshaderstate.currentlight].dltType-1,0);
2138 - if(lightenable[vertexshaderstate.currentlight])
2139 - SendDlgItemMessage(hWnd,IDC_LIGHTENABLED,BM_SETCHECK,BST_CHECKED,0);
2140 - else SendDlgItemMessage(hWnd,IDC_LIGHTENABLED,BM_SETCHECK,BST_UNCHECKED,0);
2141 - }
2142 - break;
2143 - case IDC_LIGHTENABLED:
2144 - if(HIWORD(wParam) == BN_CLICKED)
2145 - {
2146 - if(SendDlgItemMessage(hWnd,IDC_LIGHTENABLED,BM_GETCHECK,0,0) == BST_CHECKED)
2147 - {
2148 - lightenable[vertexshaderstate.currentlight] = TRUE;
2149 - d3d7dev->LightEnable(vertexshaderstate.currentlight,TRUE);
2150 - }
2151 - else
2152 - {
2153 - lightenable[vertexshaderstate.currentlight] = FALSE;
2154 - d3d7dev->LightEnable(vertexshaderstate.currentlight,FALSE);
2155 - }
2156 - }
2157 - break;
2158 - case IDC_LIGHTTYPE:
2159 - if(HIWORD(wParam) == CBN_SELCHANGE)
2160 - {
2161 - lights[vertexshaderstate.currentlight].dltType = (D3DLIGHTTYPE)
2162 - (SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_GETCURSEL,0,0) + 1);
2163 - d3d7dev->SetLight(vertexshaderstate.currentlight,&lights[vertexshaderstate.currentlight]);
2164 - }
2165 - break;
2166 - case IDC_LIGHTRANGE:
2167 - if(HIWORD(wParam) == EN_CHANGE)
2168 - {
2169 - SendDlgItemMessage(hWnd,IDC_LIGHTRANGE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
2170 - lights[vertexshaderstate.currentlight].dvRange = (float)_ttof(tmpstring);
2171 - d3d7dev->SetLight(vertexshaderstate.currentlight,&lights[vertexshaderstate.currentlight]);
2172 - }
2173 - break;
2174 - default:
2175 - return FALSE;
2176 - }
2177 - break;
2178 - case WM_CLOSE:
2179 - if(d3d7dev)
2180 - {
2181 - d3d7dev->Release();
2182 - d3d7dev = NULL;
2183 - }
2184 - if(d3d7)
2185 - {
2186 - d3d7->Release();
2187 - d3d7dev = NULL;
2188 - }
2189 - if(ddsrender)
2190 - {
2191 - ddsrender->Release();
2192 - ddsrender = NULL;
2193 - }
2194 - if(ddsurface)
2195 - {
2196 - ddsurface->Release();
2197 - ddsurface = NULL;
2198 - }
2199 - if(zbuffer)
2200 - {
2201 - zbuffer->Release();
2202 - zbuffer = NULL;
2203 - }
2204 - if(ddclipper)
2205 - {
2206 - ddclipper->Release();
2207 - ddclipper = NULL;
2208 - }
2209 - if(ddinterface)
2210 - {
2211 - ddinterface->Release();
2212 - ddinterface = NULL;
2213 - }
2214 - if(mesh)
2215 - {
2216 - free(mesh);
2217 - mesh = NULL;
2218 - }
2219 - if(vertices)
2220 - {
2221 - free(vertices);
2222 - vertices = NULL;
2223 - }
2224 - if(litvertices)
2225 - {
2226 - free(litvertices);
2227 - litvertices = NULL;
2228 - }
2229 - if(colorvertices)
2230 - {
2231 - free(colorvertices);
2232 - colorvertices = NULL;
2233 - }
2234 - EndDialog(hWnd,IDCANCEL);
2235 - break;
2236 - case WM_APP:
2237 - RunTestTimed3D(testnum);
2238 - break;
2239 - default:
2240 - return FALSE;
2241 - }
2242 - return TRUE;
2243 -}
Index: dxgltest/Tests2D.cpp
——@@ -1,1193 +0,0 @@
2 -// DXGL
3 -// Copyright (C) 2011 William Feely
4 -
5 -// This library is free software; you can redistribute it and/or
6 -// modify it under the terms of the GNU Lesser General Public
7 -// License as published by the Free Software Foundation; either
8 -// version 2.1 of the License, or (at your option) any later version.
9 -
10 -// This library is distributed in the hope that it will be useful,
11 -// but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 -// Lesser General Public License for more details.
14 -
15 -// You should have received a copy of the GNU Lesser General Public
16 -// License along with this library; if not, write to the Free Software
17 -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 -
19 -#include "common.h"
20 -#include "MultiDD.h"
21 -#include "tests.h"
22 -#include "surfacegen.h"
23 -#include "timer.h"
24 -#include "misc.h"
25 -
26 -void InitTest2D(int test);
27 -void RunTestTimed2D(int test);
28 -void RunTestLooped2D(int test);
29 -void RunTestMouse2D(int test, UINT Msg, WPARAM wParam, LPARAM lParam);
30 -
31 -
32 -static MultiDirectDraw *ddinterface;
33 -static MultiDirectDrawSurface *ddsurface;
34 -static MultiDirectDrawSurface *ddsrender;
35 -static IDirectDrawPalette *pal;
36 -static LPDIRECTDRAWCLIPPER ddclipper;
37 -static int width,height,bpp,refresh,backbuffers;
38 -static double fps;
39 -static bool fullscreen,resizable;
40 -static HWND hWnd;
41 -static int testnum;
42 -static unsigned int randnum;
43 -static int testtypes[] = {0,1,0,1,0,1,2,0,2,1};
44 -static DWORD counter;
45 -
46 -static DDSPRITE sprites[16];
47 -
48 -LRESULT CALLBACK DDWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
49 -{
50 - bool paintwnd = true;
51 - POINT p;
52 - RECT srcrect,destrect;
53 - HRESULT error;
54 - PAINTSTRUCT paintstruct;
55 - switch(Msg)
56 - {
57 - case WM_CLOSE:
58 - DestroyWindow(hWnd);
59 - break;
60 - case WM_DESTROY:
61 - StopTimer();
62 - for(int i = 0; i < 16; i++)
63 - if(sprites[i].surface) sprites[i].surface->Release();
64 - if(ddsrender)
65 - {
66 - ddsrender->Release();
67 - ddsrender = NULL;
68 - }
69 - if(ddsurface)
70 - {
71 - ddsurface->Release();
72 - ddsurface = NULL;
73 - }
74 - if(pal)
75 - {
76 - pal->Release();
77 - pal = NULL;
78 - }
79 - if(ddclipper)
80 - {
81 - ddclipper->Release();
82 - ddclipper = NULL;
83 - }
84 - if(ddinterface)
85 - {
86 - ddinterface->Release();
87 - ddinterface = NULL;
88 - }
89 - PostQuitMessage(0);
90 - break;
91 - case WM_KEYDOWN:
92 - if(wParam == VK_ESCAPE) DestroyWindow(hWnd);
93 - break;
94 - case WM_APP:
95 - RunTestTimed2D(testnum);
96 - break;
97 - case WM_SIZE:
98 - paintwnd = false;
99 - case WM_PAINT:
100 - if(paintwnd) BeginPaint(hWnd,&paintstruct);
101 - if(!fullscreen)
102 - {
103 - p.x = 0;
104 - p.y = 0;
105 - ClientToScreen(hWnd,&p);
106 - GetClientRect(hWnd,&destrect);
107 - OffsetRect(&destrect,p.x,p.y);
108 - SetRect(&srcrect,0,0,width,height);
109 - if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
110 - }
111 - if(paintwnd) EndPaint(hWnd,&paintstruct);
112 - return 0;
113 - case WM_MOUSEMOVE:
114 - case WM_LBUTTONDOWN:
115 - case WM_LBUTTONUP:
116 - case WM_LBUTTONDBLCLK:
117 - case WM_RBUTTONDOWN:
118 - case WM_RBUTTONUP:
119 - case WM_RBUTTONDBLCLK:
120 - case WM_MBUTTONDOWN:
121 - case WM_MBUTTONUP:
122 - case WM_MBUTTONDBLCLK:
123 - case WM_MOUSEWHEEL:
124 - case WM_XBUTTONDOWN:
125 - case WM_XBUTTONUP:
126 - case WM_XBUTTONDBLCLK:
127 - case WM_MOUSEHWHEEL:
128 - RunTestMouse2D(testnum,Msg,wParam,lParam);
129 - if(!fullscreen)
130 - {
131 - if ((testnum != 4) && (testnum != 10) && (testnum != 11))
132 - {
133 - p.x = 0;
134 - p.y = 0;
135 - ClientToScreen(hWnd, &p);
136 - GetClientRect(hWnd, &destrect);
137 - OffsetRect(&destrect, p.x, p.y);
138 - SetRect(&srcrect, 0, 0, width, height);
139 - if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
140 - }
141 - }
142 - break;
143 - default:
144 - return DefWindowProc(hWnd,Msg,wParam,lParam);
145 - }
146 - return FALSE;
147 -}
148 -
149 -static int ddtestnum;
150 -static int ddver;
151 -
152 -void RunTestMouse2D(int test, UINT Msg, WPARAM wParam, LPARAM lParam)
153 -{
154 - if(!ddsrender) return;
155 - DDSURFACEDESC2 ddsd;
156 - ddsd.dwSize = sizeof(DDSURFACEDESC2);
157 - DDBLTFX bltfx;
158 - unsigned char *surface;
159 - int bytes;
160 - unsigned int x,y;
161 - bool out = false;
162 - bool msgbottom = false;
163 - TCHAR message[256];
164 - message[0] = 0;
165 - HDC hDC;
166 - switch(test)
167 - {
168 - case 6:
169 - x = LOWORD(lParam);
170 - y = HIWORD(lParam);
171 - ZeroMemory(&bltfx,sizeof(DDBLTFX));
172 - bltfx.dwSize = sizeof(DDBLTFX);
173 - bltfx.dwFillColor = 0;
174 - ddsrender->Blt(NULL,NULL,NULL,DDBLT_COLORFILL,&bltfx);
175 - if(ddver > 3)ddsd.dwSize = sizeof(DDSURFACEDESC2);
176 - else ddsd.dwSize = sizeof(DDSURFACEDESC);
177 - ddsrender->GetSurfaceDesc(&ddsd);
178 - switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
179 - {
180 - case 8:
181 - bytes=1;
182 - break;
183 - case 15:
184 - case 16:
185 - bytes=2;
186 - break;
187 - case 24:
188 - bytes=3;
189 - break;
190 - case 32:
191 - default:
192 - bytes=4;
193 - }
194 - _tcscpy(message,_T("Message: "));
195 - switch(Msg)
196 - {
197 - case WM_MOUSEMOVE:
198 - _tcscat(message,_T("WM_MOUSEMOVE "));
199 - break;
200 - case WM_LBUTTONDOWN:
201 - _tcscat(message,_T("WM_LBUTTONDOWN "));
202 - break;
203 - case WM_LBUTTONUP:
204 - _tcscat(message,_T("WM_LBUTTONUP "));
205 - break;
206 - case WM_LBUTTONDBLCLK:
207 - _tcscat(message,_T("WM_LBUTTONDBLCLK "));
208 - break;
209 - case WM_RBUTTONDOWN:
210 - _tcscat(message,_T("WM_RBUTTONDOWN "));
211 - break;
212 - case WM_RBUTTONUP:
213 - _tcscat(message,_T("WM_RBUTTONUP "));
214 - break;
215 - case WM_RBUTTONDBLCLK:
216 - _tcscat(message,_T("WM_RBUTTONDBLCLK "));
217 - break;
218 - case WM_MBUTTONDOWN:
219 - _tcscat(message,_T("WM_MBUTTONDOWN "));
220 - break;
221 - case WM_MBUTTONUP:
222 - _tcscat(message,_T("WM_MBUTTONUP "));
223 - break;
224 - case WM_MBUTTONDBLCLK:
225 - _tcscat(message,_T("WM_MBUTTONDBLCLK "));
226 - break;
227 - case WM_MOUSEWHEEL:
228 - _tcscat(message,_T("WM_MOUSEWHEEL "));
229 - break;
230 - case WM_XBUTTONDOWN:
231 - _tcscat(message,_T("WM_XBUTTONDOWN "));
232 - break;
233 - case WM_XBUTTONUP:
234 - _tcscat(message,_T("WM_XBUTTONUP "));
235 - break;
236 - case WM_XBUTTONDBLCLK:
237 - _tcscat(message,_T("WM_XBUTTONDBLCLK "));
238 - break;
239 - case WM_MOUSEHWHEEL:
240 - _tcscat(message,_T("WM_MOUSEHWHEEL "));
241 - break;
242 - default:
243 - _tcscat(message,_T("unknown "));
244 - }
245 - _tcscat(message,_T("Keys: "));
246 - if(wParam & MK_CONTROL) _tcscat(message, _T("CTRL "));
247 - if(wParam & MK_SHIFT) _tcscat(message,_T("SHIFT "));
248 - _tcscat(message,_T("Buttons: "));
249 - if(wParam & MK_LBUTTON) _tcscat(message,_T("L "));
250 - if(wParam & MK_MBUTTON) _tcscat(message,_T("M "));
251 - if(wParam & MK_RBUTTON) _tcscat(message,_T("R "));
252 - if(wParam & MK_XBUTTON1) _tcscat(message,_T("X1 "));
253 - if(wParam & MK_XBUTTON2) _tcscat(message,_T("X2 "));
254 - // Add X and Y
255 - ddsrender->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
256 - surface = (unsigned char *)ddsd.lpSurface;
257 - if((x > ddsd.dwWidth) || (y > ddsd.dwHeight))
258 - {
259 - out = true;
260 - _tcscat(message,_T(" OUT OF BOUNDS"));
261 - }
262 - else surface[(x*bytes)+(y*ddsd.lPitch)] = 0xFF;
263 - ddsrender->Unlock(NULL);
264 - ddsrender->GetDC(&hDC);
265 - if(out)SetBkColor(hDC,RGB(255,0,0));
266 - else SetBkColor(hDC,RGB(0,0,255));
267 - SetTextColor(hDC,RGB(255,255,255));
268 - if(y > ddsd.dwHeight / 2) TextOut(hDC,0,0,message,_tcslen(message));
269 - else TextOut(hDC,0,ddsd.dwHeight-16,message,_tcslen(message));
270 - ddsrender->ReleaseDC(hDC);
271 - break;
272 - default:
273 - break;
274 - }
275 -}
276 -
277 -const TCHAR wndclassname2d[] = _T("DDTestWndClass");
278 -void RunTest2D(int testnum, int width, int height, int bpp, int refresh, int backbuffers, int apiver,
279 - double fps, bool fullscreen, bool resizable)
280 -{
281 - ZeroMemory(sprites,16*sizeof(DDSPRITE));
282 - DDSURFACEDESC2 ddsd;
283 - BOOL done = false;
284 - ::testnum = testnum;
285 - randnum = (unsigned int)time(NULL);
286 - ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
287 - if(apiver > 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
288 - else ddsd.dwSize = sizeof(DDSURFACEDESC);
289 - ::fullscreen = fullscreen;
290 - ::resizable = resizable;
291 - ::width = width;
292 - ::height = height;
293 - ::bpp = bpp;
294 - ::refresh = refresh;
295 - if(fullscreen)::backbuffers = backbuffers;
296 - else ::backbuffers = backbuffers = 0;
297 - ::fps = fps;
298 - ddtestnum = testnum;
299 - ddver = apiver;
300 - HINSTANCE hinstance = (HINSTANCE)GetModuleHandle(NULL);
301 - WNDCLASSEX wc;
302 - MSG Msg;
303 - ZeroMemory(&wc,sizeof(WNDCLASS));
304 - wc.cbSize = sizeof(WNDCLASSEX);
305 - wc.style = CS_HREDRAW | CS_VREDRAW;
306 - wc.lpfnWndProc = DDWndProc;
307 - wc.hInstance = hinstance;
308 - wc.hIcon = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_DXGL));
309 - wc.hIconSm = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_DXGLSM));
310 - if(testnum == 6) wc.hCursor = LoadCursor(NULL,IDC_CROSS);
311 - else wc.hCursor = LoadCursor(NULL,IDC_ARROW);
312 - wc.hbrBackground = NULL;
313 - wc.lpszClassName = wndclassname2d;
314 - if(!RegisterClassEx(&wc))
315 - {
316 - MessageBox(NULL,_T("Can not register window class"),_T("Error"),MB_ICONEXCLAMATION|MB_OK);
317 - return;
318 - }
319 - if(resizable)
320 - hWnd = CreateWindowEx(WS_EX_APPWINDOW,wndclassname2d,_T("DDraw Test Window"),WS_OVERLAPPEDWINDOW,
321 - CW_USEDEFAULT,CW_USEDEFAULT,width,height,NULL,NULL,hinstance,NULL);
322 - else if(!fullscreen)
323 - hWnd = CreateWindowEx(WS_EX_APPWINDOW,wndclassname2d,_T("DDraw Test Window"),WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
324 - CW_USEDEFAULT,CW_USEDEFAULT,width,height,NULL,NULL,hinstance,NULL);
325 - else hWnd = CreateWindowEx(0,wndclassname2d,_T("DDraw Test Window"),WS_POPUP,0,0,
326 - GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hinstance,NULL);
327 - DWORD err = GetLastError();
328 - ShowWindow(hWnd,SW_SHOWNORMAL);
329 - UpdateWindow(hWnd);
330 - RECT r1,r2;
331 - POINT p1;
332 - HRESULT error;
333 - ddinterface = new MultiDirectDraw(ddver,&error,NULL);
334 - if(fullscreen) error = ddinterface->SetCooperativeLevel(hWnd,DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN);
335 - else error = ddinterface->SetCooperativeLevel(hWnd,DDSCL_NORMAL);
336 - if(fullscreen) error = ddinterface->SetDisplayMode(width,height,bpp,refresh,0);
337 - else
338 - {
339 - GetClientRect(hWnd,&r1);
340 - GetWindowRect(hWnd,&r2);
341 - p1.x = (r2.right - r2.left) - r1.right;
342 - p1.y = (r2.bottom - r2.top) - r1.bottom;
343 - MoveWindow(hWnd,r2.left,r2.top,width+p1.x,height+p1.y,TRUE);
344 - }
345 - ddsd.dwFlags = DDSD_CAPS;
346 - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
347 - if(fullscreen)
348 - {
349 - if(backbuffers)ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
350 - ddsd.dwBackBufferCount = backbuffers;
351 - if(backbuffers) ddsd.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
352 - }
353 - error = ddinterface->CreateSurface(&ddsd,&ddsurface,NULL);
354 - if(!fullscreen)
355 - {
356 - error = ddinterface->CreateClipper(0,&ddclipper,NULL);
357 - error = ddclipper->SetHWnd(0,hWnd);
358 - error = ddsurface->SetClipper(ddclipper);
359 - ZeroMemory(&ddsd,sizeof(ddsd));
360 - if(apiver > 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
361 - else ddsd.dwSize = sizeof(DDSURFACEDESC);
362 - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
363 - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
364 - ddsd.dwWidth = width;
365 - ddsd.dwHeight = height;
366 - error = ddinterface->CreateSurface(&ddsd,&ddsrender,NULL);
367 - ddsrender->GetSurfaceDesc(&ddsd);
368 - ::bpp = ddsd.ddpfPixelFormat.dwRGBBitCount;
369 - }
370 - else
371 - {
372 - ddsrender = ddsurface;
373 - ddsrender->AddRef();
374 - }
375 - if(bpp == 8)
376 - {
377 - ddinterface->CreatePalette(DDPCAPS_8BIT|DDPCAPS_ALLOW256,(LPPALETTEENTRY)&DefaultPalette,&pal,NULL);
378 - ddsrender->SetPalette(pal);
379 - }
380 - else pal = NULL;
381 - InitTest2D(testnum);
382 - if(!fullscreen) SendMessage(hWnd,WM_PAINT,0,0);
383 - if(testtypes[testnum] == 1)
384 - {
385 - while(!done)
386 - {
387 - if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
388 - {
389 - if(Msg.message == WM_PAINT) RunTestLooped2D(testnum);
390 - else if(Msg.message == WM_QUIT) done = TRUE;
391 - else
392 - {
393 - TranslateMessage(&Msg);
394 - DispatchMessage(&Msg);
395 - }
396 - }
397 - else
398 - {
399 - RunTestLooped2D(testnum);
400 - }
401 - }
402 - }
403 - else if(testtypes[testnum] == 0)
404 - {
405 - StartTimer(hWnd,WM_APP,fps);
406 - while(GetMessage(&Msg, NULL, 0, 0) > 0)
407 - {
408 - TranslateMessage(&Msg);
409 - DispatchMessage(&Msg);
410 - }
411 - }
412 - else
413 - {
414 - while(GetMessage(&Msg, NULL, 0, 0) > 0)
415 - {
416 - TranslateMessage(&Msg);
417 - DispatchMessage(&Msg);
418 - }
419 - }
420 - UnregisterClass(wndclassname2d,hinstance);
421 - StopTimer();
422 -}
423 -
424 -
425 -void InitTest2D(int test)
426 -{
427 - DDSURFACEDESC2 ddsd;
428 - DDSCAPS2 ddscaps;
429 - HDC hRenderDC;
430 - ZeroMemory(&ddscaps,sizeof(DDSCAPS2));
431 - LPDIRECTDRAWPALETTE palette;
432 - unsigned char *buffer;
433 - MultiDirectDrawSurface *temp1 = NULL;
434 - MultiDirectDrawSurface *temp2 = NULL;
435 - HRESULT error;
436 - DDCOLORKEY ckey;
437 - ckey.dwColorSpaceHighValue = ckey.dwColorSpaceLowValue = 0;
438 - if(ddver > 3)ddsd.dwSize = sizeof(DDSURFACEDESC2);
439 - else ddsd.dwSize = sizeof(DDSURFACEDESC);
440 - error = ddsrender->GetSurfaceDesc(&ddsd);
441 - switch (test)
442 - {
443 - case 0:
444 - if (!fullscreen) backbuffers = 0;
445 - buffer = (unsigned char *)malloc(ddsd.lPitch*ddsd.dwHeight);
446 - DrawPalette(ddsd, buffer);
447 - error = ddsrender->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
448 - memcpy(ddsd.lpSurface, buffer, ddsd.lPitch*ddsd.dwHeight);
449 - error = ddsrender->Unlock(NULL);
450 - ddsrender->GetPalette(&palette);
451 - if (backbuffers > 0)
452 - {
453 - ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
454 - error = ddsrender->GetAttachedSurface(&ddscaps, &temp1);
455 - DrawGradients(ddsd, buffer, hWnd, palette, 1, 0);
456 - error = temp1->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
457 - memcpy(ddsd.lpSurface, buffer, ddsd.lPitch*ddsd.dwHeight);
458 - error = temp1->Unlock(NULL);
459 - }
460 - if (backbuffers > 1)
461 - {
462 - ddscaps.dwCaps = DDSCAPS_FLIP;
463 - error = temp1->GetAttachedSurface(&ddscaps, &temp2);
464 - temp1->Release();
465 - temp1 = temp2;
466 - DrawGradients(ddsd, buffer, hWnd, palette, 0, 0x0000FF);
467 - error = temp1->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
468 - memcpy(ddsd.lpSurface, buffer, ddsd.lPitch*ddsd.dwHeight);
469 - error = temp1->Unlock(NULL);
470 - }
471 - if (backbuffers > 2)
472 - {
473 - ddscaps.dwCaps = DDSCAPS_FLIP;
474 - error = temp1->GetAttachedSurface(&ddscaps, &temp2);
475 - temp1->Release();
476 - temp1 = temp2;
477 - DrawGradients(ddsd, buffer, hWnd, palette, 0, 0x00FF00);
478 - error = temp1->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
479 - memcpy(ddsd.lpSurface, buffer, ddsd.lPitch*ddsd.dwHeight);
480 - error = temp1->Unlock(NULL);
481 - }
482 - if (backbuffers > 3)
483 - {
484 - ddscaps.dwCaps = DDSCAPS_FLIP;
485 - error = temp1->GetAttachedSurface(&ddscaps, &temp2);
486 - temp1->Release();
487 - temp1 = temp2;
488 - DrawGradients(ddsd, buffer, hWnd, palette, 0, 0xFF0000);
489 - error = temp1->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
490 - memcpy(ddsd.lpSurface, buffer, ddsd.lPitch*ddsd.dwHeight);
491 - error = temp1->Unlock(NULL);
492 - }
493 - if (temp1) temp1->Release();
494 - free(buffer);
495 - if (palette) palette->Release();
496 - break;
497 - case 2:
498 - if (!fullscreen) backbuffers = 0;
499 - error = ddsrender->GetDC(&hRenderDC);
500 - DrawGDIPatterns(ddsd, hRenderDC, 0);
501 - ddsrender->ReleaseDC(hRenderDC);
502 - if (backbuffers > 0)
503 - {
504 - ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
505 - error = ddsrender->GetAttachedSurface(&ddscaps, &temp1);
506 - temp1->GetDC(&hRenderDC);
507 - DrawGDIPatterns(ddsd, hRenderDC, 1);
508 - temp1->ReleaseDC(hRenderDC);
509 - }
510 - if (backbuffers > 1)
511 - {
512 - ddscaps.dwCaps = DDSCAPS_FLIP;
513 - error = temp1->GetAttachedSurface(&ddscaps, &temp2);
514 - temp1->Release();
515 - temp1 = temp2;
516 - temp1->GetDC(&hRenderDC);
517 - DrawGDIPatterns(ddsd, hRenderDC, 2);
518 - temp1->ReleaseDC(hRenderDC);
519 - }
520 - if (backbuffers > 2)
521 - {
522 - ddscaps.dwCaps = DDSCAPS_FLIP;
523 - error = temp1->GetAttachedSurface(&ddscaps, &temp2);
524 - temp1->Release();
525 - temp1 = temp2;
526 - temp1->GetDC(&hRenderDC);
527 - DrawGDIPatterns(ddsd, hRenderDC, 3);
528 - temp1->ReleaseDC(hRenderDC);
529 - }
530 - if (backbuffers > 3)
531 - {
532 - ddscaps.dwCaps = DDSCAPS_FLIP;
533 - error = temp1->GetAttachedSurface(&ddscaps, &temp2);
534 - temp1->Release();
535 - temp1 = temp2;
536 - temp1->GetDC(&hRenderDC);
537 - DrawGDIPatterns(ddsd, hRenderDC, 4);
538 - temp1->ReleaseDC(hRenderDC);
539 - }
540 - if (backbuffers > 4)
541 - {
542 - ddscaps.dwCaps = DDSCAPS_FLIP;
543 - error = temp1->GetAttachedSurface(&ddscaps, &temp2);
544 - temp1->Release();
545 - temp1 = temp2;
546 - temp1->GetDC(&hRenderDC);
547 - DrawGDIPatterns(ddsd, hRenderDC, 5);
548 - temp1->ReleaseDC(hRenderDC);
549 - }
550 - if (backbuffers > 5)
551 - {
552 - ddscaps.dwCaps = DDSCAPS_FLIP;
553 - error = temp1->GetAttachedSurface(&ddscaps, &temp2);
554 - temp1->Release();
555 - temp1 = temp2;
556 - temp1->GetDC(&hRenderDC);
557 - DrawGDIPatterns(ddsd, hRenderDC, 6);
558 - temp1->ReleaseDC(hRenderDC);
559 - }
560 - if (backbuffers > 6)
561 - {
562 - ddscaps.dwCaps = DDSCAPS_FLIP;
563 - error = temp1->GetAttachedSurface(&ddscaps, &temp2);
564 - temp1->Release();
565 - temp1 = temp2;
566 - temp1->GetDC(&hRenderDC);
567 - DrawGDIPatterns(ddsd, hRenderDC, 7);
568 - temp1->ReleaseDC(hRenderDC);
569 - }
570 - if (temp1) temp1->Release();
571 - break;
572 - case 4:
573 - ddsrender->GetSurfaceDesc(&ddsd);
574 - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
575 - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
576 - ddinterface->CreateSurface(&ddsd, &sprites[0].surface, NULL);
577 - ddsrender->GetPalette(&palette);
578 - error = sprites[0].surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
579 - if(palette) palette->Release();
580 - DrawGradients(ddsd, (unsigned char *)ddsd.lpSurface, hWnd, palette, 1, 0);
581 - DrawDitheredColor(&ddsd, (unsigned char *)ddsd.lpSurface, 0, FALSE);
582 - error = sprites[0].surface->Unlock(NULL);
583 - sprites[0].width = (float)ddsd.dwWidth;
584 - sprites[0].height = (float)ddsd.dwHeight;
585 - sprites[0].rect.left = sprites[0].rect.top = 0;
586 - sprites[0].rect.right = ddsd.dwWidth;
587 - sprites[0].rect.bottom = ddsd.dwHeight;
588 - if (backbuffers) ddsrender->GetAttachedSurface(&ddscaps, &temp1);
589 - else temp1 = ddsrender;
590 - temp1->SetColorKey(DDCKEY_DESTBLT, &ckey);
591 - if (backbuffers) temp1->Release();
592 - for (int i = 1; i < 16; i++)
593 - {
594 - switch ((i - 1 & 3))
595 - {
596 - case 0:
597 - sprites[i].width = sprites[i].height = 64.f;
598 - sprites[i].ddsd.dwWidth = sprites[i].ddsd.dwHeight =
599 - sprites[i].rect.right = sprites[i].rect.bottom = 64;
600 - sprites[i].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
601 - sprites[i].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
602 - if (ddver > 3) sprites[i].ddsd.dwSize = sizeof(DDSURFACEDESC2);
603 - else sprites[i].ddsd.dwSize = sizeof(DDSURFACEDESC);
604 - ddinterface->CreateSurface(&sprites[i].ddsd, &sprites[i].surface, NULL);
605 - error = sprites[i].surface->Lock(NULL, &sprites[i].ddsd, DDLOCK_WAIT, NULL);
606 - DrawPalette(sprites[i].ddsd, (unsigned char *)sprites[i].ddsd.lpSurface);
607 - sprites[i].surface->Unlock(NULL);
608 - break;
609 - case 1:
610 - break;
611 - case 2:
612 - break;
613 - case 3:
614 - break;
615 - default:
616 - break;
617 - }
618 - if (i < 5) sprites[i].bltflags = 0;
619 - else if (i < 9)
620 - {
621 - sprites[i].bltflags = DDBLTFAST_SRCCOLORKEY;
622 - if (sprites[i].surface) sprites[i].surface->SetColorKey(DDCKEY_SRCBLT, &ckey);
623 - }
624 - else if (i < 13) sprites[i].bltflags = DDBLTFAST_DESTCOLORKEY;
625 - else
626 - {
627 - sprites[i].bltflags = DDBLTFAST_SRCCOLORKEY | DDBLTFAST_DESTCOLORKEY;
628 - if (sprites[i].surface) sprites[i].surface->SetColorKey(DDCKEY_SRCBLT, &ckey);
629 - }
630 - sprites[i].x = randfloat((float)ddsd.dwWidth);
631 - sprites[i].y = randfloat((float)ddsd.dwHeight);
632 - sprites[i].xvelocity = randfloat(5);
633 - sprites[i].yvelocity = randfloat(5);
634 - }
635 - break;
636 - case 7:
637 - if (!fullscreen) backbuffers = 0;
638 - ddsrender->GetSurfaceDesc(&ddsd);
639 - ddsrender->GetPalette(&palette);
640 - sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
641 - sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
642 - if (ddver > 3) sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC2);
643 - else sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC);
644 - memcpy(&sprites[1], &sprites[0], sizeof(DDSPRITE));
645 - memcpy(&sprites[2], &sprites[0], sizeof(DDSPRITE));
646 - memcpy(&sprites[3], &sprites[0], sizeof(DDSPRITE));
647 - memcpy(&sprites[4], &sprites[0], sizeof(DDSPRITE));
648 - memcpy(&sprites[5], &sprites[0], sizeof(DDSPRITE));
649 - sprites[0].width = sprites[0].height = 256.0f;
650 - sprites[1].width = sprites[1].height = 256.0f;
651 - sprites[2].width = sprites[2].height = 16.0f;
652 - sprites[3].width = sprites[3].height = 16.0f;
653 - sprites[4].width = sprites[4].height = 8.0f;
654 - sprites[5].width = sprites[4].height = 6.0f;
655 - sprites[0].ddsd.dwWidth = sprites[0].ddsd.dwHeight =
656 - sprites[0].rect.right = sprites[0].rect.bottom = 256;
657 - sprites[1].ddsd.dwWidth = sprites[1].ddsd.dwHeight =
658 - sprites[1].rect.right = sprites[1].rect.bottom = 256;
659 - sprites[2].ddsd.dwWidth = sprites[2].ddsd.dwHeight =
660 - sprites[2].rect.right = sprites[2].rect.bottom = 16;
661 - sprites[3].ddsd.dwWidth = sprites[3].ddsd.dwHeight =
662 - sprites[3].rect.right = sprites[3].rect.bottom = 16;
663 - sprites[4].ddsd.dwWidth = sprites[4].ddsd.dwHeight =
664 - sprites[4].rect.right = sprites[4].rect.bottom = 8;
665 - sprites[5].ddsd.dwWidth = sprites[5].ddsd.dwHeight =
666 - sprites[5].rect.right = sprites[5].rect.bottom = 6;
667 - ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
668 - ddinterface->CreateSurface(&sprites[1].ddsd, &sprites[1].surface, NULL);
669 - ddinterface->CreateSurface(&sprites[2].ddsd, &sprites[2].surface, NULL);
670 - ddinterface->CreateSurface(&sprites[3].ddsd, &sprites[3].surface, NULL);
671 - ddinterface->CreateSurface(&sprites[4].ddsd, &sprites[4].surface, NULL);
672 - ddinterface->CreateSurface(&sprites[5].ddsd, &sprites[5].surface, NULL);
673 - DDCAPS ddcaps;
674 - ddcaps.dwSize = sizeof(DDCAPS);
675 - ddinterface->GetCaps(&ddcaps, NULL);
676 - DrawROPPatterns(ddsrender, sprites, backbuffers, ddver, bpp, ddcaps.dwRops,hWnd,palette);
677 - if (palette) palette->Release();
678 - break;
679 - case 8:
680 - ddsrender->GetSurfaceDesc(&ddsd);
681 - sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
682 - sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
683 - if (ddver > 3) sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC2);
684 - else sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC);
685 - sprites[0].ddsd.dwWidth = sprites[0].ddsd.dwHeight =
686 - sprites[0].rect.right = sprites[0].rect.bottom = 64;
687 - ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
688 - DrawRotatedBlt(ddsrender, sprites);
689 - break;
690 - case 9:
691 - ddsrender->GetSurfaceDesc(&ddsd);
692 - sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
693 - sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
694 - if (ddver > 3) sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC2);
695 - else sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC);
696 - sprites[0].ddsd.dwWidth = sprites[0].ddsd.dwHeight =
697 - sprites[0].rect.right = sprites[0].rect.bottom = 255;
698 - ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
699 - counter = 0;
700 - break;
701 - case 10:
702 - case 11:
703 - ddsrender->GetSurfaceDesc(&ddsd);
704 - sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
705 - sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
706 - if (ddver > 3) sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC2);
707 - else sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC);
708 - switch (bpp)
709 - {
710 - case 8:
711 - sprites[0].width = sprites[0].height = 16;
712 - break;
713 - case 15:
714 - sprites[0].width = 32;
715 - sprites[0].height = 7;
716 - break;
717 - case 16:
718 - sprites[0].width = 64;
719 - sprites[0].height = 7;
720 - break;
721 - case 24:
722 - case 32:
723 - default:
724 - sprites[0].width = 256;
725 - sprites[0].height = 7;
726 - break;
727 - }
728 - sprites[0].ddsd.dwWidth = sprites[0].width;
729 - sprites[0].ddsd.dwHeight = sprites[0].height;
730 - memcpy(&sprites[1], &sprites[0], sizeof(DDSPRITE));
731 - memcpy(&sprites[2], &sprites[0], sizeof(DDSPRITE));
732 - ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
733 - ddinterface->CreateSurface(&sprites[1].ddsd, &sprites[1].surface, NULL);
734 - ddinterface->CreateSurface(&sprites[2].ddsd, &sprites[2].surface, NULL);
735 - sprites[1].surface->Lock(NULL, &sprites[1].ddsd, DDLOCK_WAIT, NULL);
736 - DrawColorKeyCompPatterns(sprites[1].ddsd, (unsigned char*)sprites[1].ddsd.lpSurface, bpp, 0);
737 - sprites[1].surface->Unlock(NULL);
738 - sprites[2].surface->Lock(NULL, &sprites[2].ddsd, DDLOCK_WAIT, NULL);
739 - DrawColorKeyCompPatterns(sprites[2].ddsd, (unsigned char*)sprites[2].ddsd.lpSurface, bpp, 1);
740 - sprites[2].surface->Unlock(NULL);
741 - counter = 0;
742 - }
743 -}
744 -
745 -void RunTestTimed2D(int test)
746 -{
747 - if(stoptimer) return;
748 - DDSURFACEDESC2 ddsd;
749 - DDSCAPS2 ddscaps;
750 - DDBLTFX bltfx;
751 - HDC hDCdest, hDCsrc;
752 - RECT r1, r2;
753 - POINT p;
754 - TCHAR message[256];
755 - bltfx.dwSize = sizeof(DDBLTFX);
756 - ZeroMemory(&ddscaps,sizeof(DDSCAPS2));
757 - ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
758 - MultiDirectDrawSurface *temp1 = NULL;
759 - switch(test)
760 - {
761 - case 0: // Palette and gradients
762 - case 2: // GDI patterns
763 - case 7: // ROP patterns
764 - default:
765 - if(fullscreen) ddsurface->Flip(NULL,DDFLIP_WAIT);
766 - break;
767 - case 4: // BltFast sprites
768 - if (backbuffers) ddsrender->GetAttachedSurface(&ddscaps, &temp1);
769 - else temp1 = ddsrender;
770 - bltfx.dwFillColor = 0;
771 - temp1->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &bltfx);
772 - if (backbuffers) temp1->Release();
773 - for(int i = 0; i < 16; i++)
774 - {
775 - sprites[i].x += sprites[i].xvelocity;
776 - if(sprites[i].xvelocity < 0 && sprites[i].x < 0) sprites[i].xvelocity = -sprites[i].xvelocity;
777 - if(sprites[i].xvelocity > 0 && (sprites[i].x + sprites[i].width) > width)
778 - sprites[i].xvelocity = -sprites[i].xvelocity;
779 - sprites[i].y += sprites[i].yvelocity;
780 - if(sprites[i].yvelocity < 0 && sprites[i].y < 0) sprites[i].yvelocity = -sprites[i].yvelocity;
781 - if(sprites[i].yvelocity > 0 && (sprites[i].y + sprites[i].height) > height)
782 - sprites[i].yvelocity = -sprites[i].yvelocity;
783 - if(sprites[i].surface)
784 - {
785 - if(backbuffers) ddsrender->GetAttachedSurface(&ddscaps,&temp1);
786 - else temp1 = ddsrender;
787 - temp1->BltFast((DWORD)sprites[i].x,(DWORD)sprites[i].y,sprites[i].surface,&sprites[i].rect,sprites[i].bltflags);
788 - if(backbuffers) temp1->Release();
789 - }
790 - }
791 - if (fullscreen)
792 - {
793 - if (backbuffers && ddsrender) ddsrender->Flip(NULL, DDFLIP_WAIT);
794 - }
795 - else
796 - {
797 - p.x = 0;
798 - p.y = 0;
799 - ClientToScreen(hWnd, &p);
800 - GetClientRect(hWnd, &r1);
801 - OffsetRect(&r1, p.x, p.y);
802 - SetRect(&r2, 0, 0, width, height);
803 - if (ddsurface && ddsrender) ddsurface->Blt(&r1, ddsrender, &r2, DDBLT_WAIT, NULL);
804 - }
805 - break;
806 - case 10: // Source Key Override test
807 - case 11: // Destination Key Override Test
808 - if (backbuffers) ddsrender->GetAttachedSurface(&ddscaps, &temp1);
809 - else temp1 = ddsrender;
810 -
811 - sprites[0].surface->Blt(NULL, sprites[1].surface, NULL, DDBLT_WAIT, NULL);
812 - bltfx.dwSize = sizeof(DDBLTFX);
813 - switch (bpp)
814 - {
815 - case 8:
816 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
817 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue = counter;
818 - counter++;
819 - if (counter > 255) counter = 0;
820 - r1.left = r1.top = 0;
821 - r1.right = r1.bottom = 16;
822 - break;
823 - case 15:
824 - switch (counter >> 5)
825 - {
826 - case 0:
827 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
828 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
829 - (counter & 31) << 10;
830 - break;
831 - case 1:
832 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
833 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
834 - (counter & 31) << 5;
835 - break;
836 - case 2:
837 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
838 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
839 - (counter & 31);
840 - break;
841 - case 3:
842 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
843 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
844 - (counter & 31) + ((counter & 31) << 5);
845 - break;
846 - case 4:
847 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
848 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
849 - (counter & 31) + ((counter & 31) << 10);
850 - break;
851 - case 5:
852 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
853 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
854 - ((counter & 31) << 5) + ((counter & 31) << 10);
855 - break;
856 - case 6:
857 - default:
858 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
859 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
860 - (counter & 31) + ((counter & 31) << 5) + ((counter & 31) << 10);
861 - break;
862 - }
863 - counter++;
864 - if (counter > 223) counter = 0;
865 - r1.left = r1.top = 0;
866 - r1.right = 32;
867 - r1.bottom = 7;
868 - break;
869 - case 16:
870 - switch (counter >> 6)
871 - {
872 - case 0:
873 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
874 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
875 - ((counter & 63) >> 1) << 11;
876 - break;
877 - case 1:
878 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
879 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
880 - (counter & 63) << 5;
881 - break;
882 - case 2:
883 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
884 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
885 - (counter & 63) >> 1;
886 - break;
887 - case 3:
888 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
889 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
890 - ((counter & 63) >> 1) + ((counter & 63) << 5);
891 - break;
892 - case 4:
893 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
894 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
895 - ((counter & 63) >> 1) + (((counter & 63) >> 1) << 11);
896 - break;
897 - case 5:
898 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
899 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
900 - ((counter & 63) << 5) + (((counter & 63) >> 1) << 11);
901 - break;
902 - case 6:
903 - default:
904 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
905 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
906 - ((counter & 63) >> 1) + ((counter & 63) << 5) + (((counter & 63) >> 1) << 11);
907 - break;
908 - }
909 - counter++;
910 - if (counter > 447) counter = 0;
911 - r1.left = r1.top = 0;
912 - r1.right = 64;
913 - r1.bottom = 7;
914 - break;
915 - case 24:
916 - case 32:
917 - default:
918 - switch (counter >> 8)
919 - {
920 - case 0:
921 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
922 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
923 - (counter & 255) << 16;
924 - break;
925 - case 1:
926 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
927 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
928 - (counter & 255) << 8;
929 - break;
930 - case 2:
931 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
932 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
933 - counter & 255;
934 - break;
935 - case 3:
936 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
937 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
938 - (counter & 255) + ((counter & 255) << 8);
939 - break;
940 - case 4:
941 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
942 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
943 - (counter & 255) + ((counter & 255) << 16);
944 - break;
945 - case 5:
946 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
947 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
948 - ((counter & 255) << 8) + ((counter & 255) << 16);
949 - break;
950 - case 6:
951 - default:
952 - bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
953 - bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
954 - (counter & 255) + ((counter & 255) << 8) + ((counter & 255) << 16);
955 - break;
956 - }
957 - counter++;
958 - if (counter > 1791) counter = 0;
959 - r1.left = r1.top = 0;
960 - r1.right = 256;
961 - r1.bottom = 7;
962 - break;
963 - }
964 - if (test == 10)
965 - sprites[0].surface->Blt(NULL, sprites[2].surface, NULL, DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE, &bltfx);
966 - else
967 - sprites[0].surface->Blt(NULL, sprites[2].surface, NULL, DDBLT_WAIT | DDBLT_KEYDESTOVERRIDE, &bltfx);
968 - temp1->GetDC(&hDCdest);
969 - sprites[0].surface->GetDC(&hDCsrc);
970 - if (ddver > 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
971 - else ddsd.dwSize = sizeof(DDSURFACEDESC);
972 - temp1->GetSurfaceDesc(&ddsd);
973 - StretchBlt(hDCdest, ((ddsd.dwWidth / 2) - 128), ((ddsd.dwHeight / 2) + 128), 256, -256,
974 - hDCsrc, 0, 0, r1.right, r1.bottom, SRCCOPY);
975 - sprites[0].surface->ReleaseDC(hDCsrc);
976 - SetBkColor(hDCdest, RGB(0, 0, 255));
977 - SetTextColor(hDCdest, RGB(255, 255, 255));
978 - if(test == 10)
979 - _tcscpy(message, _T("Source Color Key Override Test"));
980 - else
981 - _tcscpy(message, _T("Destination Color Key Override Test"));
982 - TextOut(hDCdest, 0, 0, message, _tcslen(message));
983 - _stprintf(message, _T("Color: 0x%08X "), bltfx.ddckSrcColorkey.dwColorSpaceHighValue);
984 - TextOut(hDCdest, 0, 16, message, _tcslen(message));
985 - temp1->ReleaseDC(hDCdest);
986 - if (backbuffers) temp1->Release();
987 - if (fullscreen)
988 - {
989 - if (backbuffers && ddsrender) ddsrender->Flip(NULL, DDFLIP_WAIT);
990 - }
991 - else
992 - {
993 - p.x = 0;
994 - p.y = 0;
995 - ClientToScreen(hWnd, &p);
996 - GetClientRect(hWnd, &r1);
997 - OffsetRect(&r1, p.x, p.y);
998 - SetRect(&r2, 0, 0, width, height);
999 - if (ddsurface && ddsrender) ddsurface->Blt(&r1, ddsrender, &r2, DDBLT_WAIT, NULL);
1000 - }
1001 - break;
1002 - }
1003 -}
1004 -
1005 -void RunTestLooped2D(int test)
1006 -{
1007 - randnum += rand(); // Improves randomness of "snow" patterns at certain resolutions
1008 - HDC hdc;
1009 - unsigned int i;
1010 - POINT p;
1011 - HPEN pen;
1012 - HBRUSH brush;
1013 - HANDLE tmphandle,tmphandle2;
1014 - RECT srcrect,destrect;
1015 - HRESULT error;
1016 - DDSURFACEDESC2 ddsd;
1017 - DDBLTFX bltfx;
1018 - if(ddver > 3)ddsd.dwSize = sizeof(DDSURFACEDESC2);
1019 - else ddsd.dwSize = sizeof(DDSURFACEDESC);
1020 - error = ddsrender->GetSurfaceDesc(&ddsd);
1021 - MultiDirectDrawSurface *temp1 = NULL;
1022 - DDSCAPS2 ddscaps;
1023 - DWORD bitmask;
1024 - ZeroMemory(&ddscaps,sizeof(DDSCAPS2));
1025 - ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
1026 - int op;
1027 - switch(test)
1028 - {
1029 - case 1:
1030 - default:
1031 - if(backbuffers)
1032 - {
1033 - ddsrender->GetAttachedSurface(&ddscaps,&temp1);
1034 - temp1->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
1035 - }
1036 - else ddsrender->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
1037 -
1038 - for(i = 0; i < ((ddsd.lPitch * ddsd.dwHeight)/4); i++)
1039 - ((DWORD*)ddsd.lpSurface)[i] = rand32(randnum);
1040 -
1041 - if(backbuffers)
1042 - {
1043 - temp1->Unlock(NULL);
1044 - ddsrender->Flip(NULL,DDFLIP_WAIT);
1045 - }
1046 - else ddsrender->Unlock(NULL);
1047 - if(!fullscreen)
1048 - {
1049 - p.x = 0;
1050 - p.y = 0;
1051 - ClientToScreen(hWnd,&p);
1052 - GetClientRect(hWnd,&destrect);
1053 - OffsetRect(&destrect,p.x,p.y);
1054 - SetRect(&srcrect,0,0,width,height);
1055 - if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
1056 - }
1057 - break;
1058 - case 3:
1059 - ddsrender->GetDC(&hdc);
1060 - op = rand32(randnum) % 4;
1061 - pen = CreatePen(rand32(randnum) % 5,0,RGB(rand32(randnum)%256,rand32(randnum)%256,rand32(randnum)%256));
1062 - brush = CreateSolidBrush(RGB(rand32(randnum)%256,rand32(randnum)%256,rand32(randnum)%256));
1063 - tmphandle = SelectObject(hdc,pen);
1064 - tmphandle2 = SelectObject(hdc,brush);
1065 - SetBkColor(hdc,RGB(rand32(randnum)%256,rand32(randnum)%256,rand32(randnum)%256));
1066 - switch(op)
1067 - {
1068 - case 0:
1069 - default:
1070 - Rectangle(hdc,rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight,
1071 - rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight);
1072 - break;
1073 - case 1:
1074 - Ellipse(hdc,rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight,
1075 - rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight);
1076 - break;
1077 - case 2:
1078 - MoveToEx(hdc,rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight,NULL);
1079 - LineTo(hdc,rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight);
1080 - break;
1081 - case 3:
1082 - SetTextColor(hdc,RGB(rand32(randnum)%256,rand32(randnum)%256,rand32(randnum)%256));
1083 - TextOut(hdc,rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight,_T("Text"),4);
1084 - break;
1085 - }
1086 - SelectObject(hdc,tmphandle2);
1087 - SelectObject(hdc,tmphandle);
1088 - DeleteObject(brush);
1089 - DeleteObject(pen);
1090 - ddsrender->ReleaseDC(hdc);
1091 - if(!fullscreen)
1092 - {
1093 - p.x = 0;
1094 - p.y = 0;
1095 - ClientToScreen(hWnd,&p);
1096 - GetClientRect(hWnd,&destrect);
1097 - OffsetRect(&destrect,p.x,p.y);
1098 - SetRect(&srcrect,0,0,width,height);
1099 - if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
1100 - }
1101 - break;
1102 - case 5:
1103 - rndrect5:
1104 - destrect.bottom = rand32(randnum)%ddsd.dwHeight;
1105 - destrect.top = rand32(randnum)%ddsd.dwHeight;
1106 - destrect.left = rand32(randnum)%ddsd.dwWidth;
1107 - destrect.right = rand32(randnum)%ddsd.dwWidth;
1108 - if((destrect.bottom < destrect.top) || (destrect.right < destrect.left)) goto rndrect5;
1109 - bltfx.dwSize = sizeof(DDBLTFX);
1110 - switch(bpp)
1111 - {
1112 - case 8:
1113 - bltfx.dwFillColor = rand32(randnum) % 0xFF;
1114 - break;
1115 - case 15:
1116 - bltfx.dwFillColor = rand32(randnum) % 0x7FFF;
1117 - break;
1118 - case 16:
1119 - bltfx.dwFillColor = rand32(randnum) % 0xFFFF;
1120 - break;
1121 - case 24:
1122 - case 32:
1123 - default:
1124 - bltfx.dwFillColor = rand32(randnum) % 0xFFFFFF;
1125 - break;
1126 - }
1127 - ddsrender->Blt(&destrect,NULL,NULL,DDBLT_COLORFILL,&bltfx);
1128 - if(!fullscreen)
1129 - {
1130 - p.x = 0;
1131 - p.y = 0;
1132 - ClientToScreen(hWnd,&p);
1133 - GetClientRect(hWnd,&destrect);
1134 - OffsetRect(&destrect,p.x,p.y);
1135 - SetRect(&srcrect,0,0,width,height);
1136 - if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
1137 - }
1138 - break;
1139 - case 9:
1140 - bltfx.dwSize = sizeof(DDBLTFX);
1141 - switch (bpp)
1142 - {
1143 - case 8:
1144 - bitmask = 0xFF;
1145 - break;
1146 - case 15:
1147 - bitmask = 0x7FFF;
1148 - break;
1149 - case 16:
1150 - bitmask = 0xFFFF;
1151 - break;
1152 - case 24:
1153 - bitmask = 0xFFFFFF;
1154 - break;
1155 - case 32:
1156 - default:
1157 - bitmask = 0xFFFFFFFF;
1158 - break;
1159 - }
1160 - for (int y = 0; y < 255; y++)
1161 - {
1162 - for (int x = 0; x < 255; x++)
1163 - {
1164 - bltfx.dwFillColor = counter & bitmask;
1165 - destrect.left = x;
1166 - destrect.right = x + 1;
1167 - destrect.top = y;
1168 - destrect.bottom = y + 1;
1169 - counter++;
1170 - sprites[0].surface->Blt(&destrect, NULL, NULL, DDBLT_COLORFILL, &bltfx);
1171 - }
1172 - }
1173 - ddsrender->Blt(NULL, sprites[0].surface, NULL, DDBLT_WAIT, NULL);
1174 - if (!fullscreen)
1175 - {
1176 - p.x = 0;
1177 - p.y = 0;
1178 - ClientToScreen(hWnd, &p);
1179 - GetClientRect(hWnd, &destrect);
1180 - OffsetRect(&destrect, p.x, p.y);
1181 - SetRect(&srcrect, 0, 0, width, height);
1182 - if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
1183 - }
1184 - break;
1185 - }
1186 - if(temp1) temp1->Release();
1187 -}
1188 -
1189 -/*
1190 -void DDFlipTestWindow::OnQueryNewPalette(wxQueryNewPaletteEvent& event)
1191 -{
1192 - //if(bpp == 8) ddsurface->SetPalette
1193 -}
1194 -*/
\ No newline at end of file
Index: Installer/dxgl.nsi
——@@ -134,7 +134,7 @@
135135 VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "DXGL ${PRODUCT_VERSION} Installer"
136136 VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${PRODUCT_VERSION}"
137137 VIAddVersionKey /LANG=${LANG_ENGLISH} "InternalName" "DXGL"
138 -VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright © 2011-2015 William Feely"
 138+VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright © 2011-2017 William Feely"
139139 VIAddVersionKey /LANG=${LANG_ENGLISH} "OriginalFilename" "DXGL-${PRODUCT_VERSION}-win32.exe"
140140 VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "DXGL"
141141 VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "${PRODUCT_VERSION}"
Index: dxgltest/dxgltest.cpp
——@@ -210,76 +210,56 @@
211211 int maxver;
212212 int buffermin;
213213 int buffermax;
214 - bool usesfps;
 214+ BOOL usesfps;
215215 float defaultfps;
216 - bool usestexture;
217 - bool usesfsaa;
 216+ BOOL is3d;
 217+ BOOL usestexture;
 218+ BOOL usesfsaa;
218219 TCHAR *name;
219220 } TEST_ITEM;
220221
221222 // Use EXACTLY one line per entry. Don't change layout of the list.
222 -const int START_2D = __LINE__;
223 -const TEST_ITEM Tests2D[] =
224 -{ // minver maxver buffermin max usesfps defaultfps usestexture usesfsaa name
225 - {1, 7, 0, 4, true, 1.0, false, false, _T("Color palette and gradient screens (direct surface access)")},
226 - {1, 7, 0, 1, false, 0.0, false, false, _T("Random noise (continuous surface upload)")},
227 - {1, 7, 0, 7, true, 1.0, false, false, _T("GDI Test patterns (GetDC() test)")},
228 - {1, 7, 0, 0, false, 0.0, false, false, _T("Random GDI patterns (does not clear screen between paints)")},
229 - {1, 7, 0, 1, true, 60.0, false, false, _T("BltFast background and sprites")},
230 - {1, 7, 0, 0, false, 0.0, false, false, _T("Random color fill Blt() paterns")},
231 - {1, 7, 0, 0, false, 0.0, false, false, _T("Mouse pointer event test")},
232 - {1, 7, 1, 1, true, 1.0, false, false, _T("Raster Operation Blt() test")},
233 - {1, 7, 0, 0, false, 0.0, false, false, _T("Mirrored and Rotated Blt() test")},
234 - {1, 7, 0, 1, false, 0.0, false, false, _T("Large batch color fill Blt() operations")},
235 - {1, 7, 0, 1, true, 60.0, false, false, _T("Source Color Key Override test")},
236 - {1, 7, 0, 1, true, 60.0, false, false, _T("Destination Color Key Override test")}
 223+const int START_TESTS = __LINE__;
 224+const TEST_ITEM Tests[] =
 225+{ // minver maxver buffermin max usesfps defaultfps is3d usestexture usesfsaa name
 226+ {1, 7, 0, 4, TRUE, 1.0, FALSE, FALSE, FALSE, _T("Color palette and gradient screens (direct surface access)")},
 227+ {1, 7, 0, 1, FALSE, 0.0, FALSE, FALSE, FALSE, _T("Random noise (continuous surface upload)")},
 228+ {1, 7, 0, 7, TRUE, 1.0, FALSE, FALSE, FALSE, _T("GDI Test patterns (GetDC() test)")},
 229+ {1, 7, 0, 0, FALSE, 0.0, FALSE, FALSE, FALSE, _T("Random GDI patterns (does not clear screen between paints)")},
 230+ {1, 7, 0, 1, TRUE, 60.0, FALSE, FALSE, FALSE, _T("BltFast background and sprites")},
 231+ {1, 7, 0, 0, FALSE, 0.0, FALSE, FALSE, FALSE, _T("Random color fill Blt() paterns")},
 232+ {1, 7, 0, 0, FALSE, 0.0, FALSE, FALSE, FALSE, _T("Mouse pointer event test")},
 233+ {1, 7, 1, 1, TRUE, 1.0, FALSE, FALSE, FALSE, _T("Raster Operation Blt() test")},
 234+ {1, 7, 0, 0, FALSE, 0.0, FALSE, FALSE, FALSE, _T("Mirrored and Rotated Blt() test")},
 235+ {1, 7, 0, 1, FALSE, 0.0, FALSE, FALSE, FALSE, _T("Large batch color fill Blt() operations")},
 236+ {1, 7, 0, 1, TRUE, 60.0, FALSE, FALSE, FALSE, _T("Source Color Key Override test")},
 237+ {1, 7, 0, 1, TRUE, 60.0, FALSE, FALSE, FALSE, _T("Destination Color Key Override test")},
 238+ {7, 7, 0, 2, TRUE, 60.0, TRUE, FALSE, TRUE, _T("DrawIndexedPrimitive cube with directional light (DX7)")},
 239+ {7, 7, 0, 2, TRUE, 60.0, TRUE, TRUE, TRUE, _T("DrawPrimitive textured cube (DX7)")},
 240+ {7, 7, 0, 0, TRUE, 60.0, TRUE, TRUE, TRUE, _T("Texture Stage shaders (Interactive, DX7)")},
 241+ {7, 7, 0, 0, TRUE, 60.0, TRUE, TRUE, TRUE, _T("Vertex shaders (Interactive, DX7)")}
237242 };
238 -const int END_2D = __LINE__ - 4;
239 -const int numtests2d = END_2D - START_2D;
 243+const int END_TESTS = __LINE__ - 4;
 244+const int numtests = END_TESTS - START_TESTS;
240245
241 -int currenttest2d = 0;
242 -int minapi2d = 1;
243 -int maxapi2d = 7;
244 -int minbuffer2d = 0;
245 -int maxbuffer2d = 4;
246 -int fps_enabled2d = false;
247 -int api2d = 1;
248 -int buffer2d = 1;
249 -bool fullscreen2d = true;
250 -bool resizable2d = false;
251 -double framerate2d = 1.00;
252 -TCHAR framerate2dstring[33];
 246+int currenttest = 0;
 247+int minapi = 1;
 248+int maxapi = 7;
 249+int minbuffer = 0;
 250+int maxbuffer = 4;
 251+int fps_enabled = false;
 252+int api = 1;
 253+int buffer = 1;
 254+int filter = 0;
 255+int msaa = 0;
 256+bool fullscreen = true;
 257+bool resizable = false;
 258+double framerate = 1.00;
 259+TCHAR frameratestring[33];
253260
254 -// Use EXACTLY one line per entry. Don't change layout of the list.
255 -const int START_3D = __LINE__;
256 -const TEST_ITEM Tests3D[] =
257 -{ // minver maxver buffermin max usesfps defaultfps usestexture usesfsaa name
258 - {7, 7, 0, 2, true, 60.0, false, true, _T("DrawIndexedPrimitive cube with directional light (DX7)")},
259 - {7, 7, 0, 2, true, 60.0, true, true, _T("DrawPrimitive textured cube (DX7)")},
260 - {7, 7, 0, 0, true, 60.0, true, true, _T("Texture Stage shaders (Interactive, DX7)")},
261 - {7, 7, 0, 0, true, 60.0, true, true, _T("Vertex shaders (Interactive, DX7)")}
262 -};
263 -const int END_3D = __LINE__ - 4;
264 -const int numtests3d = END_3D - START_3D;
 261+TCHAR tmpstring[33];
265262
266 -int currenttest3d = 0;
267 -int minapi3d = 7;
268 -int maxapi3d = 7;
269 -int minbuffer3d = 0;
270 -int maxbuffer3d = 2;
271 -int fps_enabled3d = true;
272 -int api3d = 7;
273 -int buffer3d = 1;
274 -int filter3d = 0;
275 -int msaa3d = 0;
276 -bool fullscreen3d = true;
277 -bool resizable3d = true;
278 -double framerate3d = 60.00;
279 -TCHAR framerate3dstring[33];
280 -
281 -
282 -TCHAR tmpstring[33];
283 -INT_PTR CALLBACK Test2DCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 263+INT_PTR CALLBACK TestTabCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
284264 {
285265 int i;
286266 int pos;
——@@ -291,14 +271,10 @@
292272 {
293273 case WM_INITDIALOG:
294274 if (_EnableThemeDialogTexture) _EnableThemeDialogTexture(hWnd, ETDT_ENABLETAB);
295 - DestroyWindow(GetDlgItem(hWnd,IDC_FILTERLABEL));
296 - DestroyWindow(GetDlgItem(hWnd,IDC_FILTER));
297 - DestroyWindow(GetDlgItem(hWnd,IDC_FSAALABEL));
298 - DestroyWindow(GetDlgItem(hWnd,IDC_FSAA));
299275 SendDlgItemMessage(hWnd,IDC_FULLSCREEN,BM_SETCHECK,1,0);
300 - SetDlgItemText(hWnd,IDC_TESTHEADER,_T("Test 2D graphics functionality in DXGL or DirectDraw. Press ESC to quit any test."));
301 - for(i = 0; i < numtests2d; i++)
302 - SendDlgItemMessage(hWnd,IDC_TESTLIST,LB_ADDSTRING,0,(LPARAM)Tests2D[i].name);
 276+ SetDlgItemText(hWnd,IDC_TESTHEADER,_T("Test graphics functionality in DXGL or DirectDraw. Press ESC to quit any test."));
 277+ for(i = 0; i < numtests; i++)
 278+ SendDlgItemMessage(hWnd,IDC_TESTLIST,LB_ADDSTRING,0,(LPARAM)Tests[i].name);
303279 error = DirectDrawCreate(NULL,&lpdd,NULL);
304280 if(error == DD_OK)
305281 {
——@@ -316,226 +292,28 @@
317293 i = SendDlgItemMessage(hWnd,IDC_TESTLIST,LB_GETCURSEL,0,0);
318294 if(i != -1)
319295 {
320 - currenttest2d = i;
321 - minapi2d = Tests2D[i].minver;
322 - maxapi2d = Tests2D[i].maxver;
323 - minbuffer2d = Tests2D[i].buffermin;
324 - maxbuffer2d = Tests2D[i].buffermax;
325 - fps_enabled2d = Tests2D[i].usesfps;
326 - if(Tests2D[i].usesfps) framerate2d = Tests2D[i].defaultfps;
327 - EnableWindow(GetDlgItem(hWnd,IDC_BUFFERS),TRUE);
328 - EnableWindow(GetDlgItem(hWnd,IDC_APIVER),TRUE);
329 - EnableWindow(GetDlgItem(hWnd,IDC_FRAMERATE),fps_enabled2d);
330 - EnableWindow(GetDlgItem(hWnd,IDC_TEST),TRUE);
331 - SendDlgItemMessage(hWnd,IDC_BUFFERS,EM_SETLIMITTEXT,2,0);
332 - SendDlgItemMessage(hWnd,IDC_APIVER,EM_SETLIMITTEXT,1,0);
333 - SendDlgItemMessage(hWnd,IDC_FRAMERATE,EM_SETLIMITTEXT,5,0);
334 - SendDlgItemMessage(hWnd,IDC_BUFFERS,WM_SETTEXT,0,(LPARAM)_itot(buffer2d,tmpstring,10));
335 - SendDlgItemMessage(hWnd,IDC_APIVER,WM_SETTEXT,0,(LPARAM)_itot(api2d,tmpstring,10));
336 - _stprintf(framerate2dstring,_T("%.2f"),framerate2d);
337 - SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_SETTEXT,0,(LPARAM)framerate2dstring);
338 - }
339 - }
340 - break;
341 - case IDC_FRAMERATE:
342 - if(HIWORD(wParam) == EN_CHANGE)
343 - {
344 - SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_GETTEXT,6,(LPARAM)tmpstring);
345 - if(_tcscmp(framerate2dstring,tmpstring))
346 - {
347 - pos = LOWORD(SendDlgItemMessage(hWnd,IDC_FRAMERATE,EM_GETSEL,NULL,NULL));
348 - i = _tcslen(tmpstring);
349 - f = _ttof(tmpstring);
350 - if(errno != ERANGE) framerate2d = f;
351 - if(framerate2d < 0.5) framerate2d = 0.5;
352 - if(framerate2d > 99.99) framerate2d = 99.99;
353 - _stprintf(framerate2dstring,_T("%.2f"),framerate2d);
354 - SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_SETTEXT,0,(LPARAM)framerate2dstring);
355 - SendDlgItemMessage(hWnd,IDC_FRAMERATE,EM_SETSEL,pos,pos);
356 - }
357 - }
358 - break;
359 - case IDC_APIVER:
360 - if(HIWORD(wParam) == EN_CHANGE)
361 - {
362 - SendDlgItemMessage(hWnd,IDC_APIVER,WM_GETTEXT,6,(LPARAM)tmpstring);
363 - i = _ttoi(tmpstring);
364 - if(i != api2d)
365 - {
366 - api2d = i;
367 - if(api2d == 5) api2d = 4;
368 - if(api2d == 6) api2d = 7;
369 - if(api2d < minapi2d) api2d = minapi2d;
370 - if(api2d > maxapi2d) api2d = maxapi2d;
371 - _itot(api2d,tmpstring,10);
372 - SendDlgItemMessage(hWnd,IDC_APIVER,WM_SETTEXT,0,(LPARAM)tmpstring);
373 - }
374 - }
375 - break;
376 - case IDC_BUFFERS:
377 - if(HIWORD(wParam) == EN_CHANGE)
378 - {
379 - SendDlgItemMessage(hWnd,IDC_BUFFERS,WM_GETTEXT,6,(LPARAM)tmpstring);
380 - i = _ttoi(tmpstring);
381 - if(i != buffer2d)
382 - {
383 - buffer2d = i;
384 - if(buffer2d < minbuffer2d) buffer2d = minbuffer2d;
385 - if(buffer2d > maxbuffer2d) buffer2d = maxbuffer2d;
386 - _itot(buffer2d,tmpstring,10);
387 - SendDlgItemMessage(hWnd,IDC_BUFFERS,WM_SETTEXT,0,(LPARAM)tmpstring);
388 - }
389 - }
390 - break;
391 - case IDC_TEST:
392 - if(SendDlgItemMessage(hWnd,IDC_RESIZABLE,BM_GETCHECK,0,0)) resizable2d = true;
393 - else resizable2d = false;
394 - if (buffer2d < minbuffer2d) buffer2d = minbuffer2d;
395 - if (buffer2d > maxbuffer2d) buffer2d = maxbuffer2d;
396 - i = SendDlgItemMessage(hWnd, IDC_VIDMODES, LB_GETCURSEL, 0, 0);
397 - SendDlgItemMessage(hWnd,IDC_VIDMODES,LB_GETTEXT,i,(LPARAM)tmpstring);
398 - TranslateResolutionString(tmpstring,width,height,bpp,refresh);
399 - RunTest2D(currenttest2d,width,height,bpp,refresh,buffer2d,api2d,framerate2d,fullscreen2d,resizable2d);
400 - break;
401 - case IDC_WINDOWED:
402 - SendDlgItemMessage(hWnd,IDC_FULLSCREEN,BM_SETCHECK,0,0);
403 - SendDlgItemMessage(hWnd,IDC_WINDOWED,BM_SETCHECK,1,0);
404 - fullscreen2d = false;
405 - break;
406 - case IDC_FULLSCREEN:
407 - SendDlgItemMessage(hWnd,IDC_FULLSCREEN,BM_SETCHECK,1,0);
408 - SendDlgItemMessage(hWnd,IDC_WINDOWED,BM_SETCHECK,0,0);
409 - fullscreen2d = true;
410 - break;
411 - }
412 - break;
413 - case WM_NOTIFY:
414 - switch(((LPNMHDR)lParam)->code)
415 - {
416 - case UDN_DELTAPOS:
417 - switch(((LPNMHDR)lParam)->idFrom)
418 - {
419 - case IDC_SPINFRAME:
420 - framerate2d -= ((LPNMUPDOWN)lParam)->iDelta;
421 - if(framerate2d < 0.01) framerate2d = 0.01;
422 - if(framerate2d > 99.99) framerate2d = 99.99;
423 - _stprintf(framerate2dstring,_T("%.2f"),framerate2d);
424 - SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_SETTEXT,0,(LPARAM)framerate2dstring);
425 - break;
426 - case IDC_SPINAPI:
427 - if(api2d < 1) api2d = 1;
428 - if(api2d > 7) api2d = 7;
429 - if(((LPNMUPDOWN)lParam)->iDelta > 0)
430 - {
431 - switch(api2d)
 296+ currenttest = i;
 297+ minapi = Tests[i].minver;
 298+ maxapi = Tests[i].maxver;
 299+ if (api < minapi)
432300 {
433 - case 1:
434 - case 2:
435 - default:
436 - api2d = 1;
437 - break;
438 - case 3:
439 - api2d = 2;
440 - break;
441 - case 4:
442 - api2d = 3;
443 - break;
444 - case 7:
445 - case 6:
446 - case 5:
447 - api2d = 4;
 301+ SendDlgItemMessage(hWnd, IDC_APIVER, WM_SETTEXT, 0, (LPARAM)_itot(minapi, tmpstring, 10));
 302+ api = minapi;
448303 }
449 - }
450 - else
451 - {
452 - switch(api2d)
 304+ if (api > maxapi)
453305 {
454 - case 1:
455 - default:
456 - api2d = 2;
457 - break;
458 - case 2:
459 - api2d = 3;
460 - break;
461 - case 3:
462 - api2d = 4;
463 - break;
464 - case 4:
465 - case 5:
466 - case 6:
467 - case 7:
468 - api2d = 7;
 306+ SendDlgItemMessage(hWnd, IDC_APIVER, WM_SETTEXT, 0, (LPARAM)_itot(maxapi, tmpstring, 10));
 307+ api = maxapi;
469308 }
470 - }
471 - if(api2d < minapi2d) api2d = minapi2d;
472 - if(api2d > maxapi2d) api2d = maxapi2d;
473 - SendDlgItemMessage(hWnd,IDC_APIVER,WM_SETTEXT,0,(LPARAM)_itot(api2d,tmpstring,10));
474 - break;
475 - case IDC_SPINBACK:
476 - buffer2d -= ((LPNMUPDOWN)lParam)->iDelta;
477 - if(buffer2d < minbuffer2d) buffer2d = minbuffer2d;
478 - if(buffer2d > maxbuffer2d) buffer2d = maxbuffer2d;
479 - SendDlgItemMessage(hWnd,IDC_BUFFERS,WM_SETTEXT,0,(LPARAM)_itot(buffer2d,tmpstring,10));
480 - break;
481 - default:
482 - break;
483 - }
484 - break;
485 - default:
486 - break;
487 - }
488 - break;
489 - default:
490 - return FALSE;
491 - }
492 - return TRUE;
493 -}
494 -
495 -INT_PTR CALLBACK Test3DCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
496 -{
497 - int i;
498 - int pos;
499 - double f;
500 - LPDIRECTDRAW lpdd;
501 - HRESULT error;
502 - int width,height,bpp,refresh;
503 - switch(Msg)
504 - {
505 - case WM_INITDIALOG:
506 - if (_EnableThemeDialogTexture) _EnableThemeDialogTexture(hWnd, ETDT_ENABLETAB);
507 - SendDlgItemMessage(hWnd,IDC_FULLSCREEN,BM_SETCHECK,1,0);
508 - SetDlgItemText(hWnd,IDC_TESTHEADER,_T("Test 3D graphics functionality in DXGL or Direct3D. Press ESC to quit any test."));
509 - for(i = 0; i < numtests3d; i++)
510 - SendDlgItemMessage(hWnd,IDC_TESTLIST,LB_ADDSTRING,0,(LPARAM)Tests3D[i].name);
511 - error = DirectDrawCreate(NULL,&lpdd,NULL);
512 - if(error == DD_OK)
513 - {
514 - error = lpdd->EnumDisplayModes(DDEDM_REFRESHRATES,NULL,GetDlgItem(hWnd,IDC_VIDMODES),EnumModesCallback32);
515 - lpdd->Release();
516 - }
517 - SendDlgItemMessage(hWnd,IDC_VIDMODES,LB_SETCURSEL,modenum,0);
518 - break;
519 - case WM_COMMAND:
520 - switch(LOWORD(wParam))
521 - {
522 - case IDC_TESTLIST:
523 - if(HIWORD(wParam) == LBN_SELCHANGE)
524 - {
525 - i = SendDlgItemMessage(hWnd,IDC_TESTLIST,LB_GETCURSEL,0,0);
526 - if(i != -1)
527 - {
528 - currenttest3d = i;
529 - minapi3d = Tests3D[i].minver;
530 - maxapi3d = Tests3D[i].maxver;
531 - minbuffer3d = Tests3D[i].buffermin;
532 - maxbuffer3d = Tests3D[i].buffermax;
533 - fps_enabled3d = Tests3D[i].usesfps;
534 - if(Tests3D[i].usesfps) framerate3d = Tests3D[i].defaultfps;
535 - if((i != 2) && (i !=3))
 309+ minbuffer = Tests[i].buffermin;
 310+ maxbuffer = Tests[i].buffermax;
 311+ fps_enabled = Tests[i].usesfps;
 312+ if(Tests[i].usesfps) framerate = Tests[i].defaultfps;
 313+ if((i != 14) && (i != 15))
536314 {
537315 EnableWindow(GetDlgItem(hWnd,IDC_BUFFERS),TRUE);
538316 EnableWindow(GetDlgItem(hWnd,IDC_APIVER),TRUE);
539 - EnableWindow(GetDlgItem(hWnd,IDC_FRAMERATE),fps_enabled3d);
 317+ EnableWindow(GetDlgItem(hWnd,IDC_FRAMERATE),fps_enabled);
540318 EnableWindow(GetDlgItem(hWnd,IDC_TEST),TRUE);
541319 EnableWindow(GetDlgItem(hWnd,IDC_WINDOWED),TRUE);
542320 EnableWindow(GetDlgItem(hWnd,IDC_FULLSCREEN),TRUE);
——@@ -556,15 +334,15 @@
557335 EnableWindow(GetDlgItem(hWnd,IDC_VIDMODES),FALSE);
558336 SendDlgItemMessage(hWnd,IDC_WINDOWED,BM_SETCHECK,BST_CHECKED,0);
559337 SendDlgItemMessage(hWnd,IDC_FULLSCREEN,BM_SETCHECK,BST_UNCHECKED,0);
560 - fullscreen3d = false;
 338+ fullscreen = false;
561339 }
562340 SendDlgItemMessage(hWnd,IDC_BUFFERS,EM_SETLIMITTEXT,2,0);
563341 SendDlgItemMessage(hWnd,IDC_APIVER,EM_SETLIMITTEXT,1,0);
564342 SendDlgItemMessage(hWnd,IDC_FRAMERATE,EM_SETLIMITTEXT,5,0);
565 - SendDlgItemMessage(hWnd,IDC_BUFFERS,WM_SETTEXT,0,(LPARAM)_itot(buffer3d,tmpstring,10));
566 - SendDlgItemMessage(hWnd,IDC_APIVER,WM_SETTEXT,0,(LPARAM)_itot(api3d,tmpstring,10));
567 - _stprintf(framerate3dstring,_T("%.2f"),framerate3d);
568 - SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_SETTEXT,0,(LPARAM)framerate3dstring);
 343+ SendDlgItemMessage(hWnd,IDC_BUFFERS,WM_SETTEXT,0,(LPARAM)_itot(buffer,tmpstring,10));
 344+ SendDlgItemMessage(hWnd,IDC_APIVER,WM_SETTEXT,0,(LPARAM)_itot(api,tmpstring,10));
 345+ _stprintf(frameratestring,_T("%.2f"),framerate);
 346+ SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_SETTEXT,0,(LPARAM)frameratestring);
569347 }
570348 }
571349 break;
——@@ -572,16 +350,16 @@
573351 if(HIWORD(wParam) == EN_CHANGE)
574352 {
575353 SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_GETTEXT,6,(LPARAM)tmpstring);
576 - if(_tcscmp(framerate3dstring,tmpstring))
 354+ if(_tcscmp(frameratestring,tmpstring))
577355 {
578356 pos = LOWORD(SendDlgItemMessage(hWnd,IDC_FRAMERATE,EM_GETSEL,NULL,NULL));
579357 i = _tcslen(tmpstring);
580358 f = _ttof(tmpstring);
581 - if(errno != ERANGE) framerate3d = f;
582 - if(framerate3d < 0.5) framerate3d = 0.5;
583 - if(framerate3d > 99.99) framerate3d = 99.99;
584 - _stprintf(framerate3dstring,_T("%.2f"),framerate3d);
585 - SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_SETTEXT,0,(LPARAM)framerate3dstring);
 359+ if(errno != ERANGE) framerate = f;
 360+ if(framerate < 0.5) framerate = 0.5;
 361+ if(framerate > 99.99) framerate = 99.99;
 362+ _stprintf(frameratestring,_T("%.2f"),framerate);
 363+ SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_SETTEXT,0,(LPARAM)frameratestring);
586364 SendDlgItemMessage(hWnd,IDC_FRAMERATE,EM_SETSEL,pos,pos);
587365 }
588366 }
——@@ -591,14 +369,14 @@
592370 {
593371 SendDlgItemMessage(hWnd,IDC_APIVER,WM_GETTEXT,6,(LPARAM)tmpstring);
594372 i = _ttoi(tmpstring);
595 - if(i != api3d)
 373+ if(i != api)
596374 {
597 - api3d = i;
598 - if(api3d == 5) api3d = 4;
599 - if(api3d == 6) api3d = 7;
600 - if(api3d < minapi3d) api3d = minapi3d;
601 - if(api3d > maxapi3d) api3d = maxapi3d;
602 - _itot(api3d,tmpstring,10);
 375+ api = i;
 376+ if(api == 5) api = 4;
 377+ if(api == 6) api = 7;
 378+ if(api < minapi) api = minapi;
 379+ if(api > maxapi) api = maxapi;
 380+ _itot(api,tmpstring,10);
603381 SendDlgItemMessage(hWnd,IDC_APIVER,WM_SETTEXT,0,(LPARAM)tmpstring);
604382 }
605383 }
——@@ -608,33 +386,36 @@
609387 {
610388 SendDlgItemMessage(hWnd,IDC_BUFFERS,WM_GETTEXT,6,(LPARAM)tmpstring);
611389 i = _ttoi(tmpstring);
612 - if(i != buffer3d)
 390+ if(i != buffer)
613391 {
614 - buffer3d = i;
615 - if(buffer3d < minbuffer3d) buffer3d = minbuffer3d;
616 - if(buffer3d > maxbuffer3d) buffer3d = maxbuffer3d;
617 - _itot(buffer3d,tmpstring,10);
 392+ buffer = i;
 393+ if(buffer < minbuffer) buffer = minbuffer;
 394+ if(buffer > maxbuffer) buffer = maxbuffer;
 395+ _itot(buffer,tmpstring,10);
618396 SendDlgItemMessage(hWnd,IDC_BUFFERS,WM_SETTEXT,0,(LPARAM)tmpstring);
619397 }
620398 }
621399 break;
622400 case IDC_TEST:
623 - if(SendDlgItemMessage(hWnd,IDC_RESIZABLE,BM_GETCHECK,0,0)) resizable3d = true;
624 - else resizable3d = false;
625 - i = SendDlgItemMessage(hWnd,IDC_VIDMODES,LB_GETCURSEL,0,0);
 401+ if(SendDlgItemMessage(hWnd,IDC_RESIZABLE,BM_GETCHECK,0,0)) resizable = true;
 402+ else resizable = false;
 403+ if (buffer < minbuffer) buffer = minbuffer;
 404+ if (buffer > maxbuffer) buffer = maxbuffer;
 405+ i = SendDlgItemMessage(hWnd, IDC_VIDMODES, LB_GETCURSEL, 0, 0);
626406 SendDlgItemMessage(hWnd,IDC_VIDMODES,LB_GETTEXT,i,(LPARAM)tmpstring);
627407 TranslateResolutionString(tmpstring,width,height,bpp,refresh);
628 - RunTest3D(currenttest3d,width,height,bpp,refresh,buffer3d,api3d,filter3d,msaa3d,framerate3d,fullscreen3d,resizable3d);
 408+ RunDXGLTest(currenttest, width, height, bpp, refresh, buffer, api,
 409+ filter, msaa, framerate, fullscreen, resizable, Tests[currenttest].is3d);
629410 break;
630411 case IDC_WINDOWED:
631412 SendDlgItemMessage(hWnd,IDC_FULLSCREEN,BM_SETCHECK,0,0);
632413 SendDlgItemMessage(hWnd,IDC_WINDOWED,BM_SETCHECK,1,0);
633 - fullscreen3d = false;
 414+ fullscreen = false;
634415 break;
635416 case IDC_FULLSCREEN:
636417 SendDlgItemMessage(hWnd,IDC_FULLSCREEN,BM_SETCHECK,1,0);
637418 SendDlgItemMessage(hWnd,IDC_WINDOWED,BM_SETCHECK,0,0);
638 - fullscreen3d = true;
 419+ fullscreen = true;
639420 break;
640421 }
641422 break;
——@@ -645,66 +426,66 @@
646427 switch(((LPNMHDR)lParam)->idFrom)
647428 {
648429 case IDC_SPINFRAME:
649 - framerate3d -= ((LPNMUPDOWN)lParam)->iDelta;
650 - if(framerate3d < 0.01) framerate3d = 0.01;
651 - if(framerate3d > 99.99) framerate3d = 99.99;
652 - _stprintf(framerate3dstring,_T("%.2f"),framerate3d);
653 - SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_SETTEXT,0,(LPARAM)framerate3dstring);
 430+ framerate -= ((LPNMUPDOWN)lParam)->iDelta;
 431+ if(framerate < 0.01) framerate = 0.01;
 432+ if(framerate > 99.99) framerate = 99.99;
 433+ _stprintf(frameratestring,_T("%.2f"),framerate);
 434+ SendDlgItemMessage(hWnd,IDC_FRAMERATE,WM_SETTEXT,0,(LPARAM)frameratestring);
654435 break;
655436 case IDC_SPINAPI:
656 - if(api3d < 1) api3d = 1;
657 - if(api3d > 7) api3d = 7;
 437+ if(api < 1) api = 1;
 438+ if(api > 7) api = 7;
658439 if(((LPNMUPDOWN)lParam)->iDelta > 0)
659440 {
660 - switch(api3d)
 441+ switch(api)
661442 {
662443 case 1:
663444 case 2:
664445 default:
665 - api3d = 1;
 446+ api = 1;
666447 break;
667448 case 3:
668 - api3d = 2;
 449+ api = 2;
669450 break;
670451 case 4:
671 - api3d = 7;
 452+ api = 3;
672453 break;
673454 case 7:
674455 case 6:
675456 case 5:
676 - api3d = 3;
 457+ api = 4;
677458 }
678459 }
679460 else
680461 {
681 - switch(api3d)
 462+ switch(api)
682463 {
683464 case 1:
684465 default:
685 - api3d = 2;
 466+ api = 2;
686467 break;
687468 case 2:
688 - api3d = 3;
 469+ api = 3;
689470 break;
690471 case 3:
691 - api3d = 7;
 472+ api = 4;
692473 break;
693474 case 4:
694475 case 5:
695476 case 6:
696477 case 7:
697 - api3d = 7;
 478+ api = 7;
698479 }
699480 }
700 - if(api3d < minapi3d) api3d = minapi3d;
701 - if(api3d > maxapi3d) api3d = maxapi3d;
702 - SendDlgItemMessage(hWnd,IDC_APIVER,WM_SETTEXT,0,(LPARAM)_itot(api3d,tmpstring,10));
 481+ if(api < minapi) api = minapi;
 482+ if(api > maxapi) api = maxapi;
 483+ SendDlgItemMessage(hWnd,IDC_APIVER,WM_SETTEXT,0,(LPARAM)_itot(api,tmpstring,10));
703484 break;
704485 case IDC_SPINBACK:
705 - buffer3d -= ((LPNMUPDOWN)lParam)->iDelta;
706 - if(buffer3d < minbuffer3d) buffer3d = minbuffer3d;
707 - if(buffer3d > maxbuffer3d) buffer3d = maxbuffer3d;
708 - SendDlgItemMessage(hWnd,IDC_BUFFERS,WM_SETTEXT,0,(LPARAM)_itot(buffer3d,tmpstring,10));
 486+ buffer -= ((LPNMUPDOWN)lParam)->iDelta;
 487+ if(buffer < minbuffer) buffer = minbuffer;
 488+ if(buffer > maxbuffer) buffer = maxbuffer;
 489+ SendDlgItemMessage(hWnd,IDC_BUFFERS,WM_SETTEXT,0,(LPARAM)_itot(buffer,tmpstring,10));
709490 break;
710491 default:
711492 break;
——@@ -720,7 +501,6 @@
721502 return TRUE;
722503 }
723504
724 -
725505 HWND tabwnd[3];
726506 int tabopen;
727507 INT_PTR CALLBACK DXGLTestCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
——@@ -744,14 +524,11 @@
745525 tab.mask = TCIF_TEXT;
746526 tab.pszText = _T("System");
747527 SendDlgItemMessage(hWnd,IDC_TABS,TCM_INSERTITEM,0,(LPARAM)&tab);
748 - tab.pszText = _T("2D Graphics");
 528+ tab.pszText = _T("Graphics tests");
749529 hTab = GetDlgItem(hWnd,IDC_TABS);
750530 SendDlgItemMessage(hWnd,IDC_TABS,TCM_INSERTITEM,1,(LPARAM)&tab);
751 - tab.pszText = _T("3D Graphics");
752 - SendDlgItemMessage(hWnd,IDC_TABS,TCM_INSERTITEM,2,(LPARAM)&tab);
753531 tabwnd[0] = CreateDialog(hinstance,MAKEINTRESOURCE(IDD_SYSINFO),hTab,SysTabCallback);
754 - tabwnd[1] = CreateDialog(hinstance,MAKEINTRESOURCE(IDD_TESTGFX),hTab,Test2DCallback);
755 - tabwnd[2] = CreateDialog(hinstance,MAKEINTRESOURCE(IDD_TESTGFX),hTab,Test3DCallback);
 532+ tabwnd[1] = CreateDialog(hinstance,MAKEINTRESOURCE(IDD_TESTGFX),hTab,TestTabCallback);
756533 SendDlgItemMessage(hWnd,IDC_TABS,TCM_GETITEMRECT,0,(LPARAM)&tabrect);
757534 SetWindowPos(tabwnd[0],NULL,tabrect.left,tabrect.bottom+3,0,0,SWP_SHOWWINDOW|SWP_NOSIZE);
758535 ShowWindow(tabwnd[1],SW_HIDE);
Index: dxgltest/dxgltest.vcxproj
——@@ -213,7 +213,7 @@
214214 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
215215 </ClCompile>
216216 <ClCompile Include="MultiDD.cpp" />
217 - <ClCompile Include="Tests2D.cpp" />
 217+ <ClCompile Include="tests.cpp" />
218218 <ClCompile Include="dxgltest.cpp" />
219219 <ClCompile Include="palette.cpp" />
220220 <ClCompile Include="precomp.cpp">
——@@ -224,7 +224,6 @@
225225 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
226226 </ClCompile>
227227 <ClCompile Include="surfacegen.cpp" />
228 - <ClCompile Include="Tests3D.cpp" />
229228 <ClCompile Include="timer.cpp" />
230229 </ItemGroup>
231230 <ItemGroup>
Index: dxgltest/dxgltest.vcxproj.filters
——@@ -59,9 +59,6 @@
6060 <ClCompile Include="precomp.cpp">
6161 <Filter>Source Files</Filter>
6262 </ClCompile>
63 - <ClCompile Include="Tests2D.cpp">
64 - <Filter>Source Files</Filter>
65 - </ClCompile>
6663 <ClCompile Include="MultiDD.cpp">
6764 <Filter>Source Files</Filter>
6865 </ClCompile>
——@@ -71,7 +68,7 @@
7269 <ClCompile Include="dxguid.cpp">
7370 <Filter>Source Files</Filter>
7471 </ClCompile>
75 - <ClCompile Include="Tests3D.cpp">
 72+ <ClCompile Include="tests.cpp">
7673 <Filter>Source Files</Filter>
7774 </ClCompile>
7875 </ItemGroup>
Index: dxgltest/tests.cpp
——@@ -0,0 +1,3173 @@
 2+// DXGL
 3+// Copyright (C) 2011 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+#include "common.h"
 20+#include "MultiDD.h"
 21+#include "tests.h"
 22+#include "surfacegen.h"
 23+#include "timer.h"
 24+#include "misc.h"
 25+#define D3D_OVERLOADS
 26+#include "../ddraw/include/d3d.h"
 27+
 28+void InitTest(int test);
 29+void RunTestTimed(int test);
 30+void RunTestLooped(int test);
 31+void RunTestMouse(int test, UINT Msg, WPARAM wParam, LPARAM lParam);
 32+
 33+
 34+static MultiDirectDraw *ddinterface;
 35+static MultiDirectDrawSurface *ddsurface;
 36+static MultiDirectDrawSurface *ddsrender;
 37+static MultiDirectDrawSurface *zbuffer;
 38+static MultiDirectDrawSurface *textures[8];
 39+static IDirectDrawPalette *pal;
 40+static IDirect3D7 *d3d7;
 41+static IDirect3DDevice7 *d3d7dev;
 42+D3DMATERIAL7 material;
 43+static LPDIRECTDRAWCLIPPER ddclipper;
 44+static int width,height,bpp,refresh,backbuffers;
 45+static double fps;
 46+static bool fullscreen,resizable;
 47+static HWND hWnd;
 48+static int testnum;
 49+static unsigned int randnum;
 50+static int testtypes[] = {0,1,0,1,0,1,2,0,2,1,0,0,0,0,0,0};
 51+static DWORD counter;
 52+
 53+#define FVF_COLORVERTEX (D3DFVF_VERTEX | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
 54+struct COLORVERTEX
 55+{
 56+ D3DVALUE x;
 57+ D3DVALUE y;
 58+ D3DVALUE z;
 59+ D3DVALUE nx;
 60+ D3DVALUE ny;
 61+ D3DVALUE nz;
 62+ D3DCOLOR color;
 63+ D3DCOLOR specular;
 64+ D3DVALUE tu;
 65+ D3DVALUE tv;
 66+public:
 67+ COLORVERTEX() {};
 68+ COLORVERTEX(const D3DVECTOR& v, const D3DVECTOR& n, D3DCOLOR _color,
 69+ D3DCOLOR _specular, D3DVALUE _tu, D3DVALUE _tv)
 70+ {
 71+ x = v.x; y = v.y; z = v.z;
 72+ nx = n.x; ny = n.y; nz = n.z;
 73+ color = _color; specular = _specular;
 74+ tu = _tu; tv = _tv;
 75+ }
 76+
 77+};
 78+
 79+static int numpoints = 0;
 80+static int numindices = 0;
 81+static D3DVERTEX *vertices = NULL;
 82+static D3DLVERTEX *litvertices = NULL;
 83+static COLORVERTEX *colorvertices = NULL;
 84+static WORD *mesh = NULL;
 85+static D3DLIGHT7 lights[8];
 86+static BOOL lightenable[8];
 87+static DWORD bgcolor = 0;
 88+
 89+typedef struct
 90+{
 91+ DWORD ambient;
 92+ DWORD diffuse;
 93+ DWORD specular;
 94+} HEXLIGHTCOLOR;
 95+HEXLIGHTCOLOR hexlightcolor[8];
 96+
 97+typedef struct
 98+{
 99+ D3DTEXTUREOP colorop;
 100+ DWORD colorarg1;
 101+ DWORD colorarg2;
 102+ D3DTEXTUREOP alphaop;
 103+ DWORD alphaarg1;
 104+ DWORD alphaarg2;
 105+ DWORD texturetype;
 106+ TCHAR texturefile[MAX_PATH + 1];
 107+ MultiDirectDrawSurface* texture;
 108+ BOOL colorkey;
 109+ DWORD keycolor;
 110+} TEXSTAGE;
 111+
 112+typedef struct
 113+{
 114+ int currentstage;
 115+ TEXSTAGE texstages[8];
 116+ DWORD diffuse;
 117+ DWORD specular;
 118+ DWORD factor;
 119+ D3DFOGMODE vertexfog;
 120+ D3DFOGMODE pixelfog;
 121+ FLOAT fogstart;
 122+ FLOAT fogend;
 123+ FLOAT fogdensity;
 124+ BOOL rangefog;
 125+ DWORD fogcolor;
 126+ BOOL alphatest;
 127+ BOOL alphastipple;
 128+ BOOL colorkey;
 129+ BOOL colorkeyblend;
 130+ D3DBLEND srcblend;
 131+ D3DBLEND destblend;
 132+ BYTE refalpha;
 133+ D3DCMPFUNC alphafunc;
 134+ D3DLINEPATTERN linepattern;
 135+ DWORD fillstippletype;
 136+ TCHAR fillstipplefile[MAX_PATH + 1];
 137+ DWORD fillstipple[32];
 138+} TEXSHADERSTATE;
 139+
 140+static TEXSHADERSTATE texshaderstate;
 141+const TEXSHADERSTATE defaulttexshaderstate =
 142+{
 143+ 0,
 144+ {
 145+ { D3DTOP_MODULATE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_SELECTARG1,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0 },
 146+ { D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0 },
 147+ { D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0 },
 148+ { D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0 },
 149+ { D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0 },
 150+ { D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0 },
 151+ { D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0 },
 152+ { D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,D3DTOP_DISABLE,D3DTA_TEXTURE,D3DTA_CURRENT,0,_T(""),NULL,FALSE,0 },
 153+ },
 154+ 0xFFFFFFFF,
 155+ 0,
 156+ 0xFFFFFFFF,
 157+ D3DFOG_NONE,
 158+ D3DFOG_NONE,
 159+ 0.0,
 160+ 1.0,
 161+ 1.0,
 162+ FALSE,
 163+ 0,
 164+ FALSE,
 165+ FALSE,
 166+ FALSE,
 167+ FALSE,
 168+ D3DBLEND_ONE,
 169+ D3DBLEND_ZERO,
 170+ 0,
 171+ D3DCMP_ALWAYS,
 172+ { 0,0 }
 173+};
 174+
 175+typedef struct
 176+{
 177+ DWORD texturetype;
 178+ TCHAR texturefile[MAX_PATH + 1];
 179+ MultiDirectDrawSurface* texture;
 180+ int currentlight;
 181+} VERTEXSHADERSTATE;
 182+static VERTEXSHADERSTATE vertexshaderstate;
 183+
 184+static DDSPRITE sprites[16];
 185+
 186+LRESULT CALLBACK DDWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 187+{
 188+ bool paintwnd = true;
 189+ POINT p;
 190+ RECT srcrect,destrect;
 191+ HRESULT error;
 192+ PAINTSTRUCT paintstruct;
 193+ switch(Msg)
 194+ {
 195+ case WM_CLOSE:
 196+ DestroyWindow(hWnd);
 197+ break;
 198+ case WM_DESTROY:
 199+ StopTimer();
 200+ for(int i = 0; i < 16; i++)
 201+ if(sprites[i].surface) sprites[i].surface->Release();
 202+ for (int i = 0; i < 8; i++)
 203+ {
 204+ if (textures[i])
 205+ {
 206+ textures[i]->Release();
 207+ textures[i] = NULL;
 208+ }
 209+ }
 210+ if (d3d7dev)
 211+ {
 212+ d3d7dev->Release();
 213+ d3d7dev = NULL;
 214+ }
 215+ if (d3d7)
 216+ {
 217+ d3d7->Release();
 218+ d3d7dev = NULL;
 219+ }
 220+ if(ddsrender)
 221+ {
 222+ ddsrender->Release();
 223+ ddsrender = NULL;
 224+ }
 225+ if(ddsurface)
 226+ {
 227+ ddsurface->Release();
 228+ ddsurface = NULL;
 229+ }
 230+ if (zbuffer)
 231+ {
 232+ zbuffer->Release();
 233+ zbuffer = NULL;
 234+ }
 235+ if(pal)
 236+ {
 237+ pal->Release();
 238+ pal = NULL;
 239+ }
 240+ if(ddclipper)
 241+ {
 242+ ddclipper->Release();
 243+ ddclipper = NULL;
 244+ }
 245+ if(ddinterface)
 246+ {
 247+ ddinterface->Release();
 248+ ddinterface = NULL;
 249+ }
 250+ if (mesh)
 251+ {
 252+ free(mesh);
 253+ mesh = NULL;
 254+ }
 255+ if (vertices)
 256+ {
 257+ free(vertices);
 258+ vertices = NULL;
 259+ }
 260+ if (litvertices)
 261+ {
 262+ free(litvertices);
 263+ litvertices = NULL;
 264+ }
 265+ if (colorvertices)
 266+ {
 267+ free(colorvertices);
 268+ colorvertices = NULL;
 269+ }
 270+ PostQuitMessage(0);
 271+ break;
 272+ case WM_KEYDOWN:
 273+ if(wParam == VK_ESCAPE) DestroyWindow(hWnd);
 274+ break;
 275+ case WM_APP:
 276+ RunTestTimed(testnum);
 277+ break;
 278+ case WM_SIZE:
 279+ paintwnd = false;
 280+ case WM_PAINT:
 281+ if(paintwnd) BeginPaint(hWnd,&paintstruct);
 282+ if(!fullscreen)
 283+ {
 284+ p.x = 0;
 285+ p.y = 0;
 286+ ClientToScreen(hWnd,&p);
 287+ GetClientRect(hWnd,&destrect);
 288+ OffsetRect(&destrect,p.x,p.y);
 289+ SetRect(&srcrect,0,0,width,height);
 290+ if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
 291+ }
 292+ if(paintwnd) EndPaint(hWnd,&paintstruct);
 293+ return 0;
 294+ case WM_MOUSEMOVE:
 295+ case WM_LBUTTONDOWN:
 296+ case WM_LBUTTONUP:
 297+ case WM_LBUTTONDBLCLK:
 298+ case WM_RBUTTONDOWN:
 299+ case WM_RBUTTONUP:
 300+ case WM_RBUTTONDBLCLK:
 301+ case WM_MBUTTONDOWN:
 302+ case WM_MBUTTONUP:
 303+ case WM_MBUTTONDBLCLK:
 304+ case WM_MOUSEWHEEL:
 305+ case WM_XBUTTONDOWN:
 306+ case WM_XBUTTONUP:
 307+ case WM_XBUTTONDBLCLK:
 308+ case WM_MOUSEHWHEEL:
 309+ RunTestMouse(testnum,Msg,wParam,lParam);
 310+ if(!fullscreen)
 311+ {
 312+ if ((testnum != 4) && (testnum != 10) && (testnum != 11))
 313+ {
 314+ p.x = 0;
 315+ p.y = 0;
 316+ ClientToScreen(hWnd, &p);
 317+ GetClientRect(hWnd, &destrect);
 318+ OffsetRect(&destrect, p.x, p.y);
 319+ SetRect(&srcrect, 0, 0, width, height);
 320+ if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
 321+ }
 322+ }
 323+ break;
 324+ default:
 325+ return DefWindowProc(hWnd,Msg,wParam,lParam);
 326+ }
 327+ return FALSE;
 328+}
 329+
 330+static int ddtestnum;
 331+static int d3dver;
 332+static int ddver;
 333+
 334+void RunTestMouse(int test, UINT Msg, WPARAM wParam, LPARAM lParam)
 335+{
 336+ if(!ddsrender) return;
 337+ DDSURFACEDESC2 ddsd;
 338+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 339+ DDBLTFX bltfx;
 340+ unsigned char *surface;
 341+ int bytes;
 342+ unsigned int x,y;
 343+ bool out = false;
 344+ bool msgbottom = false;
 345+ TCHAR message[256];
 346+ message[0] = 0;
 347+ HDC hDC;
 348+ switch(test)
 349+ {
 350+ case 6:
 351+ x = LOWORD(lParam);
 352+ y = HIWORD(lParam);
 353+ ZeroMemory(&bltfx,sizeof(DDBLTFX));
 354+ bltfx.dwSize = sizeof(DDBLTFX);
 355+ bltfx.dwFillColor = 0;
 356+ ddsrender->Blt(NULL,NULL,NULL,DDBLT_COLORFILL,&bltfx);
 357+ if(ddver > 3)ddsd.dwSize = sizeof(DDSURFACEDESC2);
 358+ else ddsd.dwSize = sizeof(DDSURFACEDESC);
 359+ ddsrender->GetSurfaceDesc(&ddsd);
 360+ switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
 361+ {
 362+ case 8:
 363+ bytes=1;
 364+ break;
 365+ case 15:
 366+ case 16:
 367+ bytes=2;
 368+ break;
 369+ case 24:
 370+ bytes=3;
 371+ break;
 372+ case 32:
 373+ default:
 374+ bytes=4;
 375+ }
 376+ _tcscpy(message,_T("Message: "));
 377+ switch(Msg)
 378+ {
 379+ case WM_MOUSEMOVE:
 380+ _tcscat(message,_T("WM_MOUSEMOVE "));
 381+ break;
 382+ case WM_LBUTTONDOWN:
 383+ _tcscat(message,_T("WM_LBUTTONDOWN "));
 384+ break;
 385+ case WM_LBUTTONUP:
 386+ _tcscat(message,_T("WM_LBUTTONUP "));
 387+ break;
 388+ case WM_LBUTTONDBLCLK:
 389+ _tcscat(message,_T("WM_LBUTTONDBLCLK "));
 390+ break;
 391+ case WM_RBUTTONDOWN:
 392+ _tcscat(message,_T("WM_RBUTTONDOWN "));
 393+ break;
 394+ case WM_RBUTTONUP:
 395+ _tcscat(message,_T("WM_RBUTTONUP "));
 396+ break;
 397+ case WM_RBUTTONDBLCLK:
 398+ _tcscat(message,_T("WM_RBUTTONDBLCLK "));
 399+ break;
 400+ case WM_MBUTTONDOWN:
 401+ _tcscat(message,_T("WM_MBUTTONDOWN "));
 402+ break;
 403+ case WM_MBUTTONUP:
 404+ _tcscat(message,_T("WM_MBUTTONUP "));
 405+ break;
 406+ case WM_MBUTTONDBLCLK:
 407+ _tcscat(message,_T("WM_MBUTTONDBLCLK "));
 408+ break;
 409+ case WM_MOUSEWHEEL:
 410+ _tcscat(message,_T("WM_MOUSEWHEEL "));
 411+ break;
 412+ case WM_XBUTTONDOWN:
 413+ _tcscat(message,_T("WM_XBUTTONDOWN "));
 414+ break;
 415+ case WM_XBUTTONUP:
 416+ _tcscat(message,_T("WM_XBUTTONUP "));
 417+ break;
 418+ case WM_XBUTTONDBLCLK:
 419+ _tcscat(message,_T("WM_XBUTTONDBLCLK "));
 420+ break;
 421+ case WM_MOUSEHWHEEL:
 422+ _tcscat(message,_T("WM_MOUSEHWHEEL "));
 423+ break;
 424+ default:
 425+ _tcscat(message,_T("unknown "));
 426+ }
 427+ _tcscat(message,_T("Keys: "));
 428+ if(wParam & MK_CONTROL) _tcscat(message, _T("CTRL "));
 429+ if(wParam & MK_SHIFT) _tcscat(message,_T("SHIFT "));
 430+ _tcscat(message,_T("Buttons: "));
 431+ if(wParam & MK_LBUTTON) _tcscat(message,_T("L "));
 432+ if(wParam & MK_MBUTTON) _tcscat(message,_T("M "));
 433+ if(wParam & MK_RBUTTON) _tcscat(message,_T("R "));
 434+ if(wParam & MK_XBUTTON1) _tcscat(message,_T("X1 "));
 435+ if(wParam & MK_XBUTTON2) _tcscat(message,_T("X2 "));
 436+ // Add X and Y
 437+ ddsrender->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
 438+ surface = (unsigned char *)ddsd.lpSurface;
 439+ if((x > ddsd.dwWidth) || (y > ddsd.dwHeight))
 440+ {
 441+ out = true;
 442+ _tcscat(message,_T(" OUT OF BOUNDS"));
 443+ }
 444+ else surface[(x*bytes)+(y*ddsd.lPitch)] = 0xFF;
 445+ ddsrender->Unlock(NULL);
 446+ ddsrender->GetDC(&hDC);
 447+ if(out)SetBkColor(hDC,RGB(255,0,0));
 448+ else SetBkColor(hDC,RGB(0,0,255));
 449+ SetTextColor(hDC,RGB(255,255,255));
 450+ if(y > ddsd.dwHeight / 2) TextOut(hDC,0,0,message,_tcslen(message));
 451+ else TextOut(hDC,0,ddsd.dwHeight-16,message,_tcslen(message));
 452+ ddsrender->ReleaseDC(hDC);
 453+ break;
 454+ default:
 455+ break;
 456+ }
 457+}
 458+
 459+const TCHAR wndclassname[] = _T("DDTestWndClass");
 460+
 461+static HRESULT WINAPI zcallback(DDPIXELFORMAT *ddpf, VOID *context)
 462+{
 463+ if (ddpf->dwFlags == DDPF_ZBUFFER)
 464+ {
 465+ memcpy(context, ddpf, sizeof(DDPIXELFORMAT));
 466+ return D3DENUMRET_CANCEL;
 467+ }
 468+ return D3DENUMRET_OK;
 469+}
 470+
 471+INT_PTR CALLBACK TexShader7Proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
 472+INT_PTR CALLBACK VertexShader7Proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
 473+
 474+void RunDXGLTest(int testnum, int width, int height, int bpp, int refresh, int backbuffers, int apiver,
 475+ int filter, int msaa, double fps, bool fullscreen, bool resizable, BOOL is3d)
 476+{
 477+ ZeroMemory(sprites,16*sizeof(DDSPRITE));
 478+ if(testnum == 14)
 479+ {
 480+ DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_TEXSHADER),NULL,TexShader7Proc);
 481+ return;
 482+ }
 483+ if(testnum == 15)
 484+ {
 485+ DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_VERTEXSHADER),NULL,VertexShader7Proc);
 486+ return;
 487+ }
 488+ DDSCAPS2 caps;
 489+ DDSURFACEDESC2 ddsd;
 490+ DDPIXELFORMAT ddpfz;
 491+ BOOL done = false;
 492+ ::testnum = testnum;
 493+ randnum = (unsigned int)time(NULL);
 494+ ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
 495+ ZeroMemory(textures,8*sizeof(MultiDirectDrawSurface*));
 496+ if(apiver > 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
 497+ else ddsd.dwSize = sizeof(DDSURFACEDESC);
 498+ ::fullscreen = fullscreen;
 499+ ::resizable = resizable;
 500+ ::width = width;
 501+ ::height = height;
 502+ ::bpp = bpp;
 503+ ::refresh = refresh;
 504+ if(fullscreen)::backbuffers = backbuffers;
 505+ else ::backbuffers = backbuffers = 0;
 506+ ::fps = fps;
 507+ ::testnum = testnum;
 508+ d3dver = apiver;
 509+ if(apiver == 3) ddver = 4;
 510+ else ddver = apiver;
 511+ HINSTANCE hinstance = (HINSTANCE)GetModuleHandle(NULL);
 512+ WNDCLASSEX wc;
 513+ MSG Msg;
 514+ ZeroMemory(&wc,sizeof(WNDCLASS));
 515+ wc.cbSize = sizeof(WNDCLASSEX);
 516+ wc.style = CS_HREDRAW | CS_VREDRAW;
 517+ wc.lpfnWndProc = DDWndProc;
 518+ wc.hInstance = hinstance;
 519+ wc.hIcon = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_DXGL));
 520+ wc.hIconSm = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_DXGLSM));
 521+ if(testnum == 6) wc.hCursor = LoadCursor(NULL,IDC_CROSS);
 522+ else wc.hCursor = LoadCursor(NULL,IDC_ARROW);
 523+ wc.hbrBackground = NULL;
 524+ wc.lpszClassName = wndclassname;
 525+ if(!RegisterClassEx(&wc))
 526+ {
 527+ MessageBox(NULL,_T("Can not register window class"),_T("Error"),MB_ICONEXCLAMATION|MB_OK);
 528+ return;
 529+ }
 530+ if(resizable)
 531+ hWnd = CreateWindowEx(WS_EX_APPWINDOW,wndclassname,_T("DDraw Test Window"),WS_OVERLAPPEDWINDOW,
 532+ CW_USEDEFAULT,CW_USEDEFAULT,width,height,NULL,NULL,hinstance,NULL);
 533+ else if(!fullscreen)
 534+ hWnd = CreateWindowEx(WS_EX_APPWINDOW,wndclassname,_T("DDraw Test Window"),WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
 535+ CW_USEDEFAULT,CW_USEDEFAULT,width,height,NULL,NULL,hinstance,NULL);
 536+ else hWnd = CreateWindowEx(0,wndclassname,_T("DDraw Test Window"),WS_POPUP,0,0,
 537+ GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hinstance,NULL);
 538+ DWORD err = GetLastError();
 539+ ShowWindow(hWnd,SW_SHOWNORMAL);
 540+ UpdateWindow(hWnd);
 541+ RECT r1,r2;
 542+ POINT p1;
 543+ HRESULT error;
 544+ ddinterface = new MultiDirectDraw(ddver,&error,NULL);
 545+ if(fullscreen) error = ddinterface->SetCooperativeLevel(hWnd,DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN);
 546+ else error = ddinterface->SetCooperativeLevel(hWnd,DDSCL_NORMAL);
 547+ if(fullscreen) error = ddinterface->SetDisplayMode(width,height,bpp,refresh,0);
 548+ else
 549+ {
 550+ GetClientRect(hWnd,&r1);
 551+ GetWindowRect(hWnd,&r2);
 552+ p1.x = (r2.right - r2.left) - r1.right;
 553+ p1.y = (r2.bottom - r2.top) - r1.bottom;
 554+ MoveWindow(hWnd,r2.left,r2.top,width+p1.x,height+p1.y,TRUE);
 555+ }
 556+ ddsd.dwFlags = DDSD_CAPS;
 557+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
 558+ if(fullscreen)
 559+ {
 560+ if(backbuffers)ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
 561+ ddsd.dwBackBufferCount = backbuffers;
 562+ if(backbuffers) ddsd.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
 563+ if(is3d) ddsd.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
 564+ }
 565+ error = ddinterface->CreateSurface(&ddsd,&ddsurface,NULL);
 566+ if(!fullscreen)
 567+ {
 568+ error = ddinterface->CreateClipper(0,&ddclipper,NULL);
 569+ error = ddclipper->SetHWnd(0,hWnd);
 570+ error = ddsurface->SetClipper(ddclipper);
 571+ ZeroMemory(&ddsd,sizeof(ddsd));
 572+ if(apiver > 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
 573+ else ddsd.dwSize = sizeof(DDSURFACEDESC);
 574+ ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 575+ if(is3d) ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
 576+ else ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 577+ ddsd.dwWidth = width;
 578+ ddsd.dwHeight = height;
 579+ error = ddinterface->CreateSurface(&ddsd,&ddsrender,NULL);
 580+ ddsrender->GetSurfaceDesc(&ddsd);
 581+ ::bpp = ddsd.ddpfPixelFormat.dwRGBBitCount;
 582+ }
 583+ else
 584+ {
 585+ ddsrender = ddsurface;
 586+ ddsrender->AddRef();
 587+ }
 588+ if(bpp == 8)
 589+ {
 590+ ddinterface->CreatePalette(DDPCAPS_8BIT|DDPCAPS_ALLOW256,(LPPALETTEENTRY)&DefaultPalette,&pal,NULL);
 591+ ddsrender->SetPalette(pal);
 592+ }
 593+ else pal = NULL;
 594+ if (is3d)
 595+ {
 596+ error = ddinterface->QueryInterface(IID_IDirect3D7, (VOID**)&d3d7);
 597+ error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice, zcallback, &ddpfz);
 598+ error = ddsrender->GetSurfaceDesc(&ddsd);
 599+ ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
 600+ ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
 601+ memcpy(&ddsd.ddpfPixelFormat, &ddpfz, sizeof(DDPIXELFORMAT));
 602+ error = ddinterface->CreateSurface(&ddsd, &zbuffer, NULL);
 603+ error = ddsrender->AddAttachedSurface(zbuffer);
 604+ error = d3d7->CreateDevice(IID_IDirect3DHALDevice, (LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(), &d3d7dev);
 605+ if (error != D3D_OK)
 606+ error = d3d7->CreateDevice(IID_IDirect3DRGBDevice, (LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(), &d3d7dev);
 607+ ddsrender->GetSurfaceDesc(&ddsd);
 608+ D3DVIEWPORT7 vp = { 0,0,ddsd.dwWidth,ddsd.dwHeight,0.0f,1.0f };
 609+ error = d3d7dev->SetViewport(&vp);
 610+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_ZENABLE, TRUE);
 611+ }
 612+ InitTest(testnum);
 613+ if(!fullscreen) SendMessage(hWnd,WM_PAINT,0,0);
 614+ if(testtypes[testnum] == 1)
 615+ {
 616+ while(!done)
 617+ {
 618+ if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
 619+ {
 620+ if(Msg.message == WM_PAINT) RunTestLooped(testnum);
 621+ else if(Msg.message == WM_QUIT) done = TRUE;
 622+ else
 623+ {
 624+ TranslateMessage(&Msg);
 625+ DispatchMessage(&Msg);
 626+ }
 627+ }
 628+ else
 629+ {
 630+ RunTestLooped(testnum);
 631+ }
 632+ }
 633+ }
 634+ else if(testtypes[testnum] == 0)
 635+ {
 636+ StartTimer(hWnd,WM_APP,fps);
 637+ while(GetMessage(&Msg, NULL, 0, 0) > 0)
 638+ {
 639+ TranslateMessage(&Msg);
 640+ DispatchMessage(&Msg);
 641+ }
 642+ }
 643+ else
 644+ {
 645+ while(GetMessage(&Msg, NULL, 0, 0) > 0)
 646+ {
 647+ TranslateMessage(&Msg);
 648+ DispatchMessage(&Msg);
 649+ }
 650+ }
 651+ UnregisterClass(wndclassname,hinstance);
 652+ StopTimer();
 653+}
 654+
 655+void MakeCube3D(float size, int detail)
 656+{
 657+ if (detail < 2) return;
 658+ D3DVECTOR normals[6];
 659+ normals[0] = D3DVECTOR(0.0f, 0.0f, -1.0f);
 660+ normals[1] = D3DVECTOR(1.0f, 0.0f, 0.0f);
 661+ normals[2] = D3DVECTOR(0.0f, 0.0f, 1.0f);
 662+ normals[3] = D3DVECTOR(-1.0f, 0.0f, 0.0f);
 663+ normals[4] = D3DVECTOR(0.0f, 1.0f, 0.0f);
 664+ normals[5] = D3DVECTOR(0.0f, -1.0f, 0.0f);
 665+ int numfacevertices = detail*detail;
 666+ D3DVECTOR *face = (D3DVECTOR*)malloc(numfacevertices * sizeof(D3DVECTOR));
 667+ int numfaceindices = ((detail - 1)*(detail - 1)) * 6;
 668+ WORD *faceindex = (WORD*)malloc(numfaceindices * sizeof(WORD));
 669+ int ptr = 0;
 670+ float fx, fy;
 671+ // Generate points
 672+ for (int y = 0; y < detail; y++)
 673+ {
 674+ fy = (((float)(y / (float)(detail - 1))) - .5f)*size;
 675+ for (int x = 0; x < detail; x++)
 676+ {
 677+ fx = (((float)(x / (float)(detail - 1))) - .5f)*size;
 678+ face[ptr] = D3DVECTOR(fx, fy, 0);
 679+ ptr++;
 680+ }
 681+ }
 682+ // Generate triangle indices
 683+ ptr = 0;
 684+ for (int y = 0; y < (detail - 1); y++)
 685+ {
 686+ for (int x = 0; x < (detail - 1); x++)
 687+ {
 688+ faceindex[ptr++] = x + (detail*y);
 689+ faceindex[ptr++] = x + (detail*(y + 1));
 690+ faceindex[ptr++] = (x + 1) + (detail*y);
 691+ faceindex[ptr++] = (x + 1) + (detail*y);
 692+ faceindex[ptr++] = x + (detail*(y + 1));
 693+ faceindex[ptr++] = (x + 1) + (detail*(y + 1));
 694+ }
 695+ }
 696+ numpoints = (detail*detail) * 6;
 697+ numindices = ((detail - 1)*(detail - 1)) * 36;
 698+ if (vertices) free(vertices);
 699+ if (litvertices) free(litvertices);
 700+ if (colorvertices) free(colorvertices);
 701+ if (mesh) free(mesh);
 702+ vertices = (D3DVERTEX*)malloc(numpoints * sizeof(D3DVERTEX));
 703+ litvertices = (D3DLVERTEX*)malloc(numpoints * sizeof(D3DLVERTEX));
 704+ colorvertices = (COLORVERTEX*)malloc(numpoints * sizeof(COLORVERTEX));
 705+ mesh = (WORD*)malloc(numindices * sizeof(WORD));
 706+ // Generate vertex list
 707+ float u, v;
 708+ D3DVECTOR pos;
 709+ D3DVECTOR normal;
 710+ // Front face
 711+ ptr = 0;
 712+ for (int y = 0; y < detail; y++)
 713+ {
 714+ for (int x = 0; x < detail; x++)
 715+ {
 716+ u = (float)x / (float)(detail - 1);
 717+ v = 1.f - ((float)y / (float)(detail - 1));
 718+ ptr = x + (detail*y);
 719+ pos = D3DVECTOR(face[ptr].x, face[ptr].y, -size / 2.f);
 720+ normal = D3DVECTOR(0, 0, -1);
 721+ vertices[ptr] = D3DVERTEX(pos, normal, u, v);
 722+ litvertices[ptr] = D3DLVERTEX(pos, 0xFFFFFFFF, 0, u, v);
 723+ colorvertices[ptr] = COLORVERTEX(pos, normal, 0xFFFFFFFF, 0, u, v);
 724+ }
 725+ }
 726+ // Right face
 727+ ptr = 0;
 728+ for (int y = 0; y < detail; y++)
 729+ {
 730+ for (int x = 0; x < detail; x++)
 731+ {
 732+ u = (float)x / (float)(detail - 1);
 733+ v = 1.f - ((float)y / (float)(detail - 1));
 734+ ptr = x + (detail*y);
 735+ pos = D3DVECTOR(size / 2.f, face[ptr].y, face[ptr].x);
 736+ normal = D3DVECTOR(1, 0, 0);
 737+ vertices[ptr + numfacevertices] = D3DVERTEX(pos, normal, u, v);
 738+ litvertices[ptr + numfacevertices] = D3DLVERTEX(pos, 0xFFFFFFFF, 0, u, v);
 739+ colorvertices[ptr + numfacevertices] = COLORVERTEX(pos, normal, 0xFFFFFFFF, 0, u, v);
 740+ }
 741+ }
 742+ // Back face
 743+ ptr = 0;
 744+ for (int y = 0; y < detail; y++)
 745+ {
 746+ for (int x = 0; x < detail; x++)
 747+ {
 748+ u = (float)x / (float)(detail - 1);
 749+ v = 1.f - ((float)y / (float)(detail - 1));
 750+ ptr = x + (detail*y);
 751+ pos = D3DVECTOR(-face[ptr].x, face[ptr].y, size / 2.f);
 752+ normal = D3DVECTOR(0, 0, 1);
 753+ vertices[ptr + (numfacevertices * 2)] = D3DVERTEX(pos, normal, u, v);
 754+ litvertices[ptr + (numfacevertices * 2)] = D3DLVERTEX(pos, 0xFFFFFFFF, 0, u, v);
 755+ colorvertices[ptr + (numfacevertices * 2)] = COLORVERTEX(pos, normal, 0xFFFFFFFF, 0, u, v);
 756+ }
 757+ }
 758+ // Left face
 759+ ptr = 0;
 760+ for (int y = 0; y < detail; y++)
 761+ {
 762+ for (int x = 0; x < detail; x++)
 763+ {
 764+ u = (float)x / (float)(detail - 1);
 765+ v = 1.f - ((float)y / (float)(detail - 1));
 766+ ptr = x + (detail*y);
 767+ pos = D3DVECTOR(-size / 2.f, face[ptr].y, -face[ptr].x);
 768+ normal = D3DVECTOR(-1, 0, 0);
 769+ vertices[ptr + (numfacevertices * 3)] = D3DVERTEX(pos, normal, u, v);
 770+ litvertices[ptr + (numfacevertices * 3)] = D3DLVERTEX(pos, 0xFFFFFFFF, 0, u, v);
 771+ colorvertices[ptr + (numfacevertices * 3)] = COLORVERTEX(pos, normal, 0xFFFFFFFF, 0, u, v);
 772+ }
 773+ }
 774+ // Top face
 775+ for (int y = 0; y < detail; y++)
 776+ {
 777+ for (int x = 0; x < detail; x++)
 778+ {
 779+ u = (float)x / (float)(detail - 1);
 780+ v = 1.f - ((float)y / (float)(detail - 1));
 781+ ptr = x + (detail*y);
 782+ pos = D3DVECTOR(face[ptr].x, size / 2.f, face[ptr].y);
 783+ normal = D3DVECTOR(0, 1, 0);
 784+ vertices[ptr + (numfacevertices * 4)] = D3DVERTEX(pos, normal, u, v);
 785+ litvertices[ptr + (numfacevertices * 4)] = D3DLVERTEX(pos, 0xFFFFFFFF, 0, u, v);
 786+ colorvertices[ptr + (numfacevertices * 4)] = COLORVERTEX(pos, normal, 0xFFFFFFFF, 0, u, v);
 787+ }
 788+ }
 789+ // Bottom face
 790+ for (int y = 0; y < detail; y++)
 791+ {
 792+ for (int x = 0; x < detail; x++)
 793+ {
 794+ u = (float)x / (float)(detail - 1);
 795+ v = 1.f - ((float)y / (float)(detail - 1));
 796+ ptr = x + (detail*y);
 797+ pos = D3DVECTOR(face[ptr].x, -size / 2.f, -face[ptr].y);
 798+ normal = D3DVECTOR(0, -1, 0);
 799+ vertices[ptr + (numfacevertices * 5)] = D3DVERTEX(pos, normal, u, v);
 800+ litvertices[ptr + (numfacevertices * 5)] = D3DLVERTEX(pos, 0xFFFFFFFF, 0, u, v);
 801+ colorvertices[ptr + (numfacevertices * 5)] = COLORVERTEX(pos, normal, 0xFFFFFFFF, 0, u, v);
 802+ }
 803+ }
 804+ free(face);
 805+ // Generate index table
 806+ ptr = 0;
 807+ for (int i = 0; i < 6; i++)
 808+ {
 809+ for (int j = 0; j < numfaceindices; j++)
 810+ mesh[ptr++] = faceindex[j] + (i*numfacevertices);
 811+ }
 812+ free(faceindex);
 813+}
 814+
 815+void SetVertexColor(D3DLVERTEX *start, COLORVERTEX *start_color, int count, DWORD color)
 816+{
 817+ for (int i = 0; i < count; i++)
 818+ {
 819+ start[i].color = color;
 820+ start_color[i].color = color;
 821+ }
 822+}
 823+
 824+void SetVertexSpecular(D3DLVERTEX *start, COLORVERTEX *start_color, int count, DWORD color)
 825+{
 826+ for (int i = 0; i < count; i++)
 827+ {
 828+ start[i].specular = color;
 829+ start_color[i].specular = color;
 830+ }
 831+}
 832+
 833+
 834+DDPIXELFORMAT texformats[256];
 835+int texformatindex = 0;
 836+
 837+void cleartexformats()
 838+{
 839+ ZeroMemory(texformats, 256 * sizeof(DDPIXELFORMAT));
 840+ texformatindex = 0;
 841+}
 842+
 843+HRESULT CALLBACK gettexformat(LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext)
 844+{
 845+ memcpy(&texformats[texformatindex], lpDDPixFmt, sizeof(DDPIXELFORMAT));
 846+ texformatindex++;
 847+ if (texformatindex >= 256) return D3DENUMRET_CANCEL;
 848+ return D3DENUMRET_OK;
 849+}
 850+
 851+static bool gentexture(const DDPIXELFORMAT format, MultiDirectDrawSurface **surface, int width, int height, int pattern)
 852+{
 853+ DDSURFACEDESC2 ddsd;
 854+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 855+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 856+ ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_TEXTURESTAGE;
 857+ ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
 858+ ddsd.dwWidth = width;
 859+ ddsd.dwHeight = height;
 860+ ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
 861+ ddsd.ddpfPixelFormat = format;
 862+ HRESULT error = ddinterface->CreateSurface(&ddsd, surface, NULL);
 863+ if (error != D3D_OK) return false;
 864+ switch (pattern)
 865+ {
 866+ case 0:
 867+ default:
 868+ (*surface)->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
 869+ DrawPalette(ddsd, (unsigned char *)ddsd.lpSurface);
 870+ (*surface)->Unlock(NULL);
 871+ }
 872+ return true;
 873+}
 874+
 875+void MakeLights()
 876+{
 877+ for (int i = 0; i < 8; i++)
 878+ {
 879+ lightenable[i] = FALSE;
 880+ ZeroMemory(&lights[i], sizeof(D3DLIGHT7));
 881+ lights[i].dcvDiffuse.r = lights[i].dcvDiffuse.g = lights[i].dcvDiffuse.b = 1;
 882+ lights[i].dltType = D3DLIGHT_DIRECTIONAL;
 883+ hexlightcolor[i].diffuse = 0xFFFFFF;
 884+ }
 885+ lightenable[0] = TRUE;
 886+ lights[0].dvPosition = D3DVECTOR(-10, -10, -10);
 887+ lights[1].dvPosition = D3DVECTOR(10, -10, -10);
 888+ lights[2].dvPosition = D3DVECTOR(-10, 10, -10);
 889+ lights[3].dvPosition = D3DVECTOR(10, 10, -10);
 890+ lights[4].dvPosition = D3DVECTOR(-10, -10, 10);
 891+ lights[5].dvPosition = D3DVECTOR(10, -10, 10);
 892+ lights[6].dvPosition = D3DVECTOR(-10, 10, 10);
 893+ lights[7].dvPosition = D3DVECTOR(10, 10, 10);
 894+ lights[0].dvDirection = D3DVECTOR(1, 1, 1);
 895+ lights[1].dvDirection = D3DVECTOR(-1, 1, 1);
 896+ lights[2].dvDirection = D3DVECTOR(1, -1, 1);
 897+ lights[3].dvDirection = D3DVECTOR(-1, -1, 1);
 898+ lights[4].dvDirection = D3DVECTOR(1, 1, -1);
 899+ lights[5].dvDirection = D3DVECTOR(-1, 1, -1);
 900+ lights[6].dvDirection = D3DVECTOR(1, -1, -1);
 901+ lights[7].dvDirection = D3DVECTOR(-1, -1, -1);
 902+}
 903+
 904+static const DDPIXELFORMAT fmt_rgba4444 = { sizeof(DDPIXELFORMAT),DDPF_RGB | DDPF_ALPHAPIXELS,0,16,0xF00,0xF0,0xF,0xF000 };
 905+static const DDPIXELFORMAT fmt_rgba1555 = { sizeof(DDPIXELFORMAT),DDPF_RGB | DDPF_ALPHAPIXELS,0,16,0x7C00,0x3E0,0x1F,0x8000 };
 906+static const DDPIXELFORMAT fmt_rgb565 = { sizeof(DDPIXELFORMAT),DDPF_RGB,0,16,0xF800,0x7E0,0x1F,0 };
 907+static const DDPIXELFORMAT fmt_rgba8888 = { sizeof(DDPIXELFORMAT),DDPF_RGB | DDPF_ALPHAPIXELS,0,32,0xFF0000,0xFF00,0xFF,0xFF000000 };
 908+
 909+void InitTest(int test)
 910+{
 911+ DDSURFACEDESC2 ddsd;
 912+ DDSCAPS2 ddscaps;
 913+ HDC hRenderDC;
 914+ ZeroMemory(&ddscaps,sizeof(DDSCAPS2));
 915+ LPDIRECTDRAWPALETTE palette;
 916+ unsigned char *buffer;
 917+ MultiDirectDrawSurface *temp1 = NULL;
 918+ MultiDirectDrawSurface *temp2 = NULL;
 919+ HRESULT error;
 920+ D3DMATRIX matWorld;
 921+ D3DMATRIX matView;
 922+ D3DMATRIX matProj;
 923+ D3DMATRIX mat;
 924+ bgcolor = 0;
 925+ DDCOLORKEY ckey;
 926+ ckey.dwColorSpaceHighValue = ckey.dwColorSpaceLowValue = 0;
 927+ if(ddver > 3)ddsd.dwSize = sizeof(DDSURFACEDESC2);
 928+ else ddsd.dwSize = sizeof(DDSURFACEDESC);
 929+ error = ddsrender->GetSurfaceDesc(&ddsd);
 930+ switch (test)
 931+ {
 932+ case 0:
 933+ if (!fullscreen) backbuffers = 0;
 934+ buffer = (unsigned char *)malloc(ddsd.lPitch*ddsd.dwHeight);
 935+ DrawPalette(ddsd, buffer);
 936+ error = ddsrender->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
 937+ memcpy(ddsd.lpSurface, buffer, ddsd.lPitch*ddsd.dwHeight);
 938+ error = ddsrender->Unlock(NULL);
 939+ ddsrender->GetPalette(&palette);
 940+ if (backbuffers > 0)
 941+ {
 942+ ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
 943+ error = ddsrender->GetAttachedSurface(&ddscaps, &temp1);
 944+ DrawGradients(ddsd, buffer, hWnd, palette, 1, 0);
 945+ error = temp1->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
 946+ memcpy(ddsd.lpSurface, buffer, ddsd.lPitch*ddsd.dwHeight);
 947+ error = temp1->Unlock(NULL);
 948+ }
 949+ if (backbuffers > 1)
 950+ {
 951+ ddscaps.dwCaps = DDSCAPS_FLIP;
 952+ error = temp1->GetAttachedSurface(&ddscaps, &temp2);
 953+ temp1->Release();
 954+ temp1 = temp2;
 955+ DrawGradients(ddsd, buffer, hWnd, palette, 0, 0x0000FF);
 956+ error = temp1->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
 957+ memcpy(ddsd.lpSurface, buffer, ddsd.lPitch*ddsd.dwHeight);
 958+ error = temp1->Unlock(NULL);
 959+ }
 960+ if (backbuffers > 2)
 961+ {
 962+ ddscaps.dwCaps = DDSCAPS_FLIP;
 963+ error = temp1->GetAttachedSurface(&ddscaps, &temp2);
 964+ temp1->Release();
 965+ temp1 = temp2;
 966+ DrawGradients(ddsd, buffer, hWnd, palette, 0, 0x00FF00);
 967+ error = temp1->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
 968+ memcpy(ddsd.lpSurface, buffer, ddsd.lPitch*ddsd.dwHeight);
 969+ error = temp1->Unlock(NULL);
 970+ }
 971+ if (backbuffers > 3)
 972+ {
 973+ ddscaps.dwCaps = DDSCAPS_FLIP;
 974+ error = temp1->GetAttachedSurface(&ddscaps, &temp2);
 975+ temp1->Release();
 976+ temp1 = temp2;
 977+ DrawGradients(ddsd, buffer, hWnd, palette, 0, 0xFF0000);
 978+ error = temp1->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
 979+ memcpy(ddsd.lpSurface, buffer, ddsd.lPitch*ddsd.dwHeight);
 980+ error = temp1->Unlock(NULL);
 981+ }
 982+ if (temp1) temp1->Release();
 983+ free(buffer);
 984+ if (palette) palette->Release();
 985+ break;
 986+ case 2:
 987+ if (!fullscreen) backbuffers = 0;
 988+ error = ddsrender->GetDC(&hRenderDC);
 989+ DrawGDIPatterns(ddsd, hRenderDC, 0);
 990+ ddsrender->ReleaseDC(hRenderDC);
 991+ if (backbuffers > 0)
 992+ {
 993+ ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
 994+ error = ddsrender->GetAttachedSurface(&ddscaps, &temp1);
 995+ temp1->GetDC(&hRenderDC);
 996+ DrawGDIPatterns(ddsd, hRenderDC, 1);
 997+ temp1->ReleaseDC(hRenderDC);
 998+ }
 999+ if (backbuffers > 1)
 1000+ {
 1001+ ddscaps.dwCaps = DDSCAPS_FLIP;
 1002+ error = temp1->GetAttachedSurface(&ddscaps, &temp2);
 1003+ temp1->Release();
 1004+ temp1 = temp2;
 1005+ temp1->GetDC(&hRenderDC);
 1006+ DrawGDIPatterns(ddsd, hRenderDC, 2);
 1007+ temp1->ReleaseDC(hRenderDC);
 1008+ }
 1009+ if (backbuffers > 2)
 1010+ {
 1011+ ddscaps.dwCaps = DDSCAPS_FLIP;
 1012+ error = temp1->GetAttachedSurface(&ddscaps, &temp2);
 1013+ temp1->Release();
 1014+ temp1 = temp2;
 1015+ temp1->GetDC(&hRenderDC);
 1016+ DrawGDIPatterns(ddsd, hRenderDC, 3);
 1017+ temp1->ReleaseDC(hRenderDC);
 1018+ }
 1019+ if (backbuffers > 3)
 1020+ {
 1021+ ddscaps.dwCaps = DDSCAPS_FLIP;
 1022+ error = temp1->GetAttachedSurface(&ddscaps, &temp2);
 1023+ temp1->Release();
 1024+ temp1 = temp2;
 1025+ temp1->GetDC(&hRenderDC);
 1026+ DrawGDIPatterns(ddsd, hRenderDC, 4);
 1027+ temp1->ReleaseDC(hRenderDC);
 1028+ }
 1029+ if (backbuffers > 4)
 1030+ {
 1031+ ddscaps.dwCaps = DDSCAPS_FLIP;
 1032+ error = temp1->GetAttachedSurface(&ddscaps, &temp2);
 1033+ temp1->Release();
 1034+ temp1 = temp2;
 1035+ temp1->GetDC(&hRenderDC);
 1036+ DrawGDIPatterns(ddsd, hRenderDC, 5);
 1037+ temp1->ReleaseDC(hRenderDC);
 1038+ }
 1039+ if (backbuffers > 5)
 1040+ {
 1041+ ddscaps.dwCaps = DDSCAPS_FLIP;
 1042+ error = temp1->GetAttachedSurface(&ddscaps, &temp2);
 1043+ temp1->Release();
 1044+ temp1 = temp2;
 1045+ temp1->GetDC(&hRenderDC);
 1046+ DrawGDIPatterns(ddsd, hRenderDC, 6);
 1047+ temp1->ReleaseDC(hRenderDC);
 1048+ }
 1049+ if (backbuffers > 6)
 1050+ {
 1051+ ddscaps.dwCaps = DDSCAPS_FLIP;
 1052+ error = temp1->GetAttachedSurface(&ddscaps, &temp2);
 1053+ temp1->Release();
 1054+ temp1 = temp2;
 1055+ temp1->GetDC(&hRenderDC);
 1056+ DrawGDIPatterns(ddsd, hRenderDC, 7);
 1057+ temp1->ReleaseDC(hRenderDC);
 1058+ }
 1059+ if (temp1) temp1->Release();
 1060+ break;
 1061+ case 4:
 1062+ ddsrender->GetSurfaceDesc(&ddsd);
 1063+ ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 1064+ ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 1065+ ddinterface->CreateSurface(&ddsd, &sprites[0].surface, NULL);
 1066+ ddsrender->GetPalette(&palette);
 1067+ error = sprites[0].surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
 1068+ if(palette) palette->Release();
 1069+ DrawGradients(ddsd, (unsigned char *)ddsd.lpSurface, hWnd, palette, 1, 0);
 1070+ DrawDitheredColor(&ddsd, (unsigned char *)ddsd.lpSurface, 0, FALSE);
 1071+ error = sprites[0].surface->Unlock(NULL);
 1072+ sprites[0].width = (float)ddsd.dwWidth;
 1073+ sprites[0].height = (float)ddsd.dwHeight;
 1074+ sprites[0].rect.left = sprites[0].rect.top = 0;
 1075+ sprites[0].rect.right = ddsd.dwWidth;
 1076+ sprites[0].rect.bottom = ddsd.dwHeight;
 1077+ if (backbuffers) ddsrender->GetAttachedSurface(&ddscaps, &temp1);
 1078+ else temp1 = ddsrender;
 1079+ temp1->SetColorKey(DDCKEY_DESTBLT, &ckey);
 1080+ if (backbuffers) temp1->Release();
 1081+ for (int i = 1; i < 16; i++)
 1082+ {
 1083+ switch ((i - 1 & 3))
 1084+ {
 1085+ case 0:
 1086+ sprites[i].width = sprites[i].height = 64.f;
 1087+ sprites[i].ddsd.dwWidth = sprites[i].ddsd.dwHeight =
 1088+ sprites[i].rect.right = sprites[i].rect.bottom = 64;
 1089+ sprites[i].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 1090+ sprites[i].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 1091+ if (ddver > 3) sprites[i].ddsd.dwSize = sizeof(DDSURFACEDESC2);
 1092+ else sprites[i].ddsd.dwSize = sizeof(DDSURFACEDESC);
 1093+ ddinterface->CreateSurface(&sprites[i].ddsd, &sprites[i].surface, NULL);
 1094+ error = sprites[i].surface->Lock(NULL, &sprites[i].ddsd, DDLOCK_WAIT, NULL);
 1095+ DrawPalette(sprites[i].ddsd, (unsigned char *)sprites[i].ddsd.lpSurface);
 1096+ sprites[i].surface->Unlock(NULL);
 1097+ break;
 1098+ case 1:
 1099+ break;
 1100+ case 2:
 1101+ break;
 1102+ case 3:
 1103+ break;
 1104+ default:
 1105+ break;
 1106+ }
 1107+ if (i < 5) sprites[i].bltflags = 0;
 1108+ else if (i < 9)
 1109+ {
 1110+ sprites[i].bltflags = DDBLTFAST_SRCCOLORKEY;
 1111+ if (sprites[i].surface) sprites[i].surface->SetColorKey(DDCKEY_SRCBLT, &ckey);
 1112+ }
 1113+ else if (i < 13) sprites[i].bltflags = DDBLTFAST_DESTCOLORKEY;
 1114+ else
 1115+ {
 1116+ sprites[i].bltflags = DDBLTFAST_SRCCOLORKEY | DDBLTFAST_DESTCOLORKEY;
 1117+ if (sprites[i].surface) sprites[i].surface->SetColorKey(DDCKEY_SRCBLT, &ckey);
 1118+ }
 1119+ sprites[i].x = randfloat((float)ddsd.dwWidth);
 1120+ sprites[i].y = randfloat((float)ddsd.dwHeight);
 1121+ sprites[i].xvelocity = randfloat(5);
 1122+ sprites[i].yvelocity = randfloat(5);
 1123+ }
 1124+ break;
 1125+ case 7:
 1126+ if (!fullscreen) backbuffers = 0;
 1127+ ddsrender->GetSurfaceDesc(&ddsd);
 1128+ ddsrender->GetPalette(&palette);
 1129+ sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 1130+ sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 1131+ if (ddver > 3) sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC2);
 1132+ else sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC);
 1133+ memcpy(&sprites[1], &sprites[0], sizeof(DDSPRITE));
 1134+ memcpy(&sprites[2], &sprites[0], sizeof(DDSPRITE));
 1135+ memcpy(&sprites[3], &sprites[0], sizeof(DDSPRITE));
 1136+ memcpy(&sprites[4], &sprites[0], sizeof(DDSPRITE));
 1137+ memcpy(&sprites[5], &sprites[0], sizeof(DDSPRITE));
 1138+ sprites[0].width = sprites[0].height = 256.0f;
 1139+ sprites[1].width = sprites[1].height = 256.0f;
 1140+ sprites[2].width = sprites[2].height = 16.0f;
 1141+ sprites[3].width = sprites[3].height = 16.0f;
 1142+ sprites[4].width = sprites[4].height = 8.0f;
 1143+ sprites[5].width = sprites[4].height = 6.0f;
 1144+ sprites[0].ddsd.dwWidth = sprites[0].ddsd.dwHeight =
 1145+ sprites[0].rect.right = sprites[0].rect.bottom = 256;
 1146+ sprites[1].ddsd.dwWidth = sprites[1].ddsd.dwHeight =
 1147+ sprites[1].rect.right = sprites[1].rect.bottom = 256;
 1148+ sprites[2].ddsd.dwWidth = sprites[2].ddsd.dwHeight =
 1149+ sprites[2].rect.right = sprites[2].rect.bottom = 16;
 1150+ sprites[3].ddsd.dwWidth = sprites[3].ddsd.dwHeight =
 1151+ sprites[3].rect.right = sprites[3].rect.bottom = 16;
 1152+ sprites[4].ddsd.dwWidth = sprites[4].ddsd.dwHeight =
 1153+ sprites[4].rect.right = sprites[4].rect.bottom = 8;
 1154+ sprites[5].ddsd.dwWidth = sprites[5].ddsd.dwHeight =
 1155+ sprites[5].rect.right = sprites[5].rect.bottom = 6;
 1156+ ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
 1157+ ddinterface->CreateSurface(&sprites[1].ddsd, &sprites[1].surface, NULL);
 1158+ ddinterface->CreateSurface(&sprites[2].ddsd, &sprites[2].surface, NULL);
 1159+ ddinterface->CreateSurface(&sprites[3].ddsd, &sprites[3].surface, NULL);
 1160+ ddinterface->CreateSurface(&sprites[4].ddsd, &sprites[4].surface, NULL);
 1161+ ddinterface->CreateSurface(&sprites[5].ddsd, &sprites[5].surface, NULL);
 1162+ DDCAPS ddcaps;
 1163+ ddcaps.dwSize = sizeof(DDCAPS);
 1164+ ddinterface->GetCaps(&ddcaps, NULL);
 1165+ DrawROPPatterns(ddsrender, sprites, backbuffers, ddver, bpp, ddcaps.dwRops,hWnd,palette);
 1166+ if (palette) palette->Release();
 1167+ break;
 1168+ case 8:
 1169+ ddsrender->GetSurfaceDesc(&ddsd);
 1170+ sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 1171+ sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 1172+ if (ddver > 3) sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC2);
 1173+ else sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC);
 1174+ sprites[0].ddsd.dwWidth = sprites[0].ddsd.dwHeight =
 1175+ sprites[0].rect.right = sprites[0].rect.bottom = 64;
 1176+ ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
 1177+ DrawRotatedBlt(ddsrender, sprites);
 1178+ break;
 1179+ case 9:
 1180+ ddsrender->GetSurfaceDesc(&ddsd);
 1181+ sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 1182+ sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 1183+ if (ddver > 3) sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC2);
 1184+ else sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC);
 1185+ sprites[0].ddsd.dwWidth = sprites[0].ddsd.dwHeight =
 1186+ sprites[0].rect.right = sprites[0].rect.bottom = 255;
 1187+ ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
 1188+ counter = 0;
 1189+ break;
 1190+ case 10:
 1191+ case 11:
 1192+ ddsrender->GetSurfaceDesc(&ddsd);
 1193+ sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 1194+ sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 1195+ if (ddver > 3) sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC2);
 1196+ else sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC);
 1197+ switch (bpp)
 1198+ {
 1199+ case 8:
 1200+ sprites[0].width = sprites[0].height = 16;
 1201+ break;
 1202+ case 15:
 1203+ sprites[0].width = 32;
 1204+ sprites[0].height = 7;
 1205+ break;
 1206+ case 16:
 1207+ sprites[0].width = 64;
 1208+ sprites[0].height = 7;
 1209+ break;
 1210+ case 24:
 1211+ case 32:
 1212+ default:
 1213+ sprites[0].width = 256;
 1214+ sprites[0].height = 7;
 1215+ break;
 1216+ }
 1217+ sprites[0].ddsd.dwWidth = sprites[0].width;
 1218+ sprites[0].ddsd.dwHeight = sprites[0].height;
 1219+ memcpy(&sprites[1], &sprites[0], sizeof(DDSPRITE));
 1220+ memcpy(&sprites[2], &sprites[0], sizeof(DDSPRITE));
 1221+ ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
 1222+ ddinterface->CreateSurface(&sprites[1].ddsd, &sprites[1].surface, NULL);
 1223+ ddinterface->CreateSurface(&sprites[2].ddsd, &sprites[2].surface, NULL);
 1224+ sprites[1].surface->Lock(NULL, &sprites[1].ddsd, DDLOCK_WAIT, NULL);
 1225+ DrawColorKeyCompPatterns(sprites[1].ddsd, (unsigned char*)sprites[1].ddsd.lpSurface, bpp, 0);
 1226+ sprites[1].surface->Unlock(NULL);
 1227+ sprites[2].surface->Lock(NULL, &sprites[2].ddsd, DDLOCK_WAIT, NULL);
 1228+ DrawColorKeyCompPatterns(sprites[2].ddsd, (unsigned char*)sprites[2].ddsd.lpSurface, bpp, 1);
 1229+ sprites[2].surface->Unlock(NULL);
 1230+ counter = 0;
 1231+ break;
 1232+ case 12:
 1233+ MakeCube3D(5, 2);
 1234+ ZeroMemory(&material, sizeof(D3DMATERIAL7));
 1235+ material.ambient.r = 0.5f;
 1236+ material.ambient.g = 0.5f;
 1237+ material.ambient.b = 0.0f;
 1238+ material.diffuse.r = 1.0f;
 1239+ material.diffuse.g = 1.0f;
 1240+ material.diffuse.b = 1.0f;
 1241+ error = d3d7dev->SetMaterial(&material);
 1242+ error = d3d7dev->LightEnable(0, TRUE);
 1243+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);
 1244+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0x7f7f7f7f);
 1245+ mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
 1246+ mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
 1247+ mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
 1248+ mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
 1249+ matWorld = mat;
 1250+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorld);
 1251+ matView = mat;
 1252+ matView._43 = 10.0f;
 1253+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_VIEW, &matView);
 1254+ matProj = mat;
 1255+ matProj._11 = 2.0f;
 1256+ matProj._22 = 2.0f;
 1257+ matProj._34 = 1.0f;
 1258+ matProj._43 = -1.0f;
 1259+ matProj._44 = 0.0f;
 1260+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &matProj);
 1261+ ZeroMemory(&lights[0], sizeof(D3DLIGHT7));
 1262+ lights[0].dltType = D3DLIGHT_DIRECTIONAL;
 1263+ lights[0].dcvDiffuse.r = 1;
 1264+ lights[0].dcvDiffuse.g = 0;
 1265+ lights[0].dcvDiffuse.b = 1;
 1266+ lights[0].dvDirection = D3DVECTOR(5, 5, 5);
 1267+ lights[0].dvRange = D3DLIGHT_RANGE_MAX;
 1268+ lights[0].dvAttenuation1 = 0.4f;
 1269+ error = d3d7dev->SetLight(0, &lights[0]);
 1270+ break;
 1271+ case 13:
 1272+ MakeCube3D(5, 2);
 1273+ cleartexformats();
 1274+ d3d7dev->EnumTextureFormats(gettexformat, NULL);
 1275+ gentexture(fmt_rgba4444, &textures[0], 256, 256, 0);
 1276+ gentexture(fmt_rgba1555, &textures[1], 256, 256, 0);
 1277+ gentexture(fmt_rgb565, &textures[2], 256, 256, 0);
 1278+ gentexture(fmt_rgba8888, &textures[3], 256, 256, 0);
 1279+ ZeroMemory(&material, sizeof(D3DMATERIAL7));
 1280+ material.ambient.r = 1.0f;
 1281+ material.ambient.g = 1.0f;
 1282+ material.ambient.b = 1.0f;
 1283+ material.diffuse.r = 1.0f;
 1284+ material.diffuse.g = 1.0f;
 1285+ material.diffuse.b = 1.0f;
 1286+ error = d3d7dev->SetMaterial(&material);
 1287+ error = d3d7dev->LightEnable(0, TRUE);
 1288+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);
 1289+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0xFFFFFFFF);
 1290+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW);
 1291+ mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
 1292+ mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
 1293+ mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
 1294+ mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
 1295+ matWorld = mat;
 1296+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorld);
 1297+ matView = mat;
 1298+ matView._43 = 10.0f;
 1299+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_VIEW, &matView);
 1300+ matProj = mat;
 1301+ matProj._11 = 2.0f;
 1302+ matProj._22 = 2.0f;
 1303+ matProj._34 = 1.0f;
 1304+ matProj._43 = -1.0f;
 1305+ matProj._44 = 0.0f;
 1306+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &matProj);
 1307+ ZeroMemory(&lights[0], sizeof(D3DLIGHT7));
 1308+ lights[0].dltType = D3DLIGHT_DIRECTIONAL;
 1309+ lights[0].dcvDiffuse.r = 1;
 1310+ lights[0].dcvDiffuse.g = 0;
 1311+ lights[0].dcvDiffuse.b = 1;
 1312+ lights[0].dvDirection = D3DVECTOR(5, 5, 5);
 1313+ lights[0].dvRange = D3DLIGHT_RANGE_MAX;
 1314+ lights[0].dvAttenuation1 = 0.4f;
 1315+ error = d3d7dev->SetLight(0, &lights[0]);
 1316+ break;
 1317+ case 15:
 1318+ ZeroMemory(lights, 8 * sizeof(D3DLIGHT7));
 1319+ MakeLights();
 1320+ case 14:
 1321+ MakeCube3D(5, 8);
 1322+ ZeroMemory(&material, sizeof(D3DMATERIAL7));
 1323+ material.ambient.r = 1.0f;
 1324+ material.ambient.g = 1.0f;
 1325+ material.ambient.b = 1.0f;
 1326+ material.ambient.a = 1.0f;
 1327+ material.diffuse.r = 1.0f;
 1328+ material.diffuse.g = 1.0f;
 1329+ material.diffuse.b = 1.0f;
 1330+ material.diffuse.a = 1.0f;
 1331+ error = d3d7dev->SetMaterial(&material);
 1332+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
 1333+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0xffffffff);
 1334+ mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
 1335+ mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
 1336+ mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
 1337+ mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
 1338+ matWorld = mat;
 1339+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorld);
 1340+ matView = mat;
 1341+ matView._43 = 10.0f;
 1342+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_VIEW, &matView);
 1343+ matProj = mat;
 1344+ matProj._11 = 2.0f;
 1345+ matProj._22 = 2.0f;
 1346+ matProj._34 = 1.0f;
 1347+ matProj._43 = -1.0f;
 1348+ matProj._44 = 0.0f;
 1349+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &matProj);
 1350+ texshaderstate = defaulttexshaderstate;
 1351+ break;
 1352+ default:
 1353+ break;
 1354+ }
 1355+}
 1356+
 1357+void RunTestTimed(int test)
 1358+{
 1359+ if(stoptimer) return;
 1360+ DDSURFACEDESC2 ddsd;
 1361+ DDSCAPS2 ddscaps;
 1362+ DDBLTFX bltfx;
 1363+ HDC hDCdest, hDCsrc;
 1364+ RECT r1, r2;
 1365+ POINT p;
 1366+ RECT srcrect, destrect;
 1367+ HRESULT error;
 1368+ D3DMATRIX mat;
 1369+ TCHAR message[256];
 1370+ bltfx.dwSize = sizeof(DDBLTFX);
 1371+ ZeroMemory(&ddscaps,sizeof(DDSCAPS2));
 1372+ ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
 1373+ MultiDirectDrawSurface *temp1 = NULL;
 1374+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 1375+ if (d3dver >= 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
 1376+ else ddsd.dwSize = sizeof(DDSURFACEDESC);
 1377+ float time;
 1378+ switch(test)
 1379+ {
 1380+ case 0: // Palette and gradients
 1381+ case 2: // GDI patterns
 1382+ case 7: // ROP patterns
 1383+ default:
 1384+ if(fullscreen) ddsurface->Flip(NULL,DDFLIP_WAIT);
 1385+ break;
 1386+ case 4: // BltFast sprites
 1387+ if (backbuffers) ddsrender->GetAttachedSurface(&ddscaps, &temp1);
 1388+ else temp1 = ddsrender;
 1389+ bltfx.dwFillColor = 0;
 1390+ temp1->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &bltfx);
 1391+ if (backbuffers) temp1->Release();
 1392+ for(int i = 0; i < 16; i++)
 1393+ {
 1394+ sprites[i].x += sprites[i].xvelocity;
 1395+ if(sprites[i].xvelocity < 0 && sprites[i].x < 0) sprites[i].xvelocity = -sprites[i].xvelocity;
 1396+ if(sprites[i].xvelocity > 0 && (sprites[i].x + sprites[i].width) > width)
 1397+ sprites[i].xvelocity = -sprites[i].xvelocity;
 1398+ sprites[i].y += sprites[i].yvelocity;
 1399+ if(sprites[i].yvelocity < 0 && sprites[i].y < 0) sprites[i].yvelocity = -sprites[i].yvelocity;
 1400+ if(sprites[i].yvelocity > 0 && (sprites[i].y + sprites[i].height) > height)
 1401+ sprites[i].yvelocity = -sprites[i].yvelocity;
 1402+ if(sprites[i].surface)
 1403+ {
 1404+ if(backbuffers) ddsrender->GetAttachedSurface(&ddscaps,&temp1);
 1405+ else temp1 = ddsrender;
 1406+ temp1->BltFast((DWORD)sprites[i].x,(DWORD)sprites[i].y,sprites[i].surface,&sprites[i].rect,sprites[i].bltflags);
 1407+ if(backbuffers) temp1->Release();
 1408+ }
 1409+ }
 1410+ if (fullscreen)
 1411+ {
 1412+ if (backbuffers && ddsrender) ddsrender->Flip(NULL, DDFLIP_WAIT);
 1413+ }
 1414+ else
 1415+ {
 1416+ p.x = 0;
 1417+ p.y = 0;
 1418+ ClientToScreen(hWnd, &p);
 1419+ GetClientRect(hWnd, &r1);
 1420+ OffsetRect(&r1, p.x, p.y);
 1421+ SetRect(&r2, 0, 0, width, height);
 1422+ if (ddsurface && ddsrender) ddsurface->Blt(&r1, ddsrender, &r2, DDBLT_WAIT, NULL);
 1423+ }
 1424+ break;
 1425+ case 10: // Source Key Override test
 1426+ case 11: // Destination Key Override Test
 1427+ if (backbuffers) ddsrender->GetAttachedSurface(&ddscaps, &temp1);
 1428+ else temp1 = ddsrender;
 1429+
 1430+ sprites[0].surface->Blt(NULL, sprites[1].surface, NULL, DDBLT_WAIT, NULL);
 1431+ bltfx.dwSize = sizeof(DDBLTFX);
 1432+ switch (bpp)
 1433+ {
 1434+ case 8:
 1435+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1436+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue = counter;
 1437+ counter++;
 1438+ if (counter > 255) counter = 0;
 1439+ r1.left = r1.top = 0;
 1440+ r1.right = r1.bottom = 16;
 1441+ break;
 1442+ case 15:
 1443+ switch (counter >> 5)
 1444+ {
 1445+ case 0:
 1446+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1447+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1448+ (counter & 31) << 10;
 1449+ break;
 1450+ case 1:
 1451+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1452+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1453+ (counter & 31) << 5;
 1454+ break;
 1455+ case 2:
 1456+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1457+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1458+ (counter & 31);
 1459+ break;
 1460+ case 3:
 1461+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1462+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1463+ (counter & 31) + ((counter & 31) << 5);
 1464+ break;
 1465+ case 4:
 1466+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1467+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1468+ (counter & 31) + ((counter & 31) << 10);
 1469+ break;
 1470+ case 5:
 1471+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1472+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1473+ ((counter & 31) << 5) + ((counter & 31) << 10);
 1474+ break;
 1475+ case 6:
 1476+ default:
 1477+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1478+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1479+ (counter & 31) + ((counter & 31) << 5) + ((counter & 31) << 10);
 1480+ break;
 1481+ }
 1482+ counter++;
 1483+ if (counter > 223) counter = 0;
 1484+ r1.left = r1.top = 0;
 1485+ r1.right = 32;
 1486+ r1.bottom = 7;
 1487+ break;
 1488+ case 16:
 1489+ switch (counter >> 6)
 1490+ {
 1491+ case 0:
 1492+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1493+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1494+ ((counter & 63) >> 1) << 11;
 1495+ break;
 1496+ case 1:
 1497+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1498+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1499+ (counter & 63) << 5;
 1500+ break;
 1501+ case 2:
 1502+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1503+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1504+ (counter & 63) >> 1;
 1505+ break;
 1506+ case 3:
 1507+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1508+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1509+ ((counter & 63) >> 1) + ((counter & 63) << 5);
 1510+ break;
 1511+ case 4:
 1512+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1513+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1514+ ((counter & 63) >> 1) + (((counter & 63) >> 1) << 11);
 1515+ break;
 1516+ case 5:
 1517+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1518+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1519+ ((counter & 63) << 5) + (((counter & 63) >> 1) << 11);
 1520+ break;
 1521+ case 6:
 1522+ default:
 1523+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1524+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1525+ ((counter & 63) >> 1) + ((counter & 63) << 5) + (((counter & 63) >> 1) << 11);
 1526+ break;
 1527+ }
 1528+ counter++;
 1529+ if (counter > 447) counter = 0;
 1530+ r1.left = r1.top = 0;
 1531+ r1.right = 64;
 1532+ r1.bottom = 7;
 1533+ break;
 1534+ case 24:
 1535+ case 32:
 1536+ default:
 1537+ switch (counter >> 8)
 1538+ {
 1539+ case 0:
 1540+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1541+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1542+ (counter & 255) << 16;
 1543+ break;
 1544+ case 1:
 1545+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1546+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1547+ (counter & 255) << 8;
 1548+ break;
 1549+ case 2:
 1550+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1551+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1552+ counter & 255;
 1553+ break;
 1554+ case 3:
 1555+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1556+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1557+ (counter & 255) + ((counter & 255) << 8);
 1558+ break;
 1559+ case 4:
 1560+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1561+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1562+ (counter & 255) + ((counter & 255) << 16);
 1563+ break;
 1564+ case 5:
 1565+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1566+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1567+ ((counter & 255) << 8) + ((counter & 255) << 16);
 1568+ break;
 1569+ case 6:
 1570+ default:
 1571+ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = bltfx.ddckSrcColorkey.dwColorSpaceLowValue =
 1572+ bltfx.ddckDestColorkey.dwColorSpaceHighValue = bltfx.ddckDestColorkey.dwColorSpaceLowValue =
 1573+ (counter & 255) + ((counter & 255) << 8) + ((counter & 255) << 16);
 1574+ break;
 1575+ }
 1576+ counter++;
 1577+ if (counter > 1791) counter = 0;
 1578+ r1.left = r1.top = 0;
 1579+ r1.right = 256;
 1580+ r1.bottom = 7;
 1581+ break;
 1582+ }
 1583+ if (test == 10)
 1584+ sprites[0].surface->Blt(NULL, sprites[2].surface, NULL, DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE, &bltfx);
 1585+ else
 1586+ sprites[0].surface->Blt(NULL, sprites[2].surface, NULL, DDBLT_WAIT | DDBLT_KEYDESTOVERRIDE, &bltfx);
 1587+ temp1->GetDC(&hDCdest);
 1588+ sprites[0].surface->GetDC(&hDCsrc);
 1589+ if (ddver > 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
 1590+ else ddsd.dwSize = sizeof(DDSURFACEDESC);
 1591+ temp1->GetSurfaceDesc(&ddsd);
 1592+ StretchBlt(hDCdest, ((ddsd.dwWidth / 2) - 128), ((ddsd.dwHeight / 2) + 128), 256, -256,
 1593+ hDCsrc, 0, 0, r1.right, r1.bottom, SRCCOPY);
 1594+ sprites[0].surface->ReleaseDC(hDCsrc);
 1595+ SetBkColor(hDCdest, RGB(0, 0, 255));
 1596+ SetTextColor(hDCdest, RGB(255, 255, 255));
 1597+ if(test == 10)
 1598+ _tcscpy(message, _T("Source Color Key Override Test"));
 1599+ else
 1600+ _tcscpy(message, _T("Destination Color Key Override Test"));
 1601+ TextOut(hDCdest, 0, 0, message, _tcslen(message));
 1602+ _stprintf(message, _T("Color: 0x%08X "), bltfx.ddckSrcColorkey.dwColorSpaceHighValue);
 1603+ TextOut(hDCdest, 0, 16, message, _tcslen(message));
 1604+ temp1->ReleaseDC(hDCdest);
 1605+ if (backbuffers) temp1->Release();
 1606+ if (fullscreen)
 1607+ {
 1608+ if (backbuffers && ddsrender) ddsrender->Flip(NULL, DDFLIP_WAIT);
 1609+ }
 1610+ else
 1611+ {
 1612+ p.x = 0;
 1613+ p.y = 0;
 1614+ ClientToScreen(hWnd, &p);
 1615+ GetClientRect(hWnd, &r1);
 1616+ OffsetRect(&r1, p.x, p.y);
 1617+ SetRect(&r2, 0, 0, width, height);
 1618+ if (ddsurface && ddsrender) ddsurface->Blt(&r1, ddsrender, &r2, DDBLT_WAIT, NULL);
 1619+ }
 1620+ break;
 1621+ case 12:
 1622+ error = d3d7dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, bgcolor, 1.0, 0);
 1623+ time = (float)clock() / (float)CLOCKS_PER_SEC;
 1624+ mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
 1625+ mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
 1626+ mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
 1627+ mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
 1628+ mat._11 = (FLOAT)cos( (float)time );
 1629+ mat._33 = (FLOAT)cos( (float)time );
 1630+ mat._13 = -(FLOAT)sin( (float)time );
 1631+ mat._31 = (FLOAT)sin( (float)time );
 1632+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
 1633+ error = d3d7dev->BeginScene();
 1634+ error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,numpoints,mesh,numindices,0);
 1635+ error = d3d7dev->EndScene();
 1636+ if (fullscreen)
 1637+ {
 1638+ if (backbuffers) ddsurface->Flip(NULL, DDFLIP_WAIT);
 1639+ }
 1640+ else
 1641+ {
 1642+ p.x = 0;
 1643+ p.y = 0;
 1644+ ClientToScreen(hWnd, &p);
 1645+ GetClientRect(hWnd, &destrect);
 1646+ OffsetRect(&destrect, p.x, p.y);
 1647+ SetRect(&srcrect, 0, 0, width, height);
 1648+ if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
 1649+ }
 1650+ break;
 1651+ case 13:
 1652+ error = d3d7dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, bgcolor, 1.0, 0);
 1653+ time = (float)clock() / (float)CLOCKS_PER_SEC;
 1654+ mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
 1655+ mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
 1656+ mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
 1657+ mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
 1658+ mat._11 = (FLOAT)cos( (float)time );
 1659+ mat._33 = (FLOAT)cos( (float)time );
 1660+ mat._13 = -(FLOAT)sin( (float)time );
 1661+ mat._31 = (FLOAT)sin( (float)time );
 1662+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
 1663+ error = d3d7dev->BeginScene();
 1664+ error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[0]->GetSurface());
 1665+ error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices,4,0);
 1666+ error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[1]->GetSurface());
 1667+ error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+4,4,0);
 1668+ error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[2]->GetSurface());
 1669+ error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+8,4,0);
 1670+ error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[3]->GetSurface());
 1671+ error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+12,4,0);
 1672+ error = d3d7dev->EndScene();
 1673+ if (fullscreen)
 1674+ {
 1675+ if (backbuffers) ddsurface->Flip(NULL, DDFLIP_WAIT);
 1676+ }
 1677+ else
 1678+ {
 1679+ p.x = 0;
 1680+ p.y = 0;
 1681+ ClientToScreen(hWnd, &p);
 1682+ GetClientRect(hWnd, &destrect);
 1683+ OffsetRect(&destrect, p.x, p.y);
 1684+ SetRect(&srcrect, 0, 0, width, height);
 1685+ if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
 1686+ }
 1687+ break;
 1688+ case 14:
 1689+ error = d3d7dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, bgcolor, 1.0, 0);
 1690+ time = (float)clock() / (float)CLOCKS_PER_SEC;
 1691+ mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
 1692+ mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
 1693+ mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
 1694+ mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
 1695+ mat._11 = (FLOAT)cos( (float)time );
 1696+ mat._33 = (FLOAT)cos( (float)time );
 1697+ mat._13 = -(FLOAT)sin( (float)time );
 1698+ mat._31 = (FLOAT)sin( (float)time );
 1699+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
 1700+ error = d3d7dev->BeginScene();
 1701+ error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_LVERTEX,litvertices,numpoints,mesh,numindices,0);
 1702+ error = d3d7dev->EndScene();
 1703+ if (fullscreen)
 1704+ {
 1705+ if (backbuffers) ddsurface->Flip(NULL, DDFLIP_WAIT);
 1706+ }
 1707+ else
 1708+ {
 1709+ p.x = 0;
 1710+ p.y = 0;
 1711+ ClientToScreen(hWnd, &p);
 1712+ GetClientRect(hWnd, &destrect);
 1713+ OffsetRect(&destrect, p.x, p.y);
 1714+ SetRect(&srcrect, 0, 0, width, height);
 1715+ if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
 1716+ }
 1717+ break;
 1718+ case 15:
 1719+ error = d3d7dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, bgcolor, 1.0, 0);
 1720+ time = (float)clock() / (float)CLOCKS_PER_SEC;
 1721+ mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
 1722+ mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
 1723+ mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
 1724+ mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
 1725+ mat._11 = (FLOAT)cos( (float)time );
 1726+ mat._33 = (FLOAT)cos( (float)time );
 1727+ mat._13 = -(FLOAT)sin( (float)time );
 1728+ mat._31 = (FLOAT)sin( (float)time );
 1729+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
 1730+ error = d3d7dev->BeginScene();
 1731+ error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,FVF_COLORVERTEX,colorvertices,numpoints,mesh,numindices,0);
 1732+ error = d3d7dev->EndScene();
 1733+ if (fullscreen)
 1734+ {
 1735+ if (backbuffers) ddsurface->Flip(NULL, DDFLIP_WAIT);
 1736+ }
 1737+ else
 1738+ {
 1739+ p.x = 0;
 1740+ p.y = 0;
 1741+ ClientToScreen(hWnd, &p);
 1742+ GetClientRect(hWnd, &destrect);
 1743+ OffsetRect(&destrect, p.x, p.y);
 1744+ SetRect(&srcrect, 0, 0, width, height);
 1745+ if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
 1746+ }
 1747+ break;
 1748+ }
 1749+}
 1750+
 1751+void RunTestLooped(int test)
 1752+{
 1753+ randnum += rand(); // Improves randomness of "snow" patterns at certain resolutions
 1754+ HDC hdc;
 1755+ unsigned int i;
 1756+ POINT p;
 1757+ HPEN pen;
 1758+ HBRUSH brush;
 1759+ HANDLE tmphandle,tmphandle2;
 1760+ RECT srcrect,destrect;
 1761+ HRESULT error;
 1762+ DDSURFACEDESC2 ddsd;
 1763+ DDBLTFX bltfx;
 1764+ if(ddver > 3)ddsd.dwSize = sizeof(DDSURFACEDESC2);
 1765+ else ddsd.dwSize = sizeof(DDSURFACEDESC);
 1766+ error = ddsrender->GetSurfaceDesc(&ddsd);
 1767+ MultiDirectDrawSurface *temp1 = NULL;
 1768+ DDSCAPS2 ddscaps;
 1769+ DWORD bitmask;
 1770+ ZeroMemory(&ddscaps,sizeof(DDSCAPS2));
 1771+ ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
 1772+ int op;
 1773+ switch(test)
 1774+ {
 1775+ case 1:
 1776+ default:
 1777+ if(backbuffers)
 1778+ {
 1779+ ddsrender->GetAttachedSurface(&ddscaps,&temp1);
 1780+ temp1->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
 1781+ }
 1782+ else ddsrender->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
 1783+
 1784+ for(i = 0; i < ((ddsd.lPitch * ddsd.dwHeight)/4); i++)
 1785+ ((DWORD*)ddsd.lpSurface)[i] = rand32(randnum);
 1786+
 1787+ if(backbuffers)
 1788+ {
 1789+ temp1->Unlock(NULL);
 1790+ ddsrender->Flip(NULL,DDFLIP_WAIT);
 1791+ }
 1792+ else ddsrender->Unlock(NULL);
 1793+ if(!fullscreen)
 1794+ {
 1795+ p.x = 0;
 1796+ p.y = 0;
 1797+ ClientToScreen(hWnd,&p);
 1798+ GetClientRect(hWnd,&destrect);
 1799+ OffsetRect(&destrect,p.x,p.y);
 1800+ SetRect(&srcrect,0,0,width,height);
 1801+ if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
 1802+ }
 1803+ break;
 1804+ case 3:
 1805+ ddsrender->GetDC(&hdc);
 1806+ op = rand32(randnum) % 4;
 1807+ pen = CreatePen(rand32(randnum) % 5,0,RGB(rand32(randnum)%256,rand32(randnum)%256,rand32(randnum)%256));
 1808+ brush = CreateSolidBrush(RGB(rand32(randnum)%256,rand32(randnum)%256,rand32(randnum)%256));
 1809+ tmphandle = SelectObject(hdc,pen);
 1810+ tmphandle2 = SelectObject(hdc,brush);
 1811+ SetBkColor(hdc,RGB(rand32(randnum)%256,rand32(randnum)%256,rand32(randnum)%256));
 1812+ switch(op)
 1813+ {
 1814+ case 0:
 1815+ default:
 1816+ Rectangle(hdc,rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight,
 1817+ rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight);
 1818+ break;
 1819+ case 1:
 1820+ Ellipse(hdc,rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight,
 1821+ rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight);
 1822+ break;
 1823+ case 2:
 1824+ MoveToEx(hdc,rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight,NULL);
 1825+ LineTo(hdc,rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight);
 1826+ break;
 1827+ case 3:
 1828+ SetTextColor(hdc,RGB(rand32(randnum)%256,rand32(randnum)%256,rand32(randnum)%256));
 1829+ TextOut(hdc,rand32(randnum)%ddsd.dwWidth,rand32(randnum)%ddsd.dwHeight,_T("Text"),4);
 1830+ break;
 1831+ }
 1832+ SelectObject(hdc,tmphandle2);
 1833+ SelectObject(hdc,tmphandle);
 1834+ DeleteObject(brush);
 1835+ DeleteObject(pen);
 1836+ ddsrender->ReleaseDC(hdc);
 1837+ if(!fullscreen)
 1838+ {
 1839+ p.x = 0;
 1840+ p.y = 0;
 1841+ ClientToScreen(hWnd,&p);
 1842+ GetClientRect(hWnd,&destrect);
 1843+ OffsetRect(&destrect,p.x,p.y);
 1844+ SetRect(&srcrect,0,0,width,height);
 1845+ if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
 1846+ }
 1847+ break;
 1848+ case 5:
 1849+ rndrect5:
 1850+ destrect.bottom = rand32(randnum)%ddsd.dwHeight;
 1851+ destrect.top = rand32(randnum)%ddsd.dwHeight;
 1852+ destrect.left = rand32(randnum)%ddsd.dwWidth;
 1853+ destrect.right = rand32(randnum)%ddsd.dwWidth;
 1854+ if((destrect.bottom < destrect.top) || (destrect.right < destrect.left)) goto rndrect5;
 1855+ bltfx.dwSize = sizeof(DDBLTFX);
 1856+ switch(bpp)
 1857+ {
 1858+ case 8:
 1859+ bltfx.dwFillColor = rand32(randnum) % 0xFF;
 1860+ break;
 1861+ case 15:
 1862+ bltfx.dwFillColor = rand32(randnum) % 0x7FFF;
 1863+ break;
 1864+ case 16:
 1865+ bltfx.dwFillColor = rand32(randnum) % 0xFFFF;
 1866+ break;
 1867+ case 24:
 1868+ case 32:
 1869+ default:
 1870+ bltfx.dwFillColor = rand32(randnum) % 0xFFFFFF;
 1871+ break;
 1872+ }
 1873+ ddsrender->Blt(&destrect,NULL,NULL,DDBLT_COLORFILL,&bltfx);
 1874+ if(!fullscreen)
 1875+ {
 1876+ p.x = 0;
 1877+ p.y = 0;
 1878+ ClientToScreen(hWnd,&p);
 1879+ GetClientRect(hWnd,&destrect);
 1880+ OffsetRect(&destrect,p.x,p.y);
 1881+ SetRect(&srcrect,0,0,width,height);
 1882+ if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
 1883+ }
 1884+ break;
 1885+ case 9:
 1886+ bltfx.dwSize = sizeof(DDBLTFX);
 1887+ switch (bpp)
 1888+ {
 1889+ case 8:
 1890+ bitmask = 0xFF;
 1891+ break;
 1892+ case 15:
 1893+ bitmask = 0x7FFF;
 1894+ break;
 1895+ case 16:
 1896+ bitmask = 0xFFFF;
 1897+ break;
 1898+ case 24:
 1899+ bitmask = 0xFFFFFF;
 1900+ break;
 1901+ case 32:
 1902+ default:
 1903+ bitmask = 0xFFFFFFFF;
 1904+ break;
 1905+ }
 1906+ for (int y = 0; y < 255; y++)
 1907+ {
 1908+ for (int x = 0; x < 255; x++)
 1909+ {
 1910+ bltfx.dwFillColor = counter & bitmask;
 1911+ destrect.left = x;
 1912+ destrect.right = x + 1;
 1913+ destrect.top = y;
 1914+ destrect.bottom = y + 1;
 1915+ counter++;
 1916+ sprites[0].surface->Blt(&destrect, NULL, NULL, DDBLT_COLORFILL, &bltfx);
 1917+ }
 1918+ }
 1919+ ddsrender->Blt(NULL, sprites[0].surface, NULL, DDBLT_WAIT, NULL);
 1920+ if (!fullscreen)
 1921+ {
 1922+ p.x = 0;
 1923+ p.y = 0;
 1924+ ClientToScreen(hWnd, &p);
 1925+ GetClientRect(hWnd, &destrect);
 1926+ OffsetRect(&destrect, p.x, p.y);
 1927+ SetRect(&srcrect, 0, 0, width, height);
 1928+ if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
 1929+ }
 1930+ break;
 1931+ }
 1932+ if(temp1) temp1->Release();
 1933+}
 1934+
 1935+void PopulateArgCombo(HWND hWnd)
 1936+{
 1937+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Diffuse"));
 1938+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Current"));
 1939+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Texture"));
 1940+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Factor"));
 1941+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Specular"));
 1942+}
 1943+
 1944+void PopulateOpCombo(HWND hWnd, bool color)
 1945+{
 1946+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Disable"));
 1947+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Select Arg 1"));
 1948+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Select Arg 2"));
 1949+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Modulate"));
 1950+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Modulate 2x"));
 1951+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Modulate 4x"));
 1952+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Add"));
 1953+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Add Signed"));
 1954+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Add Signed 2x"));
 1955+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Subtract"));
 1956+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Add Smooth"));
 1957+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Blend Diffuse Alpha"));
 1958+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Blend Texture Alpha"));
 1959+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Blend Factor Alpha"));
 1960+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Blend Texture Alpha PM"));
 1961+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Blend Current Alpha"));
 1962+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Premodulate"));
 1963+ if (color)
 1964+ {
 1965+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Modulate Alpha Add Color"));
 1966+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Modulate Color Add Alpha"));
 1967+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Modulate Inv. Alpha Add Color"));
 1968+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Modulate Inv. Color Add Alpha"));
 1969+ }
 1970+ else
 1971+ {
 1972+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("(invalid)"));
 1973+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("(invalid)"));
 1974+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("(invalid)"));
 1975+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("(invalid)"));
 1976+ }
 1977+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Bump Env. Map"));
 1978+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Bump Env. Map Luminance"));
 1979+ if (color) SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Dot Product3"));
 1980+}
 1981+
 1982+void PopulateBlendCombo(HWND hWnd, bool src)
 1983+{
 1984+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Zero"));
 1985+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("One"));
 1986+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Source Color"));
 1987+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Inv. Src. Color"));
 1988+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Source Alpha"));
 1989+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Inv. Src. Alpha"));
 1990+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Dest. Alpha"));
 1991+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Inv. Dest. Alpha"));
 1992+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Dest. Color"));
 1993+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Inv. Dest. Color"));
 1994+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Src. Alpha Sat."));
 1995+ if (src)
 1996+ {
 1997+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Both Src. Alpha"));
 1998+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Both Inv. Src. Alpha"));
 1999+ }
 2000+}
 2001+
 2002+void PopulateCompareCombo(HWND hWnd)
 2003+{
 2004+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Never"));
 2005+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Less"));
 2006+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Equal"));
 2007+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Less or Equal"));
 2008+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Greater"));
 2009+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Not Equal"));
 2010+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Greater or Equal"));
 2011+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Always"));
 2012+}
 2013+
 2014+void PopulateFogCombo(HWND hWnd)
 2015+{
 2016+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("None"));
 2017+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Exponential"));
 2018+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Exp. Squared"));
 2019+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Linear"));
 2020+}
 2021+
 2022+void PopulateSourceCombo(HWND hWnd)
 2023+{
 2024+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Material"));
 2025+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Color 1"));
 2026+ SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("Color 2"));
 2027+}
 2028+
 2029+void strupper(TCHAR *str)
 2030+{
 2031+ TCHAR *ptr = str;
 2032+ while (*ptr != 0)
 2033+ {
 2034+ *ptr = _totupper(*ptr);
 2035+ ptr++;
 2036+ }
 2037+}
 2038+
 2039+void paddwordzeroes(TCHAR *str)
 2040+{
 2041+ TCHAR str2[16];
 2042+ str2[0] = 0;
 2043+ int len = _tcslen(str);
 2044+ if (len < 8)
 2045+ {
 2046+ for (int i = 0; i < 8 - len; i++)
 2047+ _tcscat(str2, _T("0"));
 2048+ _tcscat(str2, str);
 2049+ _tcscpy(str, str2);
 2050+ }
 2051+}
 2052+
 2053+HRESULT CALLBACK SelectTextureFormatCallback(LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext)
 2054+{
 2055+ if (lpDDPixFmt->dwFlags & (DDPF_LUMINANCE | DDPF_BUMPLUMINANCE | DDPF_BUMPDUDV)) return D3DENUMRET_OK;
 2056+ if (lpDDPixFmt->dwFourCC != 0) return D3DENUMRET_OK;
 2057+ if (!(lpDDPixFmt->dwFlags & DDPF_ALPHAPIXELS)) return D3DENUMRET_OK;
 2058+ if (lpDDPixFmt->dwRGBBitCount < 32) return D3DENUMRET_OK;
 2059+ memcpy(lpContext, lpDDPixFmt, sizeof(DDPIXELFORMAT));
 2060+ return D3DENUMRET_CANCEL;
 2061+}
 2062+
 2063+void CreateSurfaceFromBitmap(MultiDirectDrawSurface **surface, DDSURFACEDESC2 *ddsd, HDC hdc, int width, int height)
 2064+{
 2065+ ddinterface->CreateSurface(ddsd, surface, NULL);
 2066+ HDC surfacedc;
 2067+ if (surface)
 2068+ {
 2069+ (*surface)->GetDC(&surfacedc);
 2070+ BitBlt(surfacedc, 0, 0, width, height, hdc, 0, 0, SRCCOPY);
 2071+ (*surface)->ReleaseDC(surfacedc);
 2072+ }
 2073+}
 2074+
 2075+void SelectTexture(MultiDirectDrawSurface **surface, int type, DWORD colorkey, bool haskey, LPCTSTR file)
 2076+{
 2077+ DDSURFACEDESC2 ddsd;
 2078+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 2079+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 2080+ BITMAPV4HEADER bi;
 2081+ HBITMAP bitmap;
 2082+ HDC hdc;
 2083+ HDC hmemdc;
 2084+ HBITMAP holdbmp;
 2085+ HICON icon;
 2086+ VOID *bmpbits;
 2087+ ZeroMemory(&bi, sizeof(BITMAPV4HEADER));
 2088+ bi.bV4Size = sizeof(BITMAPV4HEADER);
 2089+ bi.bV4Planes = 1;
 2090+ bi.bV4BitCount = 32;
 2091+ bi.bV4V4Compression = BI_BITFIELDS;
 2092+ bi.bV4RedMask = 0x00FF0000;
 2093+ bi.bV4GreenMask = 0x0000FF00;
 2094+ bi.bV4BlueMask = 0x000000FF;
 2095+ bi.bV4AlphaMask = 0xFF000000;
 2096+ d3d7dev->EnumTextureFormats(SelectTextureFormatCallback, &ddsd.ddpfPixelFormat);
 2097+ ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
 2098+ ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_TEXTURESTAGE;
 2099+ DDCOLORKEY ckey;
 2100+ ckey.dwColorSpaceHighValue = ckey.dwColorSpaceLowValue = colorkey;
 2101+ if (haskey) ddsd.dwFlags |= DDSD_CKSRCBLT;
 2102+ if (*surface)
 2103+ {
 2104+ d3d7dev->SetTexture(texshaderstate.currentstage, NULL);
 2105+ (*surface)->Release();
 2106+ *surface = NULL;
 2107+ }
 2108+ switch (type)
 2109+ {
 2110+ case 0:
 2111+ default:
 2112+ break;
 2113+ case 1:
 2114+ break;
 2115+ case 2:
 2116+ hdc = GetDC(NULL);
 2117+ bi.bV4Width = ddsd.dwWidth = bi.bV4Height = ddsd.dwHeight = 16;
 2118+ bitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bi, DIB_RGB_COLORS, &bmpbits, NULL, 0);
 2119+ hmemdc = CreateCompatibleDC(hdc);
 2120+ ReleaseDC(NULL, hdc);
 2121+ holdbmp = (HBITMAP)SelectObject(hmemdc, bitmap);
 2122+ icon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_DXGL), IMAGE_ICON, 16, 16, 0);
 2123+ DrawIconEx(hmemdc, 0, 0, icon, 16, 16, 0, NULL, DI_NORMAL);
 2124+ CreateSurfaceFromBitmap(surface, &ddsd, hmemdc, 16, 16);
 2125+ SelectObject(hmemdc, holdbmp);
 2126+ DeleteDC(hmemdc);
 2127+ DeleteObject(bitmap);
 2128+ if (*surface && haskey) (*surface)->SetColorKey(DDCKEY_SRCBLT, &ckey);
 2129+ if (*surface) d3d7dev->SetTexture(texshaderstate.currentstage, (LPDIRECTDRAWSURFACE7)(*surface)->GetSurface());
 2130+ break;
 2131+ case 3:
 2132+ hdc = GetDC(NULL);
 2133+ bi.bV4Width = ddsd.dwWidth = bi.bV4Height = ddsd.dwHeight = 256;
 2134+ bitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bi, DIB_RGB_COLORS, &bmpbits, NULL, 0);
 2135+ hmemdc = CreateCompatibleDC(hdc);
 2136+ ReleaseDC(NULL, hdc);
 2137+ holdbmp = (HBITMAP)SelectObject(hmemdc, bitmap);
 2138+ icon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_DXGL), IMAGE_ICON, 256, 256, 0);
 2139+ DrawIconEx(hmemdc, 0, 0, icon, 256, 256, 0, NULL, DI_NORMAL);
 2140+ CreateSurfaceFromBitmap(surface, &ddsd, hmemdc, 256, 256);
 2141+ SelectObject(hmemdc, holdbmp);
 2142+ DeleteDC(hmemdc);
 2143+ DeleteObject(bitmap);
 2144+ if (*surface && haskey) (*surface)->SetColorKey(DDCKEY_SRCBLT, &ckey);
 2145+ if (*surface) d3d7dev->SetTexture(texshaderstate.currentstage, (LPDIRECTDRAWSURFACE7)(*surface)->GetSurface());
 2146+ break;
 2147+ case 4:
 2148+ break;
 2149+ }
 2150+}
 2151+
 2152+void SetShaderArg(HWND hWnd, UINT dropdown, UINT checkalpha, UINT checkinv, DWORD *texarg)
 2153+{
 2154+ DWORD arg = SendDlgItemMessage(hWnd, dropdown, CB_GETCURSEL, 0, 0);
 2155+ if (SendDlgItemMessage(hWnd, checkalpha, BM_GETCHECK, 0, 0) == BST_CHECKED)
 2156+ arg |= D3DTA_ALPHAREPLICATE;
 2157+ if (SendDlgItemMessage(hWnd, checkinv, BM_GETCHECK, 0, 0) == BST_CHECKED)
 2158+ arg |= D3DTA_COMPLEMENT;
 2159+ *texarg = arg;
 2160+}
 2161+
 2162+INT_PTR CALLBACK TexShader7Proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 2163+{
 2164+ HRESULT error;
 2165+ D3DVIEWPORT7 vp;
 2166+ HWND hDisplay;
 2167+ int number;
 2168+ float f;
 2169+ TCHAR tmpstring[MAX_PATH + 1];
 2170+ switch (Msg)
 2171+ {
 2172+ case WM_INITDIALOG:
 2173+ RECT r;
 2174+ DDSCAPS2 caps;
 2175+ DDSURFACEDESC2 ddsd;
 2176+ DDPIXELFORMAT ddpfz;
 2177+ testnum = 2;
 2178+ ddinterface = new MultiDirectDraw(7, &error, NULL);
 2179+ hDisplay = GetDlgItem(hWnd, IDC_DISPLAY);
 2180+ ::hWnd = hDisplay;
 2181+ error = ddinterface->SetCooperativeLevel(hDisplay, DDSCL_NORMAL);
 2182+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 2183+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 2184+ ddsd.dwFlags = DDSD_CAPS;
 2185+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
 2186+ error = ddinterface->CreateSurface(&ddsd, &ddsurface, NULL);
 2187+ error = ddinterface->CreateClipper(0, &ddclipper, NULL);
 2188+ error = ddclipper->SetHWnd(0, hDisplay);
 2189+ error = ddsurface->SetClipper(ddclipper);
 2190+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 2191+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 2192+ ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 2193+ ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
 2194+ GetClientRect(hDisplay, &r);
 2195+ ddsd.dwWidth = r.right;
 2196+ ddsd.dwHeight = r.bottom;
 2197+ error = ddinterface->CreateSurface(&ddsd, &ddsrender, NULL);
 2198+ error = ddinterface->QueryInterface(IID_IDirect3D7, (VOID**)&d3d7);
 2199+ error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice, zcallback, &ddpfz);
 2200+ error = ddsrender->GetSurfaceDesc(&ddsd);
 2201+ ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
 2202+ ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
 2203+ memcpy(&ddsd.ddpfPixelFormat, &ddpfz, sizeof(DDPIXELFORMAT));
 2204+ error = ddinterface->CreateSurface(&ddsd, &zbuffer, NULL);
 2205+ error = ddsrender->AddAttachedSurface(zbuffer);
 2206+ error = d3d7->CreateDevice(IID_IDirect3DHALDevice, (LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(), &d3d7dev);
 2207+ if (error != D3D_OK)
 2208+ error = d3d7->CreateDevice(IID_IDirect3DRGBDevice, (LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(), &d3d7dev);
 2209+ ddsrender->GetSurfaceDesc(&ddsd);
 2210+ vp.dvMaxZ = 1.0f;
 2211+ vp.dvMinZ = 0.0f;
 2212+ vp.dwX = vp.dwY = 0;
 2213+ vp.dwWidth = ddsd.dwWidth;
 2214+ vp.dwHeight = ddsd.dwHeight;
 2215+ error = d3d7dev->SetViewport(&vp);
 2216+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_ZENABLE, TRUE);
 2217+ InitTest(14);
 2218+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_ADDSTRING, 0, (LPARAM)_T("None"));
 2219+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_ADDSTRING, 0, (LPARAM)_T("Gradients"));
 2220+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_ADDSTRING, 0, (LPARAM)_T("DXGL logo (small)"));
 2221+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_ADDSTRING, 0, (LPARAM)_T("DXGL logo (large)"));
 2222+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_ADDSTRING, 0, (LPARAM)_T("Texture file"));
 2223+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_SETCURSEL, 0, 0);
 2224+ SendDlgItemMessage(hWnd, IDC_TEXCOLORKEY, WM_SETTEXT, 0, (LPARAM)_T(""));
 2225+ PopulateArgCombo(GetDlgItem(hWnd, IDC_CARG1));
 2226+ PopulateArgCombo(GetDlgItem(hWnd, IDC_CARG2));
 2227+ PopulateArgCombo(GetDlgItem(hWnd, IDC_AARG1));
 2228+ PopulateArgCombo(GetDlgItem(hWnd, IDC_AARG2));
 2229+ SendDlgItemMessage(hWnd, IDC_CARG1, CB_SETCURSEL, D3DTA_TEXTURE, 0);
 2230+ SendDlgItemMessage(hWnd, IDC_CARG2, CB_SETCURSEL, D3DTA_CURRENT, 0);
 2231+ SendDlgItemMessage(hWnd, IDC_AARG1, CB_SETCURSEL, D3DTA_TEXTURE, 0);
 2232+ SendDlgItemMessage(hWnd, IDC_AARG2, CB_SETCURSEL, D3DTA_CURRENT, 0);
 2233+ PopulateOpCombo(GetDlgItem(hWnd, IDC_COLOROP), true);
 2234+ PopulateOpCombo(GetDlgItem(hWnd, IDC_ALPHAOP), false);
 2235+ SendDlgItemMessage(hWnd, IDC_COLOROP, CB_SETCURSEL, D3DTOP_MODULATE - 1, 0);
 2236+ SendDlgItemMessage(hWnd, IDC_ALPHAOP, CB_SETCURSEL, D3DTOP_SELECTARG1 - 1, 0);
 2237+ SendDlgItemMessage(hWnd, IDC_DIFFUSE, WM_SETTEXT, 0, (LPARAM)_T("FFFFFFFF"));
 2238+ SendDlgItemMessage(hWnd, IDC_SPECULAR, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2239+ SendDlgItemMessage(hWnd, IDC_FACTOR, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2240+ SendDlgItemMessage(hWnd, IDC_FOGCOLOR, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2241+ SendDlgItemMessage(hWnd, IDC_BGCOLOR, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2242+ PopulateBlendCombo(GetDlgItem(hWnd, IDC_SRCBLEND), true);
 2243+ PopulateBlendCombo(GetDlgItem(hWnd, IDC_DESTBLEND), true);
 2244+ SendDlgItemMessage(hWnd, IDC_SRCBLEND, CB_SETCURSEL, D3DBLEND_ONE - 1, 0);
 2245+ SendDlgItemMessage(hWnd, IDC_DESTBLEND, CB_SETCURSEL, D3DBLEND_ZERO - 1, 0);
 2246+ PopulateCompareCombo(GetDlgItem(hWnd, IDC_ALPHAFUNC));
 2247+ SendDlgItemMessage(hWnd, IDC_ALPHAFUNC, CB_SETCURSEL, D3DCMP_ALWAYS - 1, 0);
 2248+ PopulateFogCombo(GetDlgItem(hWnd, IDC_VERTEXFOGMODE));
 2249+ PopulateFogCombo(GetDlgItem(hWnd, IDC_PIXELFOGMODE));
 2250+ SendDlgItemMessage(hWnd, IDC_VERTEXFOGMODE, CB_SETCURSEL, D3DFOG_NONE, 0);
 2251+ SendDlgItemMessage(hWnd, IDC_PIXELFOGMODE, CB_SETCURSEL, D3DFOG_NONE, 0);
 2252+ SendDlgItemMessage(hWnd, IDC_FOGSTART, WM_SETTEXT, 0, (LPARAM)_T("0.0"));
 2253+ SendDlgItemMessage(hWnd, IDC_FOGEND, WM_SETTEXT, 0, (LPARAM)_T("1.0"));
 2254+ SendDlgItemMessage(hWnd, IDC_FOGDENSITY, WM_SETTEXT, 0, (LPARAM)_T("1.0"));
 2255+ SendDlgItemMessage(hWnd, IDC_SPINSTAGE, UDM_SETRANGE32, 0, 7);
 2256+ SendDlgItemMessage(hWnd, IDC_SPINALPHAREF, UDM_SETRANGE32, 0, 255);
 2257+ ::width = ddsd.dwWidth;
 2258+ ::height = ddsd.dwHeight;
 2259+ StartTimer(hWnd, WM_APP, 60);
 2260+ break;
 2261+ case WM_COMMAND:
 2262+ switch (LOWORD(wParam))
 2263+ {
 2264+ case IDC_TEXSTAGE:
 2265+ if (HIWORD(wParam) == EN_CHANGE)
 2266+ {
 2267+ SendDlgItemMessage(hWnd, IDC_TEXSTAGE, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2268+ number = _ttoi(tmpstring);
 2269+ if (number < 0) SendDlgItemMessage(hWnd, IDC_TEXSTAGE, WM_SETTEXT, 0, (LPARAM)_T("0"));
 2270+ if (number > 7) SendDlgItemMessage(hWnd, IDC_TEXSTAGE, WM_SETTEXT, 0, (LPARAM)_T("7"));
 2271+ if (number < 0) number = 0;
 2272+ if (number > 7) number = 7;
 2273+ texshaderstate.currentstage = number;
 2274+ _itot(texshaderstate.texstages[number].keycolor, tmpstring, 16);
 2275+ strupper(tmpstring);
 2276+ paddwordzeroes(tmpstring);
 2277+ if (texshaderstate.texstages[number].colorkey == FALSE) tmpstring[0] = 0;
 2278+ SendDlgItemMessage(hWnd, IDC_TEXCOLORKEY, WM_SETTEXT, 0, (LPARAM)tmpstring);
 2279+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_SETCURSEL, texshaderstate.texstages[number].texturetype, 0);
 2280+ SendDlgItemMessage(hWnd, IDC_TEXTUREFILE, WM_SETTEXT, 0, (LPARAM)texshaderstate.texstages[number].texturefile);
 2281+ SendDlgItemMessage(hWnd, IDC_CARG1, CB_SETCURSEL, texshaderstate.texstages[number].colorarg1 & D3DTA_SELECTMASK, 0);
 2282+ SendDlgItemMessage(hWnd, IDC_CARG2, CB_SETCURSEL, texshaderstate.texstages[number].colorarg2 & D3DTA_SELECTMASK, 0);
 2283+ SendDlgItemMessage(hWnd, IDC_AARG1, CB_SETCURSEL, texshaderstate.texstages[number].alphaarg1 & D3DTA_SELECTMASK, 0);
 2284+ SendDlgItemMessage(hWnd, IDC_AARG2, CB_SETCURSEL, texshaderstate.texstages[number].alphaarg2 & D3DTA_SELECTMASK, 0);
 2285+ if (texshaderstate.texstages[number].colorarg1 & D3DTA_ALPHAREPLICATE)
 2286+ SendDlgItemMessage(hWnd, IDC_CARG1A, BM_SETCHECK, BST_CHECKED, 0);
 2287+ else SendDlgItemMessage(hWnd, IDC_CARG1A, BM_SETCHECK, BST_UNCHECKED, 0);
 2288+ if (texshaderstate.texstages[number].colorarg2 & D3DTA_ALPHAREPLICATE)
 2289+ SendDlgItemMessage(hWnd, IDC_CARG2A, BM_SETCHECK, BST_CHECKED, 0);
 2290+ else SendDlgItemMessage(hWnd, IDC_CARG2A, BM_SETCHECK, BST_UNCHECKED, 0);
 2291+ if (texshaderstate.texstages[number].alphaarg1 & D3DTA_ALPHAREPLICATE)
 2292+ SendDlgItemMessage(hWnd, IDC_AARG1A, BM_SETCHECK, BST_CHECKED, 0);
 2293+ else SendDlgItemMessage(hWnd, IDC_AARG1A, BM_SETCHECK, BST_UNCHECKED, 0);
 2294+ if (texshaderstate.texstages[number].alphaarg2 & D3DTA_ALPHAREPLICATE)
 2295+ SendDlgItemMessage(hWnd, IDC_AARG2A, BM_SETCHECK, BST_CHECKED, 0);
 2296+ else SendDlgItemMessage(hWnd, IDC_AARG2A, BM_SETCHECK, BST_UNCHECKED, 0);
 2297+ if (texshaderstate.texstages[number].colorarg1 & D3DTA_COMPLEMENT)
 2298+ SendDlgItemMessage(hWnd, IDC_CARG1INV, BM_SETCHECK, BST_CHECKED, 0);
 2299+ else SendDlgItemMessage(hWnd, IDC_CARG1INV, BM_SETCHECK, BST_UNCHECKED, 0);
 2300+ if (texshaderstate.texstages[number].colorarg2 & D3DTA_COMPLEMENT)
 2301+ SendDlgItemMessage(hWnd, IDC_CARG2INV, BM_SETCHECK, BST_CHECKED, 0);
 2302+ else SendDlgItemMessage(hWnd, IDC_CARG2INV, BM_SETCHECK, BST_UNCHECKED, 0);
 2303+ if (texshaderstate.texstages[number].alphaarg1 & D3DTA_COMPLEMENT)
 2304+ SendDlgItemMessage(hWnd, IDC_AARG1INV, BM_SETCHECK, BST_CHECKED, 0);
 2305+ else SendDlgItemMessage(hWnd, IDC_AARG1INV, BM_SETCHECK, BST_UNCHECKED, 0);
 2306+ if (texshaderstate.texstages[number].alphaarg2 & D3DTA_COMPLEMENT)
 2307+ SendDlgItemMessage(hWnd, IDC_AARG2INV, BM_SETCHECK, BST_CHECKED, 0);
 2308+ else SendDlgItemMessage(hWnd, IDC_AARG2INV, BM_SETCHECK, BST_UNCHECKED, 0);
 2309+ SendDlgItemMessage(hWnd, IDC_COLOROP, CB_SETCURSEL, texshaderstate.texstages[number].colorop - 1, 0);
 2310+ SendDlgItemMessage(hWnd, IDC_ALPHAOP, CB_SETCURSEL, texshaderstate.texstages[number].alphaop - 1, 0);
 2311+ }
 2312+ break;
 2313+ case IDC_TEXTURE:
 2314+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2315+ {
 2316+ number = texshaderstate.currentstage;
 2317+ texshaderstate.texstages[number].texturetype =
 2318+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_GETCURSEL, 0, 0);
 2319+ SelectTexture(&texshaderstate.texstages[number].texture, texshaderstate.texstages[number].texturetype,
 2320+ texshaderstate.texstages[number].keycolor, texshaderstate.texstages[number].colorkey,
 2321+ texshaderstate.texstages[number].texturefile);
 2322+ }
 2323+ break;
 2324+ case IDC_TEXTUREFILE:
 2325+ if (HIWORD(wParam) == EN_KILLFOCUS)
 2326+ {
 2327+ number = texshaderstate.currentstage;
 2328+ SendDlgItemMessage(hWnd, IDC_TEXTUREFILE, WM_GETTEXT, MAX_PATH + 1,
 2329+ (LPARAM)texshaderstate.texstages[number].texturefile);
 2330+ SelectTexture(&texshaderstate.texstages[number].texture, texshaderstate.texstages[number].texturetype,
 2331+ texshaderstate.texstages[number].keycolor, texshaderstate.texstages[number].colorkey,
 2332+ texshaderstate.texstages[number].texturefile);
 2333+ }
 2334+ break;
 2335+ case IDC_CARG1:
 2336+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2337+ {
 2338+ number = texshaderstate.currentstage;
 2339+ SetShaderArg(hWnd, IDC_CARG1, IDC_CARG1A, IDC_CARG1INV, &texshaderstate.texstages[number].colorarg1);
 2340+ d3d7dev->SetTextureStageState(number, D3DTSS_COLORARG1, texshaderstate.texstages[number].colorarg1);
 2341+ }
 2342+ break;
 2343+ case IDC_CARG1A:
 2344+ case IDC_CARG1INV:
 2345+ if (HIWORD(wParam) == BN_CLICKED)
 2346+ {
 2347+ number = texshaderstate.currentstage;
 2348+ SetShaderArg(hWnd, IDC_CARG1, IDC_CARG1A, IDC_CARG1INV, &texshaderstate.texstages[number].colorarg2);
 2349+ d3d7dev->SetTextureStageState(number, D3DTSS_COLORARG1, texshaderstate.texstages[number].colorarg2);
 2350+ }
 2351+ break;
 2352+ case IDC_CARG2:
 2353+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2354+ {
 2355+ number = texshaderstate.currentstage;
 2356+ SetShaderArg(hWnd, IDC_CARG2, IDC_CARG2A, IDC_CARG2INV, &texshaderstate.texstages[number].colorarg2);
 2357+ d3d7dev->SetTextureStageState(number, D3DTSS_COLORARG2, texshaderstate.texstages[number].colorarg2);
 2358+ }
 2359+ break;
 2360+ case IDC_CARG2A:
 2361+ case IDC_CARG2INV:
 2362+ if (HIWORD(wParam) == BN_CLICKED)
 2363+ {
 2364+ number = texshaderstate.currentstage;
 2365+ SetShaderArg(hWnd, IDC_CARG2, IDC_CARG2A, IDC_CARG2INV, &texshaderstate.texstages[number].colorarg1);
 2366+ d3d7dev->SetTextureStageState(number, D3DTSS_COLORARG2, texshaderstate.texstages[number].colorarg1);
 2367+ }
 2368+ break;
 2369+ case IDC_AARG1:
 2370+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2371+ {
 2372+ number = texshaderstate.currentstage;
 2373+ SetShaderArg(hWnd, IDC_AARG1, IDC_AARG1A, IDC_AARG1INV, &texshaderstate.texstages[number].alphaarg1);
 2374+ d3d7dev->SetTextureStageState(number, D3DTSS_ALPHAARG1, texshaderstate.texstages[number].alphaarg1);
 2375+ }
 2376+ break;
 2377+ case IDC_AARG1A:
 2378+ case IDC_AARG1INV:
 2379+ if (HIWORD(wParam) == BN_CLICKED)
 2380+ {
 2381+ number = texshaderstate.currentstage;
 2382+ SetShaderArg(hWnd, IDC_AARG1, IDC_AARG1A, IDC_AARG1INV, &texshaderstate.texstages[number].alphaarg1);
 2383+ d3d7dev->SetTextureStageState(number, D3DTSS_ALPHAARG1, texshaderstate.texstages[number].alphaarg1);
 2384+ }
 2385+ break;
 2386+ case IDC_AARG2:
 2387+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2388+ {
 2389+ number = texshaderstate.currentstage;
 2390+ SetShaderArg(hWnd, IDC_AARG2, IDC_AARG2A, IDC_AARG2INV, &texshaderstate.texstages[number].alphaarg2);
 2391+ d3d7dev->SetTextureStageState(number, D3DTSS_ALPHAARG2, texshaderstate.texstages[number].alphaarg2);
 2392+ }
 2393+ break;
 2394+ case IDC_AARG2A:
 2395+ case IDC_AARG2INV:
 2396+ if (HIWORD(wParam) == BN_CLICKED)
 2397+ {
 2398+ number = texshaderstate.currentstage;
 2399+ SetShaderArg(hWnd, IDC_AARG2, IDC_AARG2A, IDC_AARG2INV, &texshaderstate.texstages[number].alphaarg2);
 2400+ d3d7dev->SetTextureStageState(number, D3DTSS_ALPHAARG2, texshaderstate.texstages[number].alphaarg2);
 2401+ }
 2402+ break;
 2403+ case IDC_COLOROP:
 2404+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2405+ {
 2406+ number = texshaderstate.currentstage;
 2407+ texshaderstate.texstages[number].colorop = (D3DTEXTUREOP)(SendDlgItemMessage(hWnd, IDC_COLOROP, CB_GETCURSEL, 0, 0) + 1);
 2408+ d3d7dev->SetTextureStageState(number, D3DTSS_COLOROP, texshaderstate.texstages[number].colorop);
 2409+ }
 2410+ break;
 2411+ case IDC_ALPHAOP:
 2412+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2413+ {
 2414+ number = texshaderstate.currentstage;
 2415+ texshaderstate.texstages[number].alphaop = (D3DTEXTUREOP)(SendDlgItemMessage(hWnd, IDC_ALPHAOP, CB_GETCURSEL, 0, 0) + 1);
 2416+ d3d7dev->SetTextureStageState(number, D3DTSS_ALPHAOP, texshaderstate.texstages[number].alphaop);
 2417+ }
 2418+ break;
 2419+ case IDC_BGCOLOR:
 2420+ if (HIWORD(wParam) == EN_CHANGE)
 2421+ {
 2422+ SendDlgItemMessage(hWnd, IDC_BGCOLOR, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2423+ if (!_stscanf(tmpstring, _T("%x"), &bgcolor)) bgcolor = 0;
 2424+ }
 2425+ break;
 2426+ case IDC_DIFFUSE:
 2427+ if (HIWORD(wParam) == EN_CHANGE)
 2428+ {
 2429+ SendDlgItemMessage(hWnd, IDC_DIFFUSE, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2430+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2431+ SetVertexColor(litvertices, colorvertices, numpoints, number);
 2432+ }
 2433+ break;
 2434+ case IDC_SPECULAR:
 2435+ if (HIWORD(wParam) == EN_CHANGE)
 2436+ {
 2437+ SendDlgItemMessage(hWnd, IDC_SPECULAR, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2438+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2439+ SetVertexSpecular(litvertices, colorvertices, numpoints, number);
 2440+ }
 2441+ break;
 2442+ case IDC_FACTOR:
 2443+ if (HIWORD(wParam) == EN_CHANGE)
 2444+ {
 2445+ SendDlgItemMessage(hWnd, IDC_FACTOR, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2446+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2447+ d3d7dev->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR, number);
 2448+ }
 2449+ break;
 2450+ case IDC_FOGCOLOR:
 2451+ if (HIWORD(wParam) == EN_CHANGE)
 2452+ {
 2453+ SendDlgItemMessage(hWnd, IDC_FOGCOLOR, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2454+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2455+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGCOLOR, number);
 2456+ }
 2457+ break;
 2458+ case IDC_TEXCOLORKEY:
 2459+ if (HIWORD(wParam) == EN_CHANGE)
 2460+ {
 2461+ SendDlgItemMessage(hWnd, IDC_TEXCOLORKEY, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2462+ number = texshaderstate.currentstage;
 2463+ if (tmpstring[0] == 0)
 2464+ {
 2465+ texshaderstate.texstages[number].colorkey = FALSE;
 2466+ texshaderstate.texstages[number].keycolor = 0;
 2467+ }
 2468+ else
 2469+ {
 2470+ texshaderstate.texstages[number].colorkey = TRUE;
 2471+ if (!_stscanf(tmpstring, _T("%x"), &texshaderstate.texstages[number].keycolor))
 2472+ texshaderstate.texstages[number].keycolor = 0;
 2473+ }
 2474+ SelectTexture(&texshaderstate.texstages[number].texture, texshaderstate.texstages[number].texturetype,
 2475+ texshaderstate.texstages[number].keycolor, texshaderstate.texstages[number].colorkey,
 2476+ texshaderstate.texstages[number].texturefile);
 2477+ }
 2478+ case IDC_ALPHABLEND:
 2479+ if (HIWORD(wParam) == BN_CLICKED)
 2480+ {
 2481+ if (SendDlgItemMessage(hWnd, IDC_ALPHABLEND, BM_GETCHECK, 0, 0) == BST_CHECKED)
 2482+ d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
 2483+ else d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
 2484+ }
 2485+ break;
 2486+ case IDC_SRCBLEND:
 2487+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2488+ {
 2489+ d3d7dev->SetRenderState(D3DRENDERSTATE_SRCBLEND, SendDlgItemMessage(hWnd,
 2490+ IDC_SRCBLEND, CB_GETCURSEL, 0, 0) + 1);
 2491+ }
 2492+ case IDC_DESTBLEND:
 2493+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2494+ {
 2495+ d3d7dev->SetRenderState(D3DRENDERSTATE_DESTBLEND, SendDlgItemMessage(hWnd,
 2496+ IDC_DESTBLEND, CB_GETCURSEL, 0, 0) + 1);
 2497+ }
 2498+ break;
 2499+ case IDC_ALPHATEST:
 2500+ if (HIWORD(wParam) == BN_CLICKED)
 2501+ {
 2502+ if (SendDlgItemMessage(hWnd, IDC_ALPHATEST, BM_GETCHECK, 0, 0) == BST_CHECKED)
 2503+ d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, TRUE);
 2504+ else d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, FALSE);
 2505+ }
 2506+ case IDC_ALPHAFUNC:
 2507+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2508+ {
 2509+ d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHAFUNC, SendDlgItemMessage(hWnd,
 2510+ IDC_ALPHAFUNC, CB_GETCURSEL, 0, 0) + 1);
 2511+ }
 2512+ break;
 2513+ case IDC_ALPHAREF:
 2514+ if (HIWORD(wParam) == EN_CHANGE)
 2515+ {
 2516+ SendDlgItemMessage(hWnd, IDC_ALPHAREF, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2517+ number = _ttoi(tmpstring);
 2518+ if (number < 0) SendDlgItemMessage(hWnd, IDC_ALPHAREF, WM_SETTEXT, 0, (LPARAM)_T("0"));
 2519+ if (number > 255) SendDlgItemMessage(hWnd, IDC_ALPHAREF, WM_SETTEXT, 0, (LPARAM)_T("255"));
 2520+ if (number < 0) number = 0;
 2521+ if (number > 255) number = 255;
 2522+ if (d3d7dev) d3d7dev->SetRenderState(D3DRENDERSTATE_ALPHAREF, number);
 2523+ }
 2524+ case IDC_COLORKEY:
 2525+ if (HIWORD(wParam) == BN_CLICKED)
 2526+ {
 2527+ if (SendDlgItemMessage(hWnd, IDC_COLORKEY, BM_GETCHECK, 0, 0) == BST_CHECKED)
 2528+ d3d7dev->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, TRUE);
 2529+ else d3d7dev->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, FALSE);
 2530+ }
 2531+ break;
 2532+ case IDC_FOGENABLE:
 2533+ if (HIWORD(wParam) == BN_CLICKED)
 2534+ {
 2535+ if (SendDlgItemMessage(hWnd, IDC_FOGENABLE, BM_GETCHECK, 0, 0) == BST_CHECKED)
 2536+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE);
 2537+ else d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE);
 2538+ }
 2539+ break;
 2540+ case IDC_VERTEXFOGMODE:
 2541+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2542+ {
 2543+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE, SendDlgItemMessage(hWnd,
 2544+ IDC_VERTEXFOGMODE, CB_GETCURSEL, 0, 0));
 2545+ }
 2546+ break;
 2547+ case IDC_PIXELFOGMODE:
 2548+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2549+ {
 2550+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, SendDlgItemMessage(hWnd,
 2551+ IDC_PIXELFOGMODE, CB_GETCURSEL, 0, 0));
 2552+ }
 2553+ break;
 2554+ case IDC_FOGSTART:
 2555+ if (HIWORD(wParam) == EN_CHANGE)
 2556+ {
 2557+ SendDlgItemMessage(hWnd, IDC_FOGSTART, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2558+ f = (float)_ttof(tmpstring);
 2559+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGSTART, *((LPDWORD)(&f)));
 2560+ }
 2561+ break;
 2562+ case IDC_FOGEND:
 2563+ if (HIWORD(wParam) == EN_CHANGE)
 2564+ {
 2565+ SendDlgItemMessage(hWnd, IDC_FOGEND, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2566+ f = (float)_ttof(tmpstring);
 2567+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGEND, *((LPDWORD)(&f)));
 2568+ }
 2569+ break;
 2570+ case IDC_FOGDENSITY:
 2571+ if (HIWORD(wParam) == EN_CHANGE)
 2572+ {
 2573+ SendDlgItemMessage(hWnd, IDC_FOGDENSITY, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2574+ f = (float)_ttof(tmpstring);
 2575+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGDENSITY, *((LPDWORD)(&f)));
 2576+ }
 2577+ break;
 2578+ default:
 2579+ return FALSE;
 2580+ }
 2581+ break;
 2582+ case WM_CLOSE:
 2583+ if (d3d7dev)
 2584+ {
 2585+ d3d7dev->Release();
 2586+ d3d7dev = NULL;
 2587+ }
 2588+ if (d3d7)
 2589+ {
 2590+ d3d7->Release();
 2591+ d3d7dev = NULL;
 2592+ }
 2593+ if (ddsrender)
 2594+ {
 2595+ ddsrender->Release();
 2596+ ddsrender = NULL;
 2597+ }
 2598+ if (ddsurface)
 2599+ {
 2600+ ddsurface->Release();
 2601+ ddsurface = NULL;
 2602+ }
 2603+ if (zbuffer)
 2604+ {
 2605+ zbuffer->Release();
 2606+ zbuffer = NULL;
 2607+ }
 2608+ if (ddclipper)
 2609+ {
 2610+ ddclipper->Release();
 2611+ ddclipper = NULL;
 2612+ }
 2613+ if (ddinterface)
 2614+ {
 2615+ ddinterface->Release();
 2616+ ddinterface = NULL;
 2617+ }
 2618+ if (mesh)
 2619+ {
 2620+ free(mesh);
 2621+ mesh = NULL;
 2622+ }
 2623+ if (vertices)
 2624+ {
 2625+ free(vertices);
 2626+ vertices = NULL;
 2627+ }
 2628+ if (litvertices)
 2629+ {
 2630+ free(litvertices);
 2631+ litvertices = NULL;
 2632+ }
 2633+ if (colorvertices)
 2634+ {
 2635+ free(colorvertices);
 2636+ colorvertices = NULL;
 2637+ }
 2638+ EndDialog(hWnd, IDCANCEL);
 2639+ break;
 2640+ case WM_APP:
 2641+ RunTestTimed(testnum);
 2642+ break;
 2643+ default:
 2644+ return FALSE;
 2645+ }
 2646+ return TRUE;
 2647+
 2648+
 2649+}
 2650+
 2651+INT_PTR CALLBACK VertexShader7Proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 2652+{
 2653+ HRESULT error;
 2654+ D3DVIEWPORT7 vp;
 2655+ HWND hDisplay;
 2656+ int number;
 2657+ float f;
 2658+ TCHAR tmpstring[MAX_PATH + 1];
 2659+ switch (Msg)
 2660+ {
 2661+ case WM_INITDIALOG:
 2662+ RECT r;
 2663+ DDSCAPS2 caps;
 2664+ DDSURFACEDESC2 ddsd;
 2665+ DDPIXELFORMAT ddpfz;
 2666+ testnum = 3;
 2667+ ddinterface = new MultiDirectDraw(7, &error, NULL);
 2668+ hDisplay = GetDlgItem(hWnd, IDC_DISPLAY);
 2669+ ::hWnd = hDisplay;
 2670+ error = ddinterface->SetCooperativeLevel(hDisplay, DDSCL_NORMAL);
 2671+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 2672+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 2673+ ddsd.dwFlags = DDSD_CAPS;
 2674+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
 2675+ error = ddinterface->CreateSurface(&ddsd, &ddsurface, NULL);
 2676+ error = ddinterface->CreateClipper(0, &ddclipper, NULL);
 2677+ error = ddclipper->SetHWnd(0, hDisplay);
 2678+ error = ddsurface->SetClipper(ddclipper);
 2679+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 2680+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 2681+ ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 2682+ ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
 2683+ GetClientRect(hDisplay, &r);
 2684+ ddsd.dwWidth = r.right;
 2685+ ddsd.dwHeight = r.bottom;
 2686+ error = ddinterface->CreateSurface(&ddsd, &ddsrender, NULL);
 2687+ error = ddinterface->QueryInterface(IID_IDirect3D7, (VOID**)&d3d7);
 2688+ error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice, zcallback, &ddpfz);
 2689+ error = ddsrender->GetSurfaceDesc(&ddsd);
 2690+ ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
 2691+ ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
 2692+ memcpy(&ddsd.ddpfPixelFormat, &ddpfz, sizeof(DDPIXELFORMAT));
 2693+ error = ddinterface->CreateSurface(&ddsd, &zbuffer, NULL);
 2694+ error = ddsrender->AddAttachedSurface(zbuffer);
 2695+ error = d3d7->CreateDevice(IID_IDirect3DHALDevice, (LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(), &d3d7dev);
 2696+ if (error != D3D_OK)
 2697+ error = d3d7->CreateDevice(IID_IDirect3DRGBDevice, (LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(), &d3d7dev);
 2698+ ddsrender->GetSurfaceDesc(&ddsd);
 2699+ vp.dvMaxZ = 1.0f;
 2700+ vp.dvMinZ = 0.0f;
 2701+ vp.dwX = vp.dwY = 0;
 2702+ vp.dwWidth = ddsd.dwWidth;
 2703+ vp.dwHeight = ddsd.dwHeight;
 2704+ error = d3d7dev->SetViewport(&vp);
 2705+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_ZENABLE, TRUE);
 2706+ InitTest(15);
 2707+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_ADDSTRING, 0, (LPARAM)_T("None"));
 2708+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_ADDSTRING, 0, (LPARAM)_T("Gradients"));
 2709+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_ADDSTRING, 0, (LPARAM)_T("DXGL logo (small)"));
 2710+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_ADDSTRING, 0, (LPARAM)_T("DXGL logo (large)"));
 2711+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_ADDSTRING, 0, (LPARAM)_T("Texture file"));
 2712+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_SETCURSEL, 0, 0);
 2713+ SendDlgItemMessage(hWnd, IDC_DIFFUSE, WM_SETTEXT, 0, (LPARAM)_T("FFFFFFFF"));
 2714+ SendDlgItemMessage(hWnd, IDC_SPECULAR, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2715+ SendDlgItemMessage(hWnd, IDC_FACTOR, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2716+ SendDlgItemMessage(hWnd, IDC_FOGCOLOR, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2717+ SendDlgItemMessage(hWnd, IDC_BGCOLOR, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2718+ SendDlgItemMessage(hWnd, IDC_AMBIENT, WM_SETTEXT, 0, (LPARAM)_T("FFFFFFFF"));
 2719+ SendDlgItemMessage(hWnd, IDC_EMISSIVE, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2720+ SendDlgItemMessage(hWnd, IDC_MATAMBIENT, WM_SETTEXT, 0, (LPARAM)_T("FFFFFFFF"));
 2721+ SendDlgItemMessage(hWnd, IDC_MATDIFFUSE, WM_SETTEXT, 0, (LPARAM)_T("FFFFFFFF"));
 2722+ SendDlgItemMessage(hWnd, IDC_MATSPECULAR, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2723+ PopulateFogCombo(GetDlgItem(hWnd, IDC_VERTEXFOGMODE));
 2724+ PopulateFogCombo(GetDlgItem(hWnd, IDC_PIXELFOGMODE));
 2725+ SendDlgItemMessage(hWnd, IDC_VERTEXFOGMODE, CB_SETCURSEL, D3DFOG_NONE, 0);
 2726+ SendDlgItemMessage(hWnd, IDC_PIXELFOGMODE, CB_SETCURSEL, D3DFOG_NONE, 0);
 2727+ SendDlgItemMessage(hWnd, IDC_FOGSTART, WM_SETTEXT, 0, (LPARAM)_T("0.0"));
 2728+ SendDlgItemMessage(hWnd, IDC_FOGEND, WM_SETTEXT, 0, (LPARAM)_T("1.0"));
 2729+ SendDlgItemMessage(hWnd, IDC_FOGDENSITY, WM_SETTEXT, 0, (LPARAM)_T("1.0"));
 2730+ SendDlgItemMessage(hWnd, IDC_FILLMODE, CB_ADDSTRING, 0, (LPARAM)_T("Points"));
 2731+ SendDlgItemMessage(hWnd, IDC_FILLMODE, CB_ADDSTRING, 0, (LPARAM)_T("Wireframe"));
 2732+ SendDlgItemMessage(hWnd, IDC_FILLMODE, CB_ADDSTRING, 0, (LPARAM)_T("Solid"));
 2733+ SendDlgItemMessage(hWnd, IDC_FILLMODE, CB_SETCURSEL, 2, 0);
 2734+ SendDlgItemMessage(hWnd, IDC_SHADEMODE, CB_ADDSTRING, 0, (LPARAM)_T("Flat"));
 2735+ SendDlgItemMessage(hWnd, IDC_SHADEMODE, CB_ADDSTRING, 0, (LPARAM)_T("Gouraud"));
 2736+ SendDlgItemMessage(hWnd, IDC_SHADEMODE, CB_ADDSTRING, 0, (LPARAM)_T("Phong"));
 2737+ SendDlgItemMessage(hWnd, IDC_SHADEMODE, CB_SETCURSEL, 1, 0);
 2738+ SendDlgItemMessage(hWnd, IDC_CULLMODE, CB_ADDSTRING, 0, (LPARAM)_T("None"));
 2739+ SendDlgItemMessage(hWnd, IDC_CULLMODE, CB_ADDSTRING, 0, (LPARAM)_T("CW"));
 2740+ SendDlgItemMessage(hWnd, IDC_CULLMODE, CB_ADDSTRING, 0, (LPARAM)_T("CCW"));
 2741+ SendDlgItemMessage(hWnd, IDC_CULLMODE, CB_SETCURSEL, 2, 0);
 2742+ SendDlgItemMessage(hWnd, IDC_VERTEXCOLOR, BM_SETCHECK, BST_CHECKED, 0);
 2743+ PopulateSourceCombo(GetDlgItem(hWnd, IDC_DIFFUSESOURCE));
 2744+ PopulateSourceCombo(GetDlgItem(hWnd, IDC_SPECULARSOURCE));
 2745+ PopulateSourceCombo(GetDlgItem(hWnd, IDC_AMBIENTSOURCE));
 2746+ PopulateSourceCombo(GetDlgItem(hWnd, IDC_EMISSIVESOURCE));
 2747+ SendDlgItemMessage(hWnd, IDC_DIFFUSESOURCE, CB_SETCURSEL, D3DMCS_COLOR1, 0);
 2748+ SendDlgItemMessage(hWnd, IDC_SPECULARSOURCE, CB_SETCURSEL, D3DMCS_COLOR2, 0);
 2749+ SendDlgItemMessage(hWnd, IDC_AMBIENTSOURCE, CB_SETCURSEL, D3DMCS_MATERIAL, 0);
 2750+ SendDlgItemMessage(hWnd, IDC_EMISSIVESOURCE, CB_SETCURSEL, D3DMCS_MATERIAL, 0);
 2751+ SendDlgItemMessage(hWnd, IDC_SPINDETAIL, UDM_SETRANGE32, 2, 64);
 2752+ SendDlgItemMessage(hWnd, IDC_SPINDETAIL, UDM_SETPOS32, 0, 8);
 2753+ SendDlgItemMessage(hWnd, IDC_SPINLIGHT, UDM_SETRANGE32, 0, 7);
 2754+ SendDlgItemMessage(hWnd, IDC_LIGHTDIFFUSE, WM_SETTEXT, 0, (LPARAM)_T("00FFFFFF"));
 2755+ SendDlgItemMessage(hWnd, IDC_LIGHTAMBIENT, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2756+ SendDlgItemMessage(hWnd, IDC_LIGHTSPECULAR, WM_SETTEXT, 0, (LPARAM)_T("00000000"));
 2757+ SendDlgItemMessage(hWnd, IDC_LIGHTRANGE, WM_SETTEXT, 0, (LPARAM)_T("0"));
 2758+ SendDlgItemMessage(hWnd, IDC_LIGHTFALLOFF, WM_SETTEXT, 0, (LPARAM)_T("0"));
 2759+ SendDlgItemMessage(hWnd, IDC_LIGHTTHETA, WM_SETTEXT, 0, (LPARAM)_T("0"));
 2760+ SendDlgItemMessage(hWnd, IDC_LIGHTPHI, WM_SETTEXT, 0, (LPARAM)_T("0"));
 2761+ SendDlgItemMessage(hWnd, IDC_LIGHTATTEN0, WM_SETTEXT, 0, (LPARAM)_T("0"));
 2762+ SendDlgItemMessage(hWnd, IDC_LIGHTATTEN1, WM_SETTEXT, 0, (LPARAM)_T("0"));
 2763+ SendDlgItemMessage(hWnd, IDC_LIGHTATTEN2, WM_SETTEXT, 0, (LPARAM)_T("0"));
 2764+ SendDlgItemMessage(hWnd, IDC_POWER, WM_SETTEXT, 0, (LPARAM)_T("0"));
 2765+ SendDlgItemMessage(hWnd, IDC_LIGHTTYPE, CB_ADDSTRING, 0, (LPARAM)_T("Point"));
 2766+ SendDlgItemMessage(hWnd, IDC_LIGHTTYPE, CB_ADDSTRING, 0, (LPARAM)_T("Spot"));
 2767+ SendDlgItemMessage(hWnd, IDC_LIGHTTYPE, CB_ADDSTRING, 0, (LPARAM)_T("Directional"));
 2768+ SendDlgItemMessage(hWnd, IDC_LIGHTTYPE, CB_ADDSTRING, 0, (LPARAM)_T("Parallel Point"));
 2769+ SendDlgItemMessage(hWnd, IDC_LIGHTTYPE, CB_ADDSTRING, 0, (LPARAM)_T("GL Spot"));
 2770+ SendDlgItemMessage(hWnd, IDC_LIGHTTYPE, CB_SETCURSEL, D3DLIGHT_DIRECTIONAL - 1, 0);
 2771+ SendDlgItemMessage(hWnd, IDC_LIGHTENABLED, BM_SETCHECK, BST_CHECKED, 0);
 2772+ ::width = ddsd.dwWidth;
 2773+ ::height = ddsd.dwHeight;
 2774+ vertexshaderstate.texture = NULL;
 2775+ vertexshaderstate.texturefile[0] = 0;
 2776+ vertexshaderstate.texturetype = 0;
 2777+ vertexshaderstate.currentlight = 0;
 2778+ StartTimer(hWnd, WM_APP, 60);
 2779+ break;
 2780+ case WM_COMMAND:
 2781+ switch (LOWORD(wParam))
 2782+ {
 2783+ case IDC_TEXTURE:
 2784+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2785+ {
 2786+ number = texshaderstate.currentstage;
 2787+ vertexshaderstate.texturetype =
 2788+ SendDlgItemMessage(hWnd, IDC_TEXTURE, CB_GETCURSEL, 0, 0);
 2789+ SelectTexture(&vertexshaderstate.texture, vertexshaderstate.texturetype,
 2790+ 0, FALSE, vertexshaderstate.texturefile);
 2791+ if ((vertexshaderstate.texturetype == 2) || (vertexshaderstate.texturetype == 3))
 2792+ d3d7dev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHAPM);
 2793+ else d3d7dev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
 2794+ }
 2795+ break;
 2796+ case IDC_TEXTUREFILE:
 2797+ if (HIWORD(wParam) == EN_KILLFOCUS)
 2798+ {
 2799+ number = texshaderstate.currentstage;
 2800+ SendDlgItemMessage(hWnd, IDC_TEXTUREFILE, WM_GETTEXT, MAX_PATH + 1,
 2801+ (LPARAM)vertexshaderstate.texturefile);
 2802+ SelectTexture(&vertexshaderstate.texture, vertexshaderstate.texturetype,
 2803+ 0, FALSE, vertexshaderstate.texturefile);
 2804+ }
 2805+ break;
 2806+ case IDC_FOGENABLE:
 2807+ if (HIWORD(wParam) == BN_CLICKED)
 2808+ {
 2809+ if (SendDlgItemMessage(hWnd, IDC_FOGENABLE, BM_GETCHECK, 0, 0) == BST_CHECKED)
 2810+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE);
 2811+ else d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE);
 2812+ }
 2813+ break;
 2814+ case IDC_VERTEXFOGMODE:
 2815+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2816+ {
 2817+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE, SendDlgItemMessage(hWnd,
 2818+ IDC_VERTEXFOGMODE, CB_GETCURSEL, 0, 0));
 2819+ }
 2820+ break;
 2821+ case IDC_PIXELFOGMODE:
 2822+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2823+ {
 2824+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, SendDlgItemMessage(hWnd,
 2825+ IDC_PIXELFOGMODE, CB_GETCURSEL, 0, 0));
 2826+ }
 2827+ break;
 2828+ case IDC_FOGSTART:
 2829+ if (HIWORD(wParam) == EN_CHANGE)
 2830+ {
 2831+ SendDlgItemMessage(hWnd, IDC_FOGSTART, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2832+ f = (float)_ttof(tmpstring);
 2833+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGSTART, *((LPDWORD)(&f)));
 2834+ }
 2835+ break;
 2836+ case IDC_FOGEND:
 2837+ if (HIWORD(wParam) == EN_CHANGE)
 2838+ {
 2839+ SendDlgItemMessage(hWnd, IDC_FOGEND, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2840+ f = (float)_ttof(tmpstring);
 2841+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGEND, *((LPDWORD)(&f)));
 2842+ }
 2843+ break;
 2844+ case IDC_FOGDENSITY:
 2845+ if (HIWORD(wParam) == EN_CHANGE)
 2846+ {
 2847+ SendDlgItemMessage(hWnd, IDC_FOGDENSITY, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2848+ f = (float)_ttof(tmpstring);
 2849+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGDENSITY, *((LPDWORD)(&f)));
 2850+ }
 2851+ break;
 2852+ case IDC_RANGEBASEDFOG:
 2853+ if (HIWORD(wParam) == BN_CLICKED)
 2854+ {
 2855+ if (SendDlgItemMessage(hWnd, IDC_RANGEBASEDFOG, BM_GETCHECK, 0, 0) == BST_CHECKED)
 2856+ d3d7dev->SetRenderState(D3DRENDERSTATE_RANGEFOGENABLE, TRUE);
 2857+ else d3d7dev->SetRenderState(D3DRENDERSTATE_RANGEFOGENABLE, FALSE);
 2858+ }
 2859+ break;
 2860+ case IDC_FILLMODE:
 2861+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2862+ {
 2863+ d3d7dev->SetRenderState(D3DRENDERSTATE_FILLMODE, SendDlgItemMessage(hWnd,
 2864+ IDC_FILLMODE, CB_GETCURSEL, 0, 0) + 1);
 2865+ }
 2866+ break;
 2867+ case IDC_SHADEMODE:
 2868+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2869+ {
 2870+ d3d7dev->SetRenderState(D3DRENDERSTATE_SHADEMODE, SendDlgItemMessage(hWnd,
 2871+ IDC_SHADEMODE, CB_GETCURSEL, 0, 0) + 1);
 2872+ }
 2873+ break;
 2874+ case IDC_CULLMODE:
 2875+ if (HIWORD(wParam) == CBN_SELCHANGE)
 2876+ {
 2877+ d3d7dev->SetRenderState(D3DRENDERSTATE_CULLMODE, SendDlgItemMessage(hWnd,
 2878+ IDC_CULLMODE, CB_GETCURSEL, 0, 0) + 1);
 2879+ }
 2880+ break;
 2881+ case IDC_DIFFUSE:
 2882+ if (HIWORD(wParam) == EN_CHANGE)
 2883+ {
 2884+ SendDlgItemMessage(hWnd, IDC_DIFFUSE, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2885+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2886+ SetVertexColor(litvertices, colorvertices, numpoints, number);
 2887+ }
 2888+ break;
 2889+ case IDC_SPECULAR:
 2890+ if (HIWORD(wParam) == EN_CHANGE)
 2891+ {
 2892+ SendDlgItemMessage(hWnd, IDC_SPECULAR, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2893+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2894+ SetVertexSpecular(litvertices, colorvertices, numpoints, number);
 2895+ }
 2896+ break;
 2897+ case IDC_FACTOR:
 2898+ if (HIWORD(wParam) == EN_CHANGE)
 2899+ {
 2900+ SendDlgItemMessage(hWnd, IDC_FACTOR, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2901+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2902+ d3d7dev->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR, number);
 2903+ }
 2904+ break;
 2905+ case IDC_FOGCOLOR:
 2906+ if (HIWORD(wParam) == EN_CHANGE)
 2907+ {
 2908+ SendDlgItemMessage(hWnd, IDC_FOGCOLOR, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2909+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2910+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGCOLOR, number);
 2911+ }
 2912+ break;
 2913+ case IDC_BGCOLOR:
 2914+ if (HIWORD(wParam) == EN_CHANGE)
 2915+ {
 2916+ SendDlgItemMessage(hWnd, IDC_BGCOLOR, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2917+ if (!_stscanf(tmpstring, _T("%x"), &bgcolor)) bgcolor = 0;
 2918+ }
 2919+ break;
 2920+ case IDC_AMBIENT:
 2921+ {
 2922+ SendDlgItemMessage(hWnd, IDC_AMBIENT, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2923+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2924+ d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, number);
 2925+ }
 2926+ break;
 2927+ case IDC_EMISSIVE:
 2928+ if (HIWORD(wParam) == EN_CHANGE)
 2929+ {
 2930+ SendDlgItemMessage(hWnd, IDC_EMISSIVE, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2931+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2932+ material.emissive.b = (float)(number & 255) / 255.0;
 2933+ material.emissive.g = (float)((number >> 8) & 255) / 255.0;
 2934+ material.emissive.r = (float)((number >> 16) & 255) / 255.0;
 2935+ material.emissive.a = (float)((number >> 24) & 255) / 255.0;
 2936+ d3d7dev->SetMaterial(&material);
 2937+ }
 2938+ break;
 2939+ case IDC_MATAMBIENT:
 2940+ if (HIWORD(wParam) == EN_CHANGE)
 2941+ {
 2942+ SendDlgItemMessage(hWnd, IDC_MATAMBIENT, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2943+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2944+ material.ambient.b = (float)(number & 255) / 255.0;
 2945+ material.ambient.g = (float)((number >> 8) & 255) / 255.0;
 2946+ material.ambient.r = (float)((number >> 16) & 255) / 255.0;
 2947+ material.ambient.a = (float)((number >> 24) & 255) / 255.0;
 2948+ d3d7dev->SetMaterial(&material);
 2949+ }
 2950+ break;
 2951+ case IDC_MATDIFFUSE:
 2952+ if (HIWORD(wParam) == EN_CHANGE)
 2953+ {
 2954+ SendDlgItemMessage(hWnd, IDC_MATDIFFUSE, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2955+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2956+ material.diffuse.b = (float)(number & 255) / 255.0;
 2957+ material.diffuse.g = (float)((number >> 8) & 255) / 255.0;
 2958+ material.diffuse.r = (float)((number >> 16) & 255) / 255.0;
 2959+ material.diffuse.a = (float)((number >> 24) & 255) / 255.0;
 2960+ d3d7dev->SetMaterial(&material);
 2961+ }
 2962+ break;
 2963+ case IDC_MATSPECULAR:
 2964+ if (HIWORD(wParam) == EN_CHANGE)
 2965+ {
 2966+ SendDlgItemMessage(hWnd, IDC_MATSPECULAR, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2967+ if (!_stscanf(tmpstring, _T("%x"), &number)) number = 0;
 2968+ material.specular.b = (float)(number & 255) / 255.0;
 2969+ material.specular.g = (float)((number >> 8) & 255) / 255.0;
 2970+ material.specular.r = (float)((number >> 16) & 255) / 255.0;
 2971+ material.specular.a = (float)((number >> 24) & 255) / 255.0;
 2972+ d3d7dev->SetMaterial(&material);
 2973+ }
 2974+ break;
 2975+ case IDC_POWER:
 2976+ if (HIWORD(wParam) == EN_CHANGE)
 2977+ {
 2978+ SendDlgItemMessage(hWnd, IDC_POWER, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 2979+ material.power = (float)_ttof(tmpstring);
 2980+ d3d7dev->SetMaterial(&material);
 2981+ }
 2982+ break;
 2983+ case IDC_ENABLELIGHT:
 2984+ if (HIWORD(wParam) == BN_CLICKED)
 2985+ {
 2986+ if (SendDlgItemMessage(hWnd, IDC_ENABLELIGHT, BM_GETCHECK, 0, 0) == BST_CHECKED)
 2987+ {
 2988+ d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);
 2989+ for (int i = 0; i < 8; i++)
 2990+ {
 2991+ d3d7dev->SetLight(i, &lights[i]);
 2992+ d3d7dev->LightEnable(i, lightenable[i]);
 2993+ }
 2994+ }
 2995+ else d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
 2996+ }
 2997+ break;
 2998+ case IDC_VERTEXCOLOR:
 2999+ if (HIWORD(wParam) == BN_CLICKED)
 3000+ {
 3001+ if (SendDlgItemMessage(hWnd, IDC_VERTEXCOLOR, BM_GETCHECK, 0, 0) == BST_CHECKED)
 3002+ d3d7dev->SetRenderState(D3DRENDERSTATE_COLORVERTEX, TRUE);
 3003+ else d3d7dev->SetRenderState(D3DRENDERSTATE_COLORVERTEX, FALSE);
 3004+ }
 3005+ break;
 3006+ case IDC_DETAIL:
 3007+ if (HIWORD(wParam) == EN_CHANGE)
 3008+ {
 3009+ SendDlgItemMessage(hWnd, IDC_DETAIL, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 3010+ number = _ttoi(tmpstring);
 3011+ if (number < 2) SendDlgItemMessage(hWnd, IDC_DETAIL, WM_SETTEXT, 0, (LPARAM)_T("2"));
 3012+ if (number > 64) SendDlgItemMessage(hWnd, IDC_DETAIL, WM_SETTEXT, 0, (LPARAM)_T("64"));
 3013+ MakeCube3D(5, number);
 3014+ }
 3015+ break;
 3016+ case IDC_DIFFUSESOURCE:
 3017+ if (HIWORD(wParam) == CBN_SELCHANGE)
 3018+ {
 3019+ d3d7dev->SetRenderState(D3DRENDERSTATE_DIFFUSEMATERIALSOURCE, SendDlgItemMessage(hWnd,
 3020+ IDC_DIFFUSESOURCE, CB_GETCURSEL, 0, 0));
 3021+ }
 3022+ break;
 3023+ case IDC_SPECULARSOURCE:
 3024+ if (HIWORD(wParam) == CBN_SELCHANGE)
 3025+ {
 3026+ d3d7dev->SetRenderState(D3DRENDERSTATE_SPECULARMATERIALSOURCE, SendDlgItemMessage(hWnd,
 3027+ IDC_SPECULARSOURCE, CB_GETCURSEL, 0, 0));
 3028+ }
 3029+ break;
 3030+ case IDC_AMBIENTSOURCE:
 3031+ if (HIWORD(wParam) == CBN_SELCHANGE)
 3032+ {
 3033+ d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE, SendDlgItemMessage(hWnd,
 3034+ IDC_AMBIENTSOURCE, CB_GETCURSEL, 0, 0));
 3035+ }
 3036+ break;
 3037+ case IDC_EMISSIVESOURCE:
 3038+ if (HIWORD(wParam) == CBN_SELCHANGE)
 3039+ {
 3040+ d3d7dev->SetRenderState(D3DRENDERSTATE_EMISSIVEMATERIALSOURCE, SendDlgItemMessage(hWnd,
 3041+ IDC_EMISSIVESOURCE, CB_GETCURSEL, 0, 0));
 3042+ }
 3043+ break;
 3044+ case IDC_LIGHTNUMBER:
 3045+ if (HIWORD(wParam) == EN_CHANGE)
 3046+ {
 3047+ SendDlgItemMessage(hWnd, IDC_LIGHTNUMBER, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 3048+ number = _ttoi(tmpstring);
 3049+ if (number < 0) SendDlgItemMessage(hWnd, IDC_LIGHTNUMBER, WM_SETTEXT, 0, (LPARAM)_T("0"));
 3050+ if (number > 7) SendDlgItemMessage(hWnd, IDC_LIGHTNUMBER, WM_SETTEXT, 0, (LPARAM)_T("7"));
 3051+ vertexshaderstate.currentlight = number;
 3052+ _itot(hexlightcolor[vertexshaderstate.currentlight].ambient, tmpstring, 16);
 3053+ strupper(tmpstring); paddwordzeroes(tmpstring);
 3054+ SendDlgItemMessage(hWnd, IDC_LIGHTAMBIENT, WM_SETTEXT, 0, (LPARAM)tmpstring);
 3055+ _itot(hexlightcolor[vertexshaderstate.currentlight].diffuse, tmpstring, 16);
 3056+ strupper(tmpstring); paddwordzeroes(tmpstring);
 3057+ SendDlgItemMessage(hWnd, IDC_LIGHTDIFFUSE, WM_SETTEXT, 0, (LPARAM)tmpstring);
 3058+ _itot(hexlightcolor[vertexshaderstate.currentlight].specular, tmpstring, 16);
 3059+ strupper(tmpstring); paddwordzeroes(tmpstring);
 3060+ SendDlgItemMessage(hWnd, IDC_LIGHTSPECULAR, WM_SETTEXT, 0, (LPARAM)tmpstring);
 3061+ SendDlgItemMessage(hWnd, IDC_LIGHTTYPE, CB_SETCURSEL, lights[vertexshaderstate.currentlight].dltType - 1, 0);
 3062+ if (lightenable[vertexshaderstate.currentlight])
 3063+ SendDlgItemMessage(hWnd, IDC_LIGHTENABLED, BM_SETCHECK, BST_CHECKED, 0);
 3064+ else SendDlgItemMessage(hWnd, IDC_LIGHTENABLED, BM_SETCHECK, BST_UNCHECKED, 0);
 3065+ }
 3066+ break;
 3067+ case IDC_LIGHTENABLED:
 3068+ if (HIWORD(wParam) == BN_CLICKED)
 3069+ {
 3070+ if (SendDlgItemMessage(hWnd, IDC_LIGHTENABLED, BM_GETCHECK, 0, 0) == BST_CHECKED)
 3071+ {
 3072+ lightenable[vertexshaderstate.currentlight] = TRUE;
 3073+ d3d7dev->LightEnable(vertexshaderstate.currentlight, TRUE);
 3074+ }
 3075+ else
 3076+ {
 3077+ lightenable[vertexshaderstate.currentlight] = FALSE;
 3078+ d3d7dev->LightEnable(vertexshaderstate.currentlight, FALSE);
 3079+ }
 3080+ }
 3081+ break;
 3082+ case IDC_LIGHTTYPE:
 3083+ if (HIWORD(wParam) == CBN_SELCHANGE)
 3084+ {
 3085+ lights[vertexshaderstate.currentlight].dltType = (D3DLIGHTTYPE)
 3086+ (SendDlgItemMessage(hWnd, IDC_LIGHTTYPE, CB_GETCURSEL, 0, 0) + 1);
 3087+ d3d7dev->SetLight(vertexshaderstate.currentlight, &lights[vertexshaderstate.currentlight]);
 3088+ }
 3089+ break;
 3090+ case IDC_LIGHTRANGE:
 3091+ if (HIWORD(wParam) == EN_CHANGE)
 3092+ {
 3093+ SendDlgItemMessage(hWnd, IDC_LIGHTRANGE, WM_GETTEXT, MAX_PATH, (LPARAM)tmpstring);
 3094+ lights[vertexshaderstate.currentlight].dvRange = (float)_ttof(tmpstring);
 3095+ d3d7dev->SetLight(vertexshaderstate.currentlight, &lights[vertexshaderstate.currentlight]);
 3096+ }
 3097+ break;
 3098+ default:
 3099+ return FALSE;
 3100+ }
 3101+ break;
 3102+ case WM_CLOSE:
 3103+ if (d3d7dev)
 3104+ {
 3105+ d3d7dev->Release();
 3106+ d3d7dev = NULL;
 3107+ }
 3108+ if (d3d7)
 3109+ {
 3110+ d3d7->Release();
 3111+ d3d7dev = NULL;
 3112+ }
 3113+ if (ddsrender)
 3114+ {
 3115+ ddsrender->Release();
 3116+ ddsrender = NULL;
 3117+ }
 3118+ if (ddsurface)
 3119+ {
 3120+ ddsurface->Release();
 3121+ ddsurface = NULL;
 3122+ }
 3123+ if (zbuffer)
 3124+ {
 3125+ zbuffer->Release();
 3126+ zbuffer = NULL;
 3127+ }
 3128+ if (ddclipper)
 3129+ {
 3130+ ddclipper->Release();
 3131+ ddclipper = NULL;
 3132+ }
 3133+ if (ddinterface)
 3134+ {
 3135+ ddinterface->Release();
 3136+ ddinterface = NULL;
 3137+ }
 3138+ if (mesh)
 3139+ {
 3140+ free(mesh);
 3141+ mesh = NULL;
 3142+ }
 3143+ if (vertices)
 3144+ {
 3145+ free(vertices);
 3146+ vertices = NULL;
 3147+ }
 3148+ if (litvertices)
 3149+ {
 3150+ free(litvertices);
 3151+ litvertices = NULL;
 3152+ }
 3153+ if (colorvertices)
 3154+ {
 3155+ free(colorvertices);
 3156+ colorvertices = NULL;
 3157+ }
 3158+ EndDialog(hWnd, IDCANCEL);
 3159+ break;
 3160+ case WM_APP:
 3161+ RunTestTimed(testnum);
 3162+ break;
 3163+ default:
 3164+ return FALSE;
 3165+ }
 3166+ return TRUE;
 3167+}
 3168+
 3169+/*
 3170+void DDFlipTestWindow::OnQueryNewPalette(wxQueryNewPaletteEvent& event)
 3171+{
 3172+ //if(bpp == 8) ddsurface->SetPalette
 3173+}
 3174+*/
\ No newline at end of file
Index: dxgltest/tests.h
——@@ -33,10 +33,7 @@
3434 RECT rect;
3535 } DDSPRITE;
3636
37 -void RunTest2D(int testnum, int width, int height, int bpp, int refresh, int backbuffers, int apiver,
38 - double fps, bool fullscreen, bool resizable);
 37+void RunDXGLTest(int testnum, int width, int height, int bpp, int refresh, int backbuffers, int apiver,
 38+ int filter, int msaa, double fps, bool fullscreen, bool resizable, BOOL is3d);
3939
40 -void RunTest3D(int testnum, int width, int height, int bpp, int refresh, int backbuffers, int apiver,
41 - int filter, int msaa, double fps, bool fullscreen, bool resizable);
42 -
4340 #endif //_TESTS_H