PlotPixelTest.cpp
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:4k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. // PlotPixelTest.cpp : Defines the class behaviors for the application.
  2. #include "stdafx.h"
  3. #include "PlotPixelTest.h"
  4. #ifdef _DEBUG
  5. #define new DEBUG_NEW
  6. #undef THIS_FILE
  7. static char THIS_FILE[] = __FILE__;
  8. #endif
  9. const bool g_bFullScreen = true; // false;
  10. const DWORD g_dwWidth = 640; // 800; // 1024;
  11. const DWORD g_dwHeight = 480; // 600; // 768;
  12. const DWORD g_dwBPP = 16; // 16; // 24; // 32;
  13. CPlotPixelTestApp::CPlotPixelTestApp(void)
  14. {
  15. SetFullScreen(g_bFullScreen);
  16. SetPackFileName(_T("."), _T("gui"));
  17. // Called during initial app startup, this function
  18. // performs all the permanent initialization.
  19. m_pDDDevice = NULL;
  20. m_pRenderSurface = NULL;
  21. // add your permanent init code here !
  22. }
  23. // Called before the app exits, this function gives the app
  24. // the chance to cleanup after itself.
  25. CPlotPixelTestApp::~CPlotPixelTestApp()
  26. {
  27. // add your cleaup code here !
  28. }
  29. bool CPlotPixelTestApp::GetDXInitSettings(void)
  30. {
  31. if (m_pDirectSound != NULL)
  32. {
  33. if (m_pDirectSound->SelectDSDriver(0) == false)
  34. return  false;
  35. }
  36. if (m_pDirectMusic != NULL)
  37. {
  38. if (m_pDirectMusic->SelectDefaultDMusPort() == false)
  39. return  false;
  40. }
  41. if (m_pDirectDraw->SelectDDDevice(0) == false)
  42. return  false;
  43. if (GetFirstDDDevice()->SelectDisplayMode(
  44. IsFullScreen(), g_dwWidth, g_dwHeight, g_dwBPP) == false)
  45. return  false;
  46. return  true;
  47. }
  48. // Called during device intialization, this code checks the device
  49. // for some minimum set of capabilities, Initialize scene objects.
  50. bool CPlotPixelTestApp::InitDXObjects(void)
  51. {
  52. m_pDDDevice = GetFirstDDDevice();
  53. m_pRenderSurface = m_pDDDevice->GetRenderSurface();
  54. // add your init code here !
  55. m_pRenderSurface->Fill(0);
  56. return  true;
  57. }
  58. // Called when the app is exitting, or the device is being changed,
  59. // this function deletes any device dependant objects.
  60. bool CPlotPixelTestApp::DestroyDXObjects(void)
  61. {
  62. // add your destroy code here !
  63. m_pRenderSurface = NULL;
  64. m_pDDDevice = NULL;
  65. return  CDirectXApp::DestroyDXObjects();
  66. }
  67. // Called once per frame, the call is the entry point for
  68. // animating the scene. This function sets up render states,
  69. // clears the viewport, and renders the scene.
  70. bool CPlotPixelTestApp::UpdateFrame(void)
  71. {
  72. // add your code here !
  73. DDSURFACEDESC2 ddsd;
  74. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  75. if (SUCCEEDED(m_pRenderSurface->Lock(&ddsd)))
  76. {
  77. for (WORD  wX = 0; wX < 50; ++ wX)
  78. {
  79. for (WORD  wY = 0; wY < 100; ++ wY)
  80. {
  81. m_pRenderSurface->PlotPixel(&ddsd, wX, wY, 255, 0, 0);
  82. }
  83. }
  84. for (wX = 50; wX < 100; ++ wX)
  85. {
  86. for (WORD  wY = 0; wY < 100; ++ wY)
  87. {
  88. m_pRenderSurface->PlotPixel(&ddsd, wX, wY, 0, 255, 0);
  89. }
  90. }
  91. for (wX = 100; wX < 150; ++ wX)
  92. {
  93. for (WORD  wY = 0; wY < 100; ++ wY)
  94. {
  95. m_pRenderSurface->PlotPixel(&ddsd, wX, wY, 0, 0, 255);
  96. }
  97. }
  98. for (wX = 150; wX < 200; ++ wX)
  99. {
  100. for (WORD  wY = 0; wY < 100; ++ wY)
  101. {
  102. m_pRenderSurface->PlotPixel(&ddsd, wX, wY, 255, 255, 0);
  103. }
  104. }
  105. for (wX = 200; wX < 250; ++ wX)
  106. {
  107. for (WORD  wY = 0; wY < 100; ++ wY)
  108. {
  109. m_pRenderSurface->PlotPixel(&ddsd, wX, wY, 255, 0, 255);
  110. }
  111. }
  112. for (wX = 250; wX < 300; ++ wX)
  113. {
  114. for (WORD  wY = 0; wY < 100; ++ wY)
  115. {
  116. m_pRenderSurface->PlotPixel(&ddsd, wX, wY, 0, 255, 255);
  117. }
  118. }
  119. //if (m_dwBPP == 8)
  120. {
  121. for (wX = 300; wX < 400; ++ wX)
  122. {
  123. for (WORD  wY = 0; wY < 100; ++ wY)
  124. {
  125. m_pRenderSurface->PutPixel(&ddsd, wX, wY, 1);
  126. }
  127. }
  128. }
  129. m_pRenderSurface->Unlock();
  130. }
  131. return  CDirectXApp::UpdateFrame();
  132. }
  133. // ---- add your functions ! ----
  134. // ----
  135. #if _MSC_VER >= 1200 && _MSC_VER < 1400
  136. #ifdef _DEBUG
  137. #pragma comment(lib, "DXGuideD_VC6.lib")
  138. #else
  139. #pragma comment(lib, "DXGuide_VC6.lib")
  140. #endif // _DEBUG
  141. #endif // _MSC_VER
  142. #if _MSC_VER >= 1000 && _MSC_VER < 1200
  143. #ifdef _DEBUG
  144. #pragma comment(lib, "DXGuideD_VC5.lib")
  145. #else
  146. #pragma comment(lib, "DXGuide_VC5.lib")
  147. #endif // _DEBUG
  148. #endif // _MSC_VER
  149. BEGIN_MESSAGE_MAP(CPlotPixelTestApp, CDirectXApp)
  150. //{{AFX_MSG_MAP(CPlotPixelTestApp)
  151. //}}AFX_MSG_MAP
  152. END_MESSAGE_MAP()
  153. CPlotPixelTestApp theApp;