DXGL r57 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r56‎ | r57 | r58 >
Date:16:03, 30 December 2011
Author:admin
Status:new
Tags:
Comment:
Complete D3D test 1
Modified paths:
  • /dxgltest/Tests3D.cpp (modified) (history)
  • /dxgltest/dxgltest.cpp (modified) (history)

Diff [purge]

Index: dxgltest/Tests3D.cpp
@@ -51,6 +51,7 @@
5252 static WORD mesh[256];
5353 static WORD cube_mesh[] = {0,1,2, 2,1,3, 4,5,6, 6,5,7, 8,9,10, 10,9,11, 12,13,14, 14,13,15, 16,17,18,
5454 18,17,19, 20,21,22, 22,21,23 };
 55+static D3DLIGHT7 lights[8];
5556
5657 LRESULT CALLBACK D3DWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
5758 {
@@ -86,6 +87,11 @@
8788 ddsurface->Release();
8889 ddsurface = NULL;
8990 }
 91+ if(zbuffer)
 92+ {
 93+ zbuffer->Release();
 94+ zbuffer = NULL;
 95+ }
9096 if(ddclipper)
9197 {
9298 ddclipper->Release();
@@ -283,6 +289,7 @@
284290 }
285291 error = ddinterface->QueryInterface(IID_IDirect3D7,(VOID**)&d3d7);
286292 error = d3d7->EnumZBufferFormats(IID_IDirect3DHALDevice,zcallback,&ddpfz);
 293+ error = ddsrender->GetSurfaceDesc(&ddsd);
287294 ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
288295 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER|DDSCAPS_VIDEOMEMORY;
289296 memcpy(&ddsd.ddpfPixelFormat,&ddpfz,sizeof(DDPIXELFORMAT));
@@ -340,14 +347,14 @@
341348
342349 void MakeCube3D(D3DVECTOR *points, D3DVECTOR *normals, D3DVERTEX *vertices)
343350 {
344 - points[0] = D3DVECTOR(0.0f,0.0f,0.0f);
345 - points[1] = D3DVECTOR(0.0f,3.0f,0.0f);
346 - points[2] = D3DVECTOR(3.0f,0.0f,0.0f);
347 - points[3] = D3DVECTOR(3.0f,3.0f,0.0f);
348 - points[4] = D3DVECTOR(3.0f,0.0f,3.0f);
349 - points[5] = D3DVECTOR(3.0f,3.0f,3.0f);
350 - points[6] = D3DVECTOR(0.0f,0.0f,3.0f);
351 - points[7] = D3DVECTOR(0.0f,3.0f,3.0f);
 351+ points[0] = D3DVECTOR(-2.5f,-2.5f,-2.5f);
 352+ points[1] = D3DVECTOR(-2.5f,2.5f,-2.5f);
 353+ points[2] = D3DVECTOR(2.5f,-2.5f,-2.5f);
 354+ points[3] = D3DVECTOR(2.5f,2.5f,-2.5f);
 355+ points[4] = D3DVECTOR(2.5f,-2.5f,2.5f);
 356+ points[5] = D3DVECTOR(2.5f,2.5f,2.5f);
 357+ points[6] = D3DVECTOR(-2.5f,-2.5f,2.5f);
 358+ points[7] = D3DVECTOR(-2.5f,2.5f,2.5f);
352359 normals[0] = D3DVECTOR(0.0f,0.0f,-1.0f);
353360 normals[1] = D3DVECTOR(1.0f,0.0f,0.0f);
354361 normals[2] = D3DVECTOR(0.0f,0.0f,1.0f);
@@ -393,11 +400,16 @@
394401 MakeCube3D(points,normals,vertices);
395402 D3DMATERIAL7 material;
396403 ZeroMemory(&material,sizeof(D3DMATERIAL7));
397 - material.ambient.r = 1.0f;
398 - material.ambient.g = 1.0f;
 404+ material.ambient.r = 0.5f;
 405+ material.ambient.g = 0.5f;
399406 material.ambient.b = 0.0f;
 407+ material.diffuse.r = 1.0f;
 408+ material.diffuse.g = 1.0f;
 409+ material.diffuse.b = 1.0f;
400410 error = d3d7dev->SetMaterial(&material);
401 - error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT,0xffffffff);
 411+ error = d3d7dev->LightEnable(0,TRUE);
 412+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);
 413+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0x7f7f7f7f);
402414 mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
403415 mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
404416 mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
@@ -414,7 +426,15 @@
415427 matProj._43 = -1.0f;
416428 matProj._44 = 0.0f;
417429 error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION,&matProj);
418 -
 430+ ZeroMemory(&lights[0],sizeof(D3DLIGHT7));
 431+ lights[0].dltType = D3DLIGHT_DIRECTIONAL;
 432+ lights[0].dcvDiffuse.r = 1;
 433+ lights[0].dcvDiffuse.g = 0;
 434+ lights[0].dcvDiffuse.b = 1;
 435+ lights[0].dvDirection = D3DVECTOR(5,5,5);
 436+ lights[0].dvRange = D3DLIGHT_RANGE_MAX;
 437+ lights[0].dvAttenuation1 = 0.4f;
 438+ error = d3d7dev->SetLight(0,&lights[0]);
419439 break;
420440 default:
421441 break;
@@ -447,11 +467,15 @@
448468 error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
449469 error = d3d7dev->BeginScene();
450470 error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,24,cube_mesh,36,0);
 471+ error = d3d7dev->EndScene();
451472 break;
452473 default:
453474 break;
454475 }
455 - if(fullscreen) ddsurface->Flip(NULL,DDFLIP_WAIT);
 476+ if(fullscreen)
 477+ {
 478+ if(backbuffers) ddsurface->Flip(NULL,DDFLIP_WAIT);
 479+ }
456480 else
457481 {
458482 p.x = 0;
Index: dxgltest/dxgltest.cpp
@@ -251,7 +251,7 @@
252252 const int START_3D = __LINE__;
253253 const TEST_ITEM Tests3D[] =
254254 { // minver maxver buffermin max usesfps defaultfps usestexture usesfsaa name
255 - {7, 7, 0, 2, true, 60.0, false, true, _T("Basic polygons (DX7)")}
 255+ {7, 7, 0, 2, true, 60.0, false, true, _T("DrawIndexedPrimitives cube with one light (DX7)")}
256256 };
257257 const int END_3D = __LINE__ - 4;
258258 const int numtests3d = END_3D - START_3D;