DXGL r265 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r264‎ | r265 | r266 >
Date:19:03, 29 September 2012
Author:admin
Status:new
Tags:
Comment:
Add fog to Texture Shader demo
Add texture and fog to Vertex Shader demo
Modified paths:
  • /dxgltest/Tests3D.cpp (modified) (history)

Diff [purge]

Index: dxgltest/Tests3D.cpp
@@ -134,6 +134,15 @@
135135 {0,0}
136136 };
137137
 138+typedef struct
 139+{
 140+ DWORD texturetype;
 141+ TCHAR texturefile[MAX_PATH+1];
 142+ MultiDirectDrawSurface* texture;
 143+} VERTEXSHADERSTATE;
 144+static VERTEXSHADERSTATE vertexshaderstate;
 145+
 146+
138147 LRESULT CALLBACK D3DWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
139148 {
140149 bool paintwnd = true;
@@ -285,7 +294,7 @@
286295 }
287296 if(testnum == 3)
288297 {
289 - DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_TEXSHADER),NULL,VertexShader7Proc);
 298+ DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_VERTEXSHADER),NULL,VertexShader7Proc);
290299 return;
291300 }
292301 DDSCAPS2 caps;
@@ -762,6 +771,7 @@
763772 error = d3d7dev->EndScene();
764773 break;
765774 case 2:
 775+ case 3:
766776 mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
767777 mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
768778 mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
@@ -1024,6 +1034,7 @@
10251035 D3DVIEWPORT7 vp;
10261036 HWND hDisplay;
10271037 int number;
 1038+ float f;
10281039 TCHAR tmpstring[MAX_PATH+1];
10291040 switch(Msg)
10301041 {
@@ -1349,6 +1360,52 @@
13501361 d3d7dev->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE,TRUE);
13511362 else d3d7dev->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE,FALSE);
13521363 }
 1364+ break;
 1365+ case IDC_FOGENABLE:
 1366+ if(HIWORD(wParam) == BN_CLICKED)
 1367+ {
 1368+ if(SendDlgItemMessage(hWnd,IDC_FOGENABLE,BM_GETCHECK,0,0) == BST_CHECKED)
 1369+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE,TRUE);
 1370+ else d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE,FALSE);
 1371+ }
 1372+ break;
 1373+ case IDC_VERTEXFOGMODE:
 1374+ if(HIWORD(wParam) == CBN_SELCHANGE)
 1375+ {
 1376+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE,SendDlgItemMessage(hWnd,
 1377+ IDC_VERTEXFOGMODE,CB_GETCURSEL,0,0));
 1378+ }
 1379+ break;
 1380+ case IDC_PIXELFOGMODE:
 1381+ if(HIWORD(wParam) == CBN_SELCHANGE)
 1382+ {
 1383+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE,SendDlgItemMessage(hWnd,
 1384+ IDC_PIXELFOGMODE,CB_GETCURSEL,0,0));
 1385+ }
 1386+ break;
 1387+ case IDC_FOGSTART:
 1388+ if(HIWORD(wParam) == EN_CHANGE)
 1389+ {
 1390+ SendDlgItemMessage(hWnd,IDC_FOGSTART,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1391+ f = (float)_ttof(tmpstring);
 1392+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGSTART, *((LPDWORD)(&f)));
 1393+ }
 1394+ case IDC_FOGEND:
 1395+ if(HIWORD(wParam) == EN_CHANGE)
 1396+ {
 1397+ SendDlgItemMessage(hWnd,IDC_FOGEND,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1398+ f = (float)_ttof(tmpstring);
 1399+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGEND, *((LPDWORD)(&f)));
 1400+ }
 1401+ case IDC_FOGDENSITY:
 1402+ if(HIWORD(wParam) == EN_CHANGE)
 1403+ {
 1404+ SendDlgItemMessage(hWnd,IDC_FOGDENSITY,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1405+ f = (float)_ttof(tmpstring);
 1406+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGDENSITY, *((LPDWORD)(&f)));
 1407+ }
 1408+ default:
 1409+ return FALSE;
13531410 }
13541411 break;
13551412 case WM_CLOSE:
@@ -1372,6 +1429,7 @@
13731430 D3DVIEWPORT7 vp;
13741431 HWND hDisplay;
13751432 int number;
 1433+ float f;
13761434 TCHAR tmpstring[MAX_PATH+1];
13771435 switch(Msg)
13781436 {
@@ -1435,10 +1493,91 @@
14361494 SendDlgItemMessage(hWnd,IDC_AMBIENT,WM_SETTEXT,0,(LPARAM)_T("FFFFFFFF"));
14371495 SendDlgItemMessage(hWnd,IDC_EMISSIVE,WM_SETTEXT,0,(LPARAM)_T("00000000"));
14381496 SendDlgItemMessage(hWnd,IDC_MATAMBIENT,WM_SETTEXT,0,(LPARAM)_T("FFFFFFFF"));
 1497+ PopulateFogCombo(GetDlgItem(hWnd,IDC_VERTEXFOGMODE));
 1498+ PopulateFogCombo(GetDlgItem(hWnd,IDC_PIXELFOGMODE));
 1499+ SendDlgItemMessage(hWnd,IDC_FOGSTART,WM_SETTEXT,0,(LPARAM)_T("0.0"));
 1500+ SendDlgItemMessage(hWnd,IDC_FOGEND,WM_SETTEXT,0,(LPARAM)_T("1.0"));
 1501+ SendDlgItemMessage(hWnd,IDC_FOGDENSITY,WM_SETTEXT,0,(LPARAM)_T("1.0"));
14391502 ::width = ddsd.dwWidth;
14401503 ::height = ddsd.dwHeight;
 1504+ vertexshaderstate.texture = NULL;
 1505+ vertexshaderstate.texturefile[0] = 0;
 1506+ vertexshaderstate.texturetype = 0;
14411507 StartTimer(hWnd,WM_APP,60);
14421508 break;
 1509+ case WM_COMMAND:
 1510+ switch(LOWORD(wParam))
 1511+ {
 1512+ case IDC_TEXTURE:
 1513+ if(HIWORD(wParam) == CBN_SELCHANGE)
 1514+ {
 1515+ number = texshaderstate.currentstage;
 1516+ vertexshaderstate.texturetype =
 1517+ SendDlgItemMessage(hWnd,IDC_TEXTURE,CB_GETCURSEL,0,0);
 1518+ SelectTexture(&vertexshaderstate.texture,vertexshaderstate.texturetype,
 1519+ 0, FALSE,vertexshaderstate.texturefile);
 1520+ if((vertexshaderstate.texturetype == 2) || (vertexshaderstate.texturetype == 3))
 1521+ d3d7dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_BLENDTEXTUREALPHAPM);
 1522+ else d3d7dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
 1523+ }
 1524+ break;
 1525+ case IDC_TEXTUREFILE:
 1526+ if(HIWORD(wParam) == EN_KILLFOCUS)
 1527+ {
 1528+ number = texshaderstate.currentstage;
 1529+ SendDlgItemMessage(hWnd,IDC_TEXTUREFILE,WM_GETTEXT,MAX_PATH+1,
 1530+ (LPARAM)vertexshaderstate.texturefile);
 1531+ SelectTexture(&vertexshaderstate.texture,vertexshaderstate.texturetype,
 1532+ 0, FALSE,vertexshaderstate.texturefile);
 1533+ }
 1534+ break;
 1535+ case IDC_FOGENABLE:
 1536+ if(HIWORD(wParam) == BN_CLICKED)
 1537+ {
 1538+ if(SendDlgItemMessage(hWnd,IDC_FOGENABLE,BM_GETCHECK,0,0) == BST_CHECKED)
 1539+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE,TRUE);
 1540+ else d3d7dev->SetRenderState(D3DRENDERSTATE_FOGENABLE,FALSE);
 1541+ }
 1542+ break;
 1543+ case IDC_VERTEXFOGMODE:
 1544+ if(HIWORD(wParam) == CBN_SELCHANGE)
 1545+ {
 1546+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE,SendDlgItemMessage(hWnd,
 1547+ IDC_VERTEXFOGMODE,CB_GETCURSEL,0,0));
 1548+ }
 1549+ break;
 1550+ case IDC_PIXELFOGMODE:
 1551+ if(HIWORD(wParam) == CBN_SELCHANGE)
 1552+ {
 1553+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE,SendDlgItemMessage(hWnd,
 1554+ IDC_PIXELFOGMODE,CB_GETCURSEL,0,0));
 1555+ }
 1556+ break;
 1557+ case IDC_FOGSTART:
 1558+ if(HIWORD(wParam) == EN_CHANGE)
 1559+ {
 1560+ SendDlgItemMessage(hWnd,IDC_FOGSTART,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1561+ f = (float)_ttof(tmpstring);
 1562+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGSTART, *((LPDWORD)(&f)));
 1563+ }
 1564+ case IDC_FOGEND:
 1565+ if(HIWORD(wParam) == EN_CHANGE)
 1566+ {
 1567+ SendDlgItemMessage(hWnd,IDC_FOGEND,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1568+ f = (float)_ttof(tmpstring);
 1569+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGEND, *((LPDWORD)(&f)));
 1570+ }
 1571+ case IDC_FOGDENSITY:
 1572+ if(HIWORD(wParam) == EN_CHANGE)
 1573+ {
 1574+ SendDlgItemMessage(hWnd,IDC_FOGDENSITY,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1575+ f = (float)_ttof(tmpstring);
 1576+ d3d7dev->SetRenderState(D3DRENDERSTATE_FOGDENSITY, *((LPDWORD)(&f)));
 1577+ }
 1578+ default:
 1579+ return FALSE;
 1580+ }
 1581+ break;
14431582 case WM_CLOSE:
14441583 ddinterface->Release();
14451584 EndDialog(hWnd,IDCANCEL);