Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

304 lines
12 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <commctrl.h>
  5. #include <memory.h>
  6. #include <assert.h>
  7. #include <gl\gl.h>
  8. #include "lighting.h"
  9. #include "hugetest.h"
  10. #include "resource.h"
  11. #include "ui_huge.h"
  12. #include "macros.h"
  13. void InitLD(LIGHTINGDATA *pld)
  14. {
  15. int i;
  16. bzero(pld,sizeof(LIGHTINGDATA));
  17. BEGINstring(pld, "lighting");
  18. ENDstring(pld, "lighting");
  19. pld->bEnable = FALSE;
  20. pld->bTwoSided = TRUE;
  21. pld->bLocalViewer = TRUE;
  22. for (i = 0 ; i < NUMBEROFLIGHTS ; i++) {
  23. pld->aLights[i].bEnable = FALSE;
  24. pld->aLights[i].afAmbient[0] = 0.0;
  25. pld->aLights[i].afAmbient[1] = 0.0;
  26. pld->aLights[i].afAmbient[2] = 0.0;
  27. pld->aLights[i].afAmbient[3] = 1.0;
  28. pld->aLights[i].afDiffuse[0] = 1.0;
  29. pld->aLights[i].afDiffuse[1] = 1.0;
  30. pld->aLights[i].afDiffuse[2] = 1.0;
  31. pld->aLights[i].afDiffuse[3] = 1.0;
  32. pld->aLights[i].afSpecular[0] = 1.0;
  33. pld->aLights[i].afSpecular[1] = 1.0;
  34. pld->aLights[i].afSpecular[2] = 1.0;
  35. pld->aLights[i].afSpecular[3] = 1.0;
  36. pld->aLights[i].afPosition[0] = 0.0;
  37. pld->aLights[i].afPosition[1] = 0.0;
  38. pld->aLights[i].afPosition[2] = 1.0;
  39. pld->aLights[i].afPosition[3] = 0.0;
  40. pld->aLights[i].afSpotDirection[0] = 0.0;
  41. pld->aLights[i].afSpotDirection[1] = 0.0;
  42. pld->aLights[i].afSpotDirection[2] = -1.0;
  43. pld->aLights[i].fSpotCutoff = 180;
  44. pld->aLights[i].afAttenuation[0] = 1.0;
  45. pld->aLights[i].afAttenuation[1] = 0.0;
  46. pld->aLights[i].afAttenuation[2] = 0.0;
  47. }
  48. }
  49. void lighting_init(const LIGHTINGDATA ld)
  50. {
  51. static int aiIndexToID[] = {
  52. GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3,
  53. GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7 };
  54. const int iMaxLights = sizeof(aiIndexToID) / sizeof(aiIndexToID[0]);
  55. int i;
  56. assert(iMaxLights >= NUMBEROFLIGHTS);
  57. if (!ld.bEnable) {
  58. glDisable(GL_LIGHTING);
  59. return;
  60. }
  61. glEnable(GL_LIGHTING);
  62. for (i = 0 ; i < NUMBEROFLIGHTS ; i++) {
  63. if (!ld.aLights[i].bEnable) {
  64. glDisable(aiIndexToID[i]);
  65. } else {
  66. glLightfv(aiIndexToID[i], GL_AMBIENT, ld.aLights[i].afAmbient);
  67. glLightfv(aiIndexToID[i], GL_DIFFUSE, ld.aLights[i].afDiffuse);
  68. glLightfv(aiIndexToID[i], GL_SPECULAR, ld.aLights[i].afSpecular);
  69. glLightfv(aiIndexToID[i], GL_POSITION, ld.aLights[i].afPosition);
  70. glLightfv(aiIndexToID[i], GL_SPOT_DIRECTION,
  71. ld.aLights[i].afSpotDirection);
  72. glLightf(aiIndexToID[i],GL_SPOT_EXPONENT,ld.aLights[i].fSpotExponent);
  73. glLightf(aiIndexToID[i], GL_SPOT_CUTOFF, ld.aLights[i].fSpotCutoff);
  74. glLightf(aiIndexToID[i], GL_CONSTANT_ATTENUATION,
  75. ld.aLights[i].afAttenuation[0]);
  76. glLightf(aiIndexToID[i], GL_LINEAR_ATTENUATION,
  77. ld.aLights[i].afAttenuation[1]);
  78. glLightf(aiIndexToID[i], GL_QUADRATIC_ATTENUATION,
  79. ld.aLights[i].afAttenuation[2]);
  80. glEnable(aiIndexToID[i]);
  81. }
  82. }
  83. }
  84. #ifndef NO_UI_IN_CNFG
  85. void lighting_EnableOrDisableWindows(HWND hDlg)
  86. {
  87. static int aiCommands[] =
  88. { L_IDC_AMBIENT1, L_IDC_AMBIENT2, L_IDC_AMBIENT3, L_IDC_AMBIENT4,
  89. L_IDC_DIFFUSE1, L_IDC_DIFFUSE2, L_IDC_DIFFUSE3, L_IDC_DIFFUSE4,
  90. L_IDC_SPECULAR1, L_IDC_SPECULAR2, L_IDC_SPECULAR3, L_IDC_SPECULAR4,
  91. L_IDC_POSITION1, L_IDC_POSITION2, L_IDC_POSITION3, L_IDC_POSITION4,
  92. L_IDC_SPOTDIR1, L_IDC_SPOTDIR2, L_IDC_SPOTDIR3,
  93. L_IDC_CUTOFF, L_IDC_EXPONENT,
  94. L_IDC_ATTENUATION1, L_IDC_ATTENUATION2, L_IDC_ATTENUATION3 };
  95. const int iNumCommands = sizeof(aiCommands) / sizeof(aiCommands[0]);
  96. BOOL b;
  97. int i;
  98. b = (BOOL) IsDlgButtonChecked(hDlg, IDC_ENABLE);
  99. EnableWindow(GetDlgItem(hDlg, L_IDC_TWOSIDED), b);
  100. EnableWindow(GetDlgItem(hDlg, L_IDC_ENABLELIGHT), b);
  101. EnableWindow(GetDlgItem(hDlg, L_IDC_LOCALVIEWER), b);
  102. EnableWindow(GetDlgItem(hDlg, L_IDC_INFINITEVIEWER), b);
  103. if (b)
  104. b = IsDlgButtonChecked(hDlg, L_IDC_ENABLELIGHT) ? TRUE :0;
  105. for (i = 0 ; i < iNumCommands ; i++) {
  106. EnableWindow(GetDlgItem(hDlg,aiCommands[i]),b);
  107. }
  108. }
  109. void lighting_SetDisplayFromData(HWND hDlg, const LIGHTINGDATA *pld, int i)
  110. {
  111. static char acBuffer[100];
  112. sprintf(acBuffer, "Light number: %d", i);
  113. SetDlgItemText(hDlg, L_IDC_LIGHT, acBuffer);
  114. CheckDlgButton(hDlg, IDC_ENABLE, pld->bEnable);
  115. CheckDlgButton(hDlg, L_IDC_TWOSIDED, pld->bTwoSided);
  116. CheckDlgButton(hDlg, L_IDC_LOCALVIEWER, pld->bLocalViewer);
  117. CheckDlgButton(hDlg, L_IDC_INFINITEVIEWER, !(pld->bLocalViewer));
  118. CheckDlgButton(hDlg, L_IDC_ENABLELIGHT, pld->aLights[i].bEnable);
  119. SetDlgFloatString(hDlg, L_IDC_AMBIENT1, pld->aLights[i].afAmbient[0]);
  120. SetDlgFloatString(hDlg, L_IDC_AMBIENT2, pld->aLights[i].afAmbient[1]);
  121. SetDlgFloatString(hDlg, L_IDC_AMBIENT3, pld->aLights[i].afAmbient[2]);
  122. SetDlgFloatString(hDlg, L_IDC_AMBIENT4, pld->aLights[i].afAmbient[3]);
  123. SetDlgFloatString(hDlg, L_IDC_DIFFUSE1, pld->aLights[i].afDiffuse[0]);
  124. SetDlgFloatString(hDlg, L_IDC_DIFFUSE2, pld->aLights[i].afDiffuse[1]);
  125. SetDlgFloatString(hDlg, L_IDC_DIFFUSE3, pld->aLights[i].afDiffuse[2]);
  126. SetDlgFloatString(hDlg, L_IDC_DIFFUSE4, pld->aLights[i].afDiffuse[3]);
  127. SetDlgFloatString(hDlg, L_IDC_SPECULAR1, pld->aLights[i].afSpecular[0]);
  128. SetDlgFloatString(hDlg, L_IDC_SPECULAR2, pld->aLights[i].afSpecular[1]);
  129. SetDlgFloatString(hDlg, L_IDC_SPECULAR3, pld->aLights[i].afSpecular[2]);
  130. SetDlgFloatString(hDlg, L_IDC_SPECULAR4, pld->aLights[i].afSpecular[3]);
  131. SetDlgFloatString(hDlg, L_IDC_POSITION1, pld->aLights[i].afPosition[0]);
  132. SetDlgFloatString(hDlg, L_IDC_POSITION2, pld->aLights[i].afPosition[1]);
  133. SetDlgFloatString(hDlg, L_IDC_POSITION3, pld->aLights[i].afPosition[2]);
  134. SetDlgFloatString(hDlg, L_IDC_POSITION4, pld->aLights[i].afPosition[3]);
  135. SetDlgFloatString(hDlg, L_IDC_SPOTDIR1, pld->aLights[i].afSpotDirection[0]);
  136. SetDlgFloatString(hDlg, L_IDC_SPOTDIR2, pld->aLights[i].afSpotDirection[1]);
  137. SetDlgFloatString(hDlg, L_IDC_SPOTDIR3, pld->aLights[i].afSpotDirection[2]);
  138. SetDlgFloatString(hDlg, L_IDC_CUTOFF, pld->aLights[i].fSpotCutoff);
  139. SetDlgFloatString(hDlg, L_IDC_EXPONENT, pld->aLights[i].fSpotExponent);
  140. SetDlgFloatString(hDlg,L_IDC_ATTENUATION1,pld->aLights[i].afAttenuation[0]);
  141. SetDlgFloatString(hDlg,L_IDC_ATTENUATION2,pld->aLights[i].afAttenuation[1]);
  142. SetDlgFloatString(hDlg,L_IDC_ATTENUATION3,pld->aLights[i].afAttenuation[2]);
  143. lighting_EnableOrDisableWindows(hDlg);
  144. }
  145. void lighting_GetDataFromDisplay(HWND hDlg, LIGHTINGDATA *pld, int i)
  146. {
  147. pld->bEnable = IsDlgButtonChecked(hDlg, IDC_ENABLE);
  148. pld->bTwoSided = IsDlgButtonChecked(hDlg, L_IDC_TWOSIDED);
  149. pld->bLocalViewer = IsDlgButtonChecked(hDlg, L_IDC_LOCALVIEWER);
  150. pld->aLights[i].bEnable = IsDlgButtonChecked(hDlg, L_IDC_ENABLELIGHT);
  151. pld->aLights[i].afAmbient[0] = GetDlgFloatString(hDlg, L_IDC_AMBIENT1);
  152. pld->aLights[i].afAmbient[1] = GetDlgFloatString(hDlg, L_IDC_AMBIENT2);
  153. pld->aLights[i].afAmbient[2] = GetDlgFloatString(hDlg, L_IDC_AMBIENT3);
  154. pld->aLights[i].afAmbient[3] = GetDlgFloatString(hDlg, L_IDC_AMBIENT4);
  155. pld->aLights[i].afDiffuse[0] = GetDlgFloatString(hDlg, L_IDC_DIFFUSE1);
  156. pld->aLights[i].afDiffuse[1] = GetDlgFloatString(hDlg, L_IDC_DIFFUSE2);
  157. pld->aLights[i].afDiffuse[2] = GetDlgFloatString(hDlg, L_IDC_DIFFUSE3);
  158. pld->aLights[i].afDiffuse[3] = GetDlgFloatString(hDlg, L_IDC_DIFFUSE4);
  159. pld->aLights[i].afSpecular[0] = GetDlgFloatString(hDlg, L_IDC_SPECULAR1);
  160. pld->aLights[i].afSpecular[1] = GetDlgFloatString(hDlg, L_IDC_SPECULAR2);
  161. pld->aLights[i].afSpecular[2] = GetDlgFloatString(hDlg, L_IDC_SPECULAR3);
  162. pld->aLights[i].afSpecular[3] = GetDlgFloatString(hDlg, L_IDC_SPECULAR4);
  163. pld->aLights[i].afPosition[0] = GetDlgFloatString(hDlg, L_IDC_POSITION1);
  164. pld->aLights[i].afPosition[1] = GetDlgFloatString(hDlg, L_IDC_POSITION2);
  165. pld->aLights[i].afPosition[2] = GetDlgFloatString(hDlg, L_IDC_POSITION3);
  166. pld->aLights[i].afPosition[3] = GetDlgFloatString(hDlg, L_IDC_POSITION4);
  167. pld->aLights[i].afSpotDirection[0] = GetDlgFloatString(hDlg,L_IDC_SPOTDIR1);
  168. pld->aLights[i].afSpotDirection[1] = GetDlgFloatString(hDlg,L_IDC_SPOTDIR2);
  169. pld->aLights[i].afSpotDirection[2] = GetDlgFloatString(hDlg,L_IDC_SPOTDIR3);
  170. pld->aLights[i].fSpotCutoff = GetDlgFloatString(hDlg, L_IDC_CUTOFF);
  171. pld->aLights[i].fSpotExponent = GetDlgFloatString(hDlg, L_IDC_EXPONENT);
  172. pld->aLights[i].afAttenuation[0]=GetDlgFloatString(hDlg,L_IDC_ATTENUATION1);
  173. pld->aLights[i].afAttenuation[1]=GetDlgFloatString(hDlg,L_IDC_ATTENUATION2);
  174. pld->aLights[i].afAttenuation[2]=GetDlgFloatString(hDlg,L_IDC_ATTENUATION3);
  175. }
  176. BOOL CALLBACK hugeLightDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
  177. {
  178. static LIGHTINGDATA *pld = NULL, ld;
  179. static int index;
  180. switch (msg)
  181. {
  182. case WM_INITDIALOG:
  183. index = 0;
  184. UD_DlgSetPos (hDlg, L_IDC_WHICHLIGHT, index);
  185. UD_DlgSetRange(hDlg, L_IDC_WHICHLIGHT, 7, 0);
  186. pld = (LIGHTINGDATA*) (((PROPSHEETPAGE*)lParam)->lParam);
  187. bcopy(pld, &ld, sizeof(ld));
  188. lighting_SetDisplayFromData(hDlg, &ld, index);
  189. lighting_EnableOrDisableWindows(hDlg);
  190. return TRUE;
  191. case WM_COMMAND:
  192. {
  193. int iControl, iNote;
  194. iControl = LOWORD(wParam);
  195. iNote = HIWORD(wParam); // notification code for edit boxes
  196. switch (iControl)
  197. {
  198. case IDC_ENABLE:
  199. case L_IDC_ENABLELIGHT:
  200. lighting_EnableOrDisableWindows(hDlg);
  201. ld.bEnable = IsDlgButtonChecked(hDlg, IDC_ENABLE);
  202. ld.aLights[index].bEnable
  203. = IsDlgButtonChecked(hDlg, L_IDC_ENABLELIGHT);
  204. break;
  205. case L_IDC_AMBIENT1:
  206. case L_IDC_AMBIENT2:
  207. case L_IDC_AMBIENT3:
  208. case L_IDC_AMBIENT4:
  209. case L_IDC_ATTENUATION1:
  210. case L_IDC_ATTENUATION2:
  211. case L_IDC_ATTENUATION3:
  212. case L_IDC_CUTOFF:
  213. case L_IDC_DIFFUSE1:
  214. case L_IDC_DIFFUSE2:
  215. case L_IDC_DIFFUSE3:
  216. case L_IDC_DIFFUSE4:
  217. case L_IDC_EXPONENT:
  218. case L_IDC_POSITION1:
  219. case L_IDC_POSITION2:
  220. case L_IDC_POSITION3:
  221. case L_IDC_POSITION4:
  222. case L_IDC_SPECULAR1:
  223. case L_IDC_SPECULAR2:
  224. case L_IDC_SPECULAR3:
  225. case L_IDC_SPECULAR4:
  226. case L_IDC_SPOTDIR1:
  227. case L_IDC_SPOTDIR2:
  228. case L_IDC_SPOTDIR3:
  229. if (EN_KILLFOCUS == iNote) {
  230. PropSheet_Changed(GetParent(hDlg),hDlg);
  231. VerifyEditboxFloat(hDlg,iControl);
  232. }
  233. break;
  234. case L_IDC_TWOSIDED:
  235. ld.bTwoSided = IsDlgButtonChecked(hDlg,L_IDC_TWOSIDED);
  236. break;
  237. case L_IDC_LOCALVIEWER:
  238. case L_IDC_INFINITEVIEWER:
  239. ld.bLocalViewer = IsDlgButtonChecked(hDlg,L_IDC_LOCALVIEWER);
  240. break;
  241. default:
  242. PropSheet_Changed(GetParent(hDlg),hDlg);
  243. break;
  244. }
  245. }
  246. break;
  247. case WM_HSCROLL:
  248. lighting_GetDataFromDisplay(hDlg, &ld, index);
  249. index = LOWORD(UD_DlgGetPos(hDlg, L_IDC_WHICHLIGHT));
  250. lighting_SetDisplayFromData(hDlg, &ld, index);
  251. break;
  252. case WM_NOTIFY:
  253. {
  254. LPNMHDR pnmh = (LPNMHDR) lParam;
  255. switch (pnmh->code)
  256. {
  257. case PSN_APPLY: // user clicked on OK or Apply
  258. lighting_GetDataFromDisplay(hDlg, &ld, index);
  259. bcopy(&ld, pld, sizeof(ld));
  260. break;
  261. case PSN_RESET: // user clicked on Cancel
  262. break;
  263. case PSN_HELP: // user clicked help
  264. break;
  265. }
  266. }
  267. break;
  268. default:
  269. return FALSE;
  270. }
  271. return TRUE;
  272. }
  273. #else
  274. #endif // NO_UI_IN_CNFG