DXGL r268 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r267‎ | r268 | r269 >
Date:21:57, 9 October 2012
Author:admin
Status:new
Tags:
Comment:
Add vertex color source to Vertex Shader demo.
Fix crashes when closing the Vertex Shader demo.
Populate light colors in Vertex Shader demo.
Modified paths:
  • /dxgltest/Tests3D.cpp (modified) (history)

Diff [purge]

Index: dxgltest/Tests3D.cpp
@@ -85,6 +85,14 @@
8686
8787 typedef struct
8888 {
 89+ DWORD ambient;
 90+ DWORD diffuse;
 91+ DWORD specular;
 92+} HEXLIGHTCOLOR;
 93+HEXLIGHTCOLOR hexlightcolor[8];
 94+
 95+typedef struct
 96+{
8997 D3DTEXTUREOP colorop;
9098 DWORD colorarg1;
9199 DWORD colorarg2;
@@ -166,6 +174,7 @@
167175 DWORD texturetype;
168176 TCHAR texturefile[MAX_PATH+1];
169177 MultiDirectDrawSurface* texture;
 178+ int currentlight;
170179 } VERTEXSHADERSTATE;
171180 static VERTEXSHADERSTATE vertexshaderstate;
172181
@@ -741,6 +750,7 @@
742751 ZeroMemory(&lights[i],sizeof(D3DLIGHT7));
743752 lights[i].dcvDiffuse.r = lights[i].dcvDiffuse.g = lights[i].dcvDiffuse.b = 1;
744753 lights[i].dltType = D3DLIGHT_DIRECTIONAL;
 754+ hexlightcolor[i].diffuse = 0xFFFFFF;
745755 }
746756 lightenable[0] = TRUE;
747757 lights[0].dvPosition = D3DVECTOR(-10,-10,-10);
@@ -1780,6 +1790,7 @@
17811791 SendDlgItemMessage(hWnd,IDC_CULLMODE,CB_ADDSTRING,0,(LPARAM)_T("CW"));
17821792 SendDlgItemMessage(hWnd,IDC_CULLMODE,CB_ADDSTRING,0,(LPARAM)_T("CCW"));
17831793 SendDlgItemMessage(hWnd,IDC_CULLMODE,CB_SETCURSEL,2,0);
 1794+ SendDlgItemMessage(hWnd,IDC_VERTEXCOLOR,BM_SETCHECK,BST_CHECKED,0);
17841795 PopulateSourceCombo(GetDlgItem(hWnd,IDC_DIFFUSESOURCE));
17851796 PopulateSourceCombo(GetDlgItem(hWnd,IDC_SPECULARSOURCE));
17861797 PopulateSourceCombo(GetDlgItem(hWnd,IDC_AMBIENTSOURCE));
@@ -1786,15 +1797,34 @@
17871798 PopulateSourceCombo(GetDlgItem(hWnd,IDC_EMISSIVESOURCE));
17881799 SendDlgItemMessage(hWnd,IDC_DIFFUSESOURCE,CB_SETCURSEL,D3DMCS_COLOR1,0);
17891800 SendDlgItemMessage(hWnd,IDC_SPECULARSOURCE,CB_SETCURSEL,D3DMCS_COLOR2,0);
1790 - SendDlgItemMessage(hWnd,IDC_AMBIENTSOURCE,CB_SETCURSEL,D3DMCS_COLOR2,0);
 1801+ SendDlgItemMessage(hWnd,IDC_AMBIENTSOURCE,CB_SETCURSEL,D3DMCS_MATERIAL,0);
17911802 SendDlgItemMessage(hWnd,IDC_EMISSIVESOURCE,CB_SETCURSEL,D3DMCS_MATERIAL,0);
17921803 SendDlgItemMessage(hWnd,IDC_SPINDETAIL,UDM_SETRANGE32,2,64);
17931804 SendDlgItemMessage(hWnd,IDC_SPINDETAIL,UDM_SETPOS32,0,8);
 1805+ SendDlgItemMessage(hWnd,IDC_SPINLIGHT,UDM_SETRANGE32,0,7);
 1806+ SendDlgItemMessage(hWnd,IDC_LIGHTDIFFUSE,WM_SETTEXT,0,(LPARAM)_T("00FFFFFF"));
 1807+ SendDlgItemMessage(hWnd,IDC_LIGHTAMBIENT,WM_SETTEXT,0,(LPARAM)_T("00000000"));
 1808+ SendDlgItemMessage(hWnd,IDC_LIGHTSPECULAR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
 1809+ SendDlgItemMessage(hWnd,IDC_LIGHTRANGE,WM_SETTEXT,0,(LPARAM)_T("0"));
 1810+ SendDlgItemMessage(hWnd,IDC_LIGHTFALLOFF,WM_SETTEXT,0,(LPARAM)_T("0"));
 1811+ SendDlgItemMessage(hWnd,IDC_LIGHTTHETA,WM_SETTEXT,0,(LPARAM)_T("0"));
 1812+ SendDlgItemMessage(hWnd,IDC_LIGHTPHI,WM_SETTEXT,0,(LPARAM)_T("0"));
 1813+ SendDlgItemMessage(hWnd,IDC_LIGHTATTEN0,WM_SETTEXT,0,(LPARAM)_T("0"));
 1814+ SendDlgItemMessage(hWnd,IDC_LIGHTATTEN1,WM_SETTEXT,0,(LPARAM)_T("0"));
 1815+ SendDlgItemMessage(hWnd,IDC_LIGHTATTEN2,WM_SETTEXT,0,(LPARAM)_T("0"));
 1816+ SendDlgItemMessage(hWnd,IDC_POWER,WM_SETTEXT,0,(LPARAM)_T("0"));
 1817+ SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_ADDSTRING,0,(LPARAM)_T("Point"));
 1818+ SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_ADDSTRING,0,(LPARAM)_T("Spot"));
 1819+ SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_ADDSTRING,0,(LPARAM)_T("Directional"));
 1820+ SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_ADDSTRING,0,(LPARAM)_T("Parallel Point"));
 1821+ SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_ADDSTRING,0,(LPARAM)_T("GL Spot"));
 1822+ SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_SETCURSEL,D3DLIGHT_DIRECTIONAL-1,0);
17941823 ::width = ddsd.dwWidth;
17951824 ::height = ddsd.dwHeight;
17961825 vertexshaderstate.texture = NULL;
17971826 vertexshaderstate.texturefile[0] = 0;
17981827 vertexshaderstate.texturetype = 0;
 1828+ vertexshaderstate.currentlight = 0;
17991829 StartTimer(hWnd,WM_APP,60);
18001830 break;
18011831 case WM_COMMAND:
@@ -1937,6 +1967,7 @@
19381968 }
19391969 break;
19401970 case IDC_EMISSIVE:
 1971+ if(HIWORD(wParam) == EN_CHANGE)
19411972 {
19421973 SendDlgItemMessage(hWnd,IDC_EMISSIVE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
19431974 _stscanf(tmpstring,_T("%x"),&number);
@@ -1948,6 +1979,7 @@
19491980 }
19501981 break;
19511982 case IDC_MATAMBIENT:
 1983+ if(HIWORD(wParam) == EN_CHANGE)
19521984 {
19531985 SendDlgItemMessage(hWnd,IDC_MATAMBIENT,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
19541986 _stscanf(tmpstring,_T("%x"),&number);
@@ -1959,6 +1991,7 @@
19601992 }
19611993 break;
19621994 case IDC_MATDIFFUSE:
 1995+ if(HIWORD(wParam) == EN_CHANGE)
19631996 {
19641997 SendDlgItemMessage(hWnd,IDC_MATDIFFUSE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
19651998 _stscanf(tmpstring,_T("%x"),&number);
@@ -1970,6 +2003,7 @@
19712004 }
19722005 break;
19732006 case IDC_MATSPECULAR:
 2007+ if(HIWORD(wParam) == EN_CHANGE)
19742008 {
19752009 SendDlgItemMessage(hWnd,IDC_MATSPECULAR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
19762010 _stscanf(tmpstring,_T("%x"),&number);
@@ -1980,6 +2014,14 @@
19812015 d3d7dev->SetMaterial(&material);
19822016 }
19832017 break;
 2018+ case IDC_POWER:
 2019+ if(HIWORD(wParam) == EN_CHANGE)
 2020+ {
 2021+ SendDlgItemMessage(hWnd,IDC_POWER,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 2022+ material.power = (float)_ttof(tmpstring);
 2023+ d3d7dev->SetMaterial(&material);
 2024+ }
 2025+ break;
19842026 case IDC_ENABLELIGHT:
19852027 if(HIWORD(wParam) == BN_CLICKED)
19862028 {
@@ -2013,6 +2055,53 @@
20142056 MakeCube3D(5,number);
20152057 }
20162058 break;
 2059+ case IDC_DIFFUSESOURCE:
 2060+ if(HIWORD(wParam) == CBN_SELCHANGE)
 2061+ {
 2062+ d3d7dev->SetRenderState(D3DRENDERSTATE_DIFFUSEMATERIALSOURCE,SendDlgItemMessage(hWnd,
 2063+ IDC_DIFFUSESOURCE,CB_GETCURSEL,0,0));
 2064+ }
 2065+ break;
 2066+ case IDC_SPECULARSOURCE:
 2067+ if(HIWORD(wParam) == CBN_SELCHANGE)
 2068+ {
 2069+ d3d7dev->SetRenderState(D3DRENDERSTATE_SPECULARMATERIALSOURCE,SendDlgItemMessage(hWnd,
 2070+ IDC_SPECULARSOURCE,CB_GETCURSEL,0,0));
 2071+ }
 2072+ break;
 2073+ case IDC_AMBIENTSOURCE:
 2074+ if(HIWORD(wParam) == CBN_SELCHANGE)
 2075+ {
 2076+ d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE,SendDlgItemMessage(hWnd,
 2077+ IDC_AMBIENTSOURCE,CB_GETCURSEL,0,0));
 2078+ }
 2079+ break;
 2080+ case IDC_EMISSIVESOURCE:
 2081+ if(HIWORD(wParam) == CBN_SELCHANGE)
 2082+ {
 2083+ d3d7dev->SetRenderState(D3DRENDERSTATE_EMISSIVEMATERIALSOURCE,SendDlgItemMessage(hWnd,
 2084+ IDC_EMISSIVESOURCE,CB_GETCURSEL,0,0));
 2085+ }
 2086+ break;
 2087+ case IDC_LIGHTNUMBER:
 2088+ if(HIWORD(wParam) == EN_CHANGE)
 2089+ {
 2090+ SendDlgItemMessage(hWnd,IDC_LIGHTNUMBER,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 2091+ number = _ttoi(tmpstring);
 2092+ if(number < 0) SendDlgItemMessage(hWnd,IDC_LIGHTNUMBER,WM_SETTEXT,0,(LPARAM)_T("0"));
 2093+ if(number > 7) SendDlgItemMessage(hWnd,IDC_LIGHTNUMBER,WM_SETTEXT,0,(LPARAM)_T("7"));
 2094+ vertexshaderstate.currentlight = number;
 2095+ _itot(hexlightcolor[vertexshaderstate.currentlight].ambient,tmpstring,16);
 2096+ strupper(tmpstring); paddwordzeroes(tmpstring);
 2097+ SendDlgItemMessage(hWnd,IDC_LIGHTAMBIENT,WM_SETTEXT,0,(LPARAM)tmpstring);
 2098+ _itot(hexlightcolor[vertexshaderstate.currentlight].diffuse,tmpstring,16);
 2099+ strupper(tmpstring); paddwordzeroes(tmpstring);
 2100+ SendDlgItemMessage(hWnd,IDC_LIGHTDIFFUSE,WM_SETTEXT,0,(LPARAM)tmpstring);
 2101+ _itot(hexlightcolor[vertexshaderstate.currentlight].specular,tmpstring,16);
 2102+ strupper(tmpstring); paddwordzeroes(tmpstring);
 2103+ SendDlgItemMessage(hWnd,IDC_LIGHTSPECULAR,WM_SETTEXT,0,(LPARAM)tmpstring);
 2104+ SendDlgItemMessage(hWnd,IDC_LIGHTTYPE,CB_SETCURSEL,lights[vertexshaderstate.currentlight].dltType-1,0);
 2105+ }
20172106 default:
20182107 return FALSE;
20192108 }