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.

197 lines
6.2 KiB

  1. #define STRICT
  2. #define D3D_OVERLOADS
  3. #include "StdAfx.h"
  4. //#include "Settings.h"
  5. //#include "Resource.h"
  6. //#include "Material.h"
  7. IDirectDrawSurface7* CreateTextureFromFile(char* filename);
  8. //******************************************************************************************
  9. #ifndef SAFE_RELEASE
  10. #define SAFE_RELEASE(p) if(p){(p)->Release();(p)=NULL;}else{};
  11. #endif
  12. //******************************************************************************************
  13. BOOL g_bNeedZBuffer = TRUE;
  14. DWORD g_dwWidth,g_dwHeight;
  15. const char* g_szKeyname = "Software\\Microsoft\\D3DClock";
  16. BOOL g_bHardwareTL;
  17. DWORD g_dwVBMemType;
  18. IDirect3D7* g_pD3D=NULL;
  19. DWORD g_dwLastTickCount;
  20. CSeaLife g_SeaLife;
  21. DWORD g_dwBaseTime=0;
  22. //Settings g_Settings;
  23. const float pi2 = 3.1415926536f*2.0f;
  24. //******************************************************************************************
  25. //******************************************************************************************
  26. int WINAPI WinMain(HINSTANCE instance , HINSTANCE prev_instance , LPSTR cmd_line , int show)
  27. {
  28. return DXSvrMain(instance , prev_instance , cmd_line , show);
  29. }
  30. //******************************************************************************************
  31. LRESULT WINAPI ScreenSaverProc(HWND wnd , UINT msg , WPARAM wParam , LPARAM lParam)
  32. {
  33. return DefDXScreenSaverProc(wnd , msg , wParam , lParam);
  34. }
  35. //******************************************************************************************
  36. BOOL ScreenSaverInit()
  37. {
  38. // Get settings
  39. //g_Settings.ReadFromReg();
  40. // Grab pixel width and height of the window we're in
  41. g_pXContext->GetBufferSize(&g_dwWidth , &g_dwHeight);
  42. TRACE("Buffer size is (%d,%d)\n" , g_dwWidth , g_dwHeight);
  43. // Set up the projection matrix to something sensible
  44. D3DXMATRIX projection;
  45. D3DXMatrixPerspectiveFovLH(&projection , 1.3f , float(g_dwHeight)/float(g_dwWidth) ,
  46. 0.1f , 100.0f);
  47. g_pDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION , projection);
  48. // Set up the initial camera to something sensible
  49. D3DXMATRIX camera;
  50. D3DXMatrixLookAtLH(&camera , &D3DXVECTOR3(0,0,-2.3f) , &D3DXVECTOR3(0,0,0) , &D3DXVECTOR3(0,1,0));
  51. g_pDevice->SetTransform(D3DTRANSFORMSTATE_VIEW , camera);
  52. // Set a matt white default material
  53. D3DMATERIAL7 mat;
  54. mat.ambient = mat.diffuse = D3DXCOLOR(1,1,1,0);
  55. mat.specular = mat.emissive = D3DXCOLOR(0,0,0,0);
  56. mat.power = 0;
  57. g_pDevice->SetMaterial(&mat);
  58. // Figure out if the device is HW or SW T&L
  59. D3DDEVICEDESC7 devdesc = {sizeof(devdesc)};
  60. g_pDevice->GetCaps(&devdesc);
  61. if (devdesc.dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
  62. {
  63. TRACE("Is hardware T&L\n");
  64. g_bHardwareTL = TRUE;
  65. g_dwVBMemType = 0;
  66. }
  67. else
  68. {
  69. TRACE("Is software T&L\n");
  70. g_bHardwareTL = FALSE;
  71. g_dwVBMemType = D3DVBCAPS_SYSTEMMEMORY;
  72. }
  73. // Grab the D3D object (we'll need it)
  74. g_pD3D = g_pXContext->GetD3D();
  75. // Set up some global renderstates
  76. g_pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE , TRUE);
  77. g_pDevice->SetTextureStageState(0 , D3DTSS_MAGFILTER , D3DTFG_LINEAR);
  78. g_pDevice->SetTextureStageState(0 , D3DTSS_MINFILTER , D3DTFN_LINEAR);
  79. g_pDevice->SetTextureStageState(0 , D3DTSS_MIPFILTER , D3DTFP_LINEAR);
  80. g_pDevice->SetTextureStageState(1 , D3DTSS_MAGFILTER , D3DTFG_LINEAR);
  81. g_pDevice->SetTextureStageState(1 , D3DTSS_MINFILTER , D3DTFN_LINEAR);
  82. g_pDevice->SetTextureStageState(1 , D3DTSS_MIPFILTER , D3DTFP_LINEAR);
  83. g_pDevice->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE , TRUE);
  84. // Set up lighting
  85. g_pDevice->SetRenderState(D3DRENDERSTATE_LIGHTING , TRUE);
  86. g_pDevice->SetRenderState(D3DRENDERSTATE_AMBIENT , 0xff222222);
  87. g_pDevice->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE , D3DMCS_MATERIAL);
  88. g_pDevice->SetRenderState(D3DRENDERSTATE_DIFFUSEMATERIALSOURCE , D3DMCS_MATERIAL);
  89. g_pDevice->SetRenderState(D3DRENDERSTATE_SPECULARMATERIALSOURCE , D3DMCS_MATERIAL);
  90. g_pDevice->SetRenderState(D3DRENDERSTATE_EMISSIVEMATERIALSOURCE , D3DMCS_MATERIAL);
  91. D3DLIGHT7 light;
  92. light.dltType = D3DLIGHT_POINT;
  93. light.dcvDiffuse = D3DXCOLOR(1,1,1,1);
  94. light.dcvSpecular = D3DXCOLOR(1,1,1,0);
  95. light.dcvAmbient = D3DXCOLOR(0,0,0,1);
  96. light.dvPosition = D3DXVECTOR3(0,0,-2);
  97. light.dvDirection = D3DXVECTOR3(0,0,1);
  98. light.dvRange = D3DLIGHT_RANGE_MAX;
  99. light.dvFalloff = 0;
  100. light.dvAttenuation0 = 0;
  101. light.dvAttenuation1 = 0;
  102. light.dvAttenuation2 = 0.3f;
  103. light.dvTheta = light.dvPhi = 0;
  104. g_pDevice->SetLight(0 , &light);
  105. g_pDevice->LightEnable(0 , TRUE);
  106. // Set texture transform (we always use the same one, if we do use one)
  107. D3DXMATRIX texmatrix;
  108. D3DXMatrixIdentity(&texmatrix);
  109. texmatrix.m00 = texmatrix.m11 = 0.5f;
  110. texmatrix.m30 = texmatrix.m31 = 0.5f;
  111. g_pDevice->SetTransform(D3DTRANSFORMSTATE_TEXTURE0 , texmatrix);
  112. g_pDevice->SetTransform(D3DTRANSFORMSTATE_TEXTURE1 , texmatrix);
  113. g_dwLastTickCount = GetTickCount();
  114. g_dwBaseTime=timeGetTime();
  115. g_SeaLife.InitDeviceObjects(g_pDevice,NULL);
  116. g_SeaLife.OneTimeSceneInit();
  117. return TRUE;
  118. }
  119. //******************************************************************************************
  120. void ScreenSaverShutdown()
  121. {
  122. g_SeaLife.DeleteDeviceObjects();
  123. g_SeaLife.FinalCleanup();
  124. SAFE_RELEASE(g_pD3D);
  125. //g_Settings.ReleaseMaterialSettings();
  126. }
  127. //******************************************************************************************
  128. void ScreenSaverDrawFrame()
  129. {
  130. DWORD tick = GetTickCount();
  131. DWORD elapsed = tick - g_dwLastTickCount;
  132. g_dwLastTickCount = tick;
  133. float felapsed = float(elapsed);
  134. static float theta,phi,xang,yang;
  135. FLOAT fTime = (timeGetTime() - g_dwBaseTime) * 0.001f;
  136. g_SeaLife.FrameMove(fTime);
  137. g_pXContext->RestoreSurfaces();
  138. //g_pXContext->Clear(D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER);
  139. //g_pDevice->BeginScene();
  140. //TODO DRAW
  141. g_SeaLife.Render(g_pDevice);
  142. //g_pDevice->EndScene();
  143. Flip();
  144. }
  145. BOOL ScreenSaverDoConfig()
  146. {
  147. return TRUE;
  148. }