render_dx9.cpp
上传用户:gzqinmao
上传日期:2022-07-13
资源大小:472k
文件大小:2k
源码类别:

OpenGL

开发平台:

Visual C++

  1. #include "Gut.h"
  2. #include "render_data.h"
  3. bool InitResourceDX9(void)
  4. {
  5. // `获得Direct3D9设备`
  6. LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
  7. // `计算出镜头坐标系的转换矩阵`
  8. Matrix4x4 view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);
  9. Matrix4x4 projection_matrix = GutMatrixPerspectiveRH_DirectX(60.0f, 1.0f, 1.0f, 100.0f);
  10. // `设置视角转换矩阵`
  11. device->SetTransform(D3DTS_PROJECTION, (D3DMATRIX *) &projection_matrix);
  12. // `设置镜头转换矩阵`
  13. device->SetTransform(D3DTS_VIEW, (D3DMATRIX *) &view_matrix);
  14. // `关闭光照`
  15. device->SetRenderState(D3DRS_LIGHTING, FALSE);
  16. return true;
  17. }
  18. bool ReleaseResourceDX9(void)
  19. {
  20. return true;
  21. }
  22. // `使用Direct3D9来绘图`
  23. void RenderFrameDX9(void)
  24. {
  25. LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
  26. device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
  27. // `开始下绘图指令`
  28. device->BeginScene(); 
  29. // `设置数据格式`
  30. device->SetFVF(D3DFVF_XYZ); 
  31. // `旋转角度`
  32. static float angle = 0.0f;
  33. angle += 0.01f;
  34. // `设置旋转矩阵`
  35. Matrix4x4 world_matrix;
  36. world_matrix.RotateZ_Replace(angle);
  37. device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &world_matrix);
  38. // `画出金字塔的8条边线`
  39. device->DrawIndexedPrimitiveUP(
  40. D3DPT_LINELIST, // `指定所要画的基本图形种类 `
  41. 0, // `会使用的最小顶点编号, 事实上没太大用处.`
  42. 5, // `顶点数组里有几个顶点`
  43. 8, // `要画出几个基本图形`
  44. g_indices, // `索引数组`
  45. D3DFMT_INDEX16, // `索引数组的类型`
  46. g_vertices, // `顶点数组`
  47. sizeof(Vector4) // `顶点数组里每个顶点的大小`
  48. );
  49. // `声明所有的绘图指令都下完了`
  50. device->EndScene(); 
  51. // `把背景backbuffer显示出来`
  52.     device->Present( NULL, NULL, NULL, NULL );
  53. }