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.

232 lines
6.1 KiB

5 years ago
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include "Raster.h"
  4. #include "CELLTimestamp.hpp"
  5. LRESULT CALLBACK windowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  6. {
  7. switch(msg)
  8. {
  9. case WM_SIZE:
  10. break;
  11. case WM_LBUTTONDOWN:
  12. {
  13. int x = LOWORD(lParam);
  14. int y = HIWORD(lParam);
  15. }
  16. break;
  17. case WM_LBUTTONUP:
  18. {
  19. int x = LOWORD(lParam);
  20. int y = HIWORD(lParam);
  21. }
  22. break;
  23. case WM_MOUSEMOVE:
  24. {
  25. int x = LOWORD(lParam);
  26. int y = HIWORD(lParam);
  27. }
  28. break;
  29. case WM_RBUTTONDOWN:
  30. {
  31. int x = LOWORD(lParam);
  32. int y = HIWORD(lParam);
  33. }
  34. break;
  35. case WM_RBUTTONUP:
  36. {
  37. int x = LOWORD(lParam);
  38. int y = HIWORD(lParam);
  39. }
  40. break;
  41. case WM_MOUSEWHEEL:
  42. {
  43. short delta = GET_WHEEL_DELTA_WPARAM(wParam);
  44. int ii = 0;
  45. }
  46. break;
  47. case WM_CLOSE:
  48. case WM_DESTROY:
  49. PostQuitMessage(0);
  50. break;
  51. default:
  52. break;
  53. }
  54. return DefWindowProc( hWnd, msg, wParam, lParam );
  55. }
  56. void getResourcePath(HINSTANCE hInstance,char pPath[1024])
  57. {
  58. char szPathName[1024];
  59. char szDriver[64];
  60. char szPath[1024];
  61. GetModuleFileNameA(hInstance,szPathName,sizeof(szPathName));
  62. _splitpath( szPathName, szDriver, szPath, 0, 0 );
  63. sprintf(pPath,"%s%s",szDriver,szPath);
  64. }
  65. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
  66. {
  67. // 1 ע�ᴰ����
  68. ::WNDCLASSEXA winClass;
  69. winClass.lpszClassName = "Raster";
  70. winClass.cbSize = sizeof(::WNDCLASSEX);
  71. winClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
  72. winClass.lpfnWndProc = windowProc;
  73. winClass.hInstance = hInstance;
  74. winClass.hIcon = 0;
  75. winClass.hIconSm = 0;
  76. winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  77. winClass.hbrBackground = (HBRUSH)(BLACK_BRUSH);
  78. winClass.lpszMenuName = NULL;
  79. winClass.cbClsExtra = 0;
  80. winClass.cbWndExtra = 0;
  81. RegisterClassExA(&winClass);
  82. // 2 ��������
  83. HWND hWnd = CreateWindowExA(
  84. NULL,
  85. "Raster",
  86. "Raster",
  87. WS_OVERLAPPEDWINDOW,
  88. 0,
  89. 0,
  90. 800,
  91. 600,
  92. 0,
  93. 0,
  94. hInstance,
  95. 0
  96. );
  97. UpdateWindow( hWnd );
  98. ShowWindow(hWnd,SW_SHOW);
  99. RECT rt = {0};
  100. GetClientRect(hWnd,&rt);
  101. int width = rt.right - rt.left;
  102. int height = rt.bottom - rt.top;
  103. void* buffer = 0;
  104. HDC hDC = GetDC(hWnd);
  105. HDC hMem = ::CreateCompatibleDC(hDC);
  106. BITMAPINFO bmpInfor;
  107. bmpInfor.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  108. bmpInfor.bmiHeader.biWidth = width;
  109. bmpInfor.bmiHeader.biHeight = -height;
  110. bmpInfor.bmiHeader.biPlanes = 1;
  111. bmpInfor.bmiHeader.biBitCount = 32;
  112. bmpInfor.bmiHeader.biCompression = BI_RGB;
  113. bmpInfor.bmiHeader.biSizeImage = 0;
  114. bmpInfor.bmiHeader.biXPelsPerMeter = 0;
  115. bmpInfor.bmiHeader.biYPelsPerMeter = 0;
  116. bmpInfor.bmiHeader.biClrUsed = 0;
  117. bmpInfor.bmiHeader.biClrImportant = 0;
  118. HBITMAP hBmp = CreateDIBSection(hDC,&bmpInfor,DIB_RGB_COLORS,(void**)&buffer,0,0);
  119. SelectObject(hMem,hBmp);
  120. char szPath[1024];
  121. getResourcePath(0,szPath);
  122. char szImage[1024];
  123. sprintf(szImage,"%s/image/bg.png",szPath);
  124. CELL::Image* image = CELL::Image::loadFromFile(szImage);
  125. sprintf(szImage,"%s/image/scale.jpg",szPath);
  126. CELL::Image* image1 = CELL::Image::loadFromFile(szImage);
  127. CELL::Raster raster(width,height,buffer);
  128. raster.setViewPort(0,0,width,height);
  129. raster.setPerspective(60,(float)(width)/(float)(height),0.1,30);
  130. struct Vertex
  131. {
  132. float x,y,z;
  133. float u,v;
  134. CELL::Rgba color;
  135. };
  136. MSG msg = {0};
  137. while(true)
  138. {
  139. if (msg.message == WM_DESTROY
  140. ||msg.message == WM_CLOSE
  141. ||msg.message == WM_QUIT)
  142. {
  143. break;
  144. }
  145. if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  146. {
  147. TranslateMessage( &msg );
  148. DispatchMessage( &msg );
  149. }
  150. raster.clear();
  151. CELL::CELLTimestamp tms;
  152. tms.update();
  153. double mis = tms.getElapsedTimeInMicroSec();
  154. char szBuf[128];
  155. sprintf(szBuf,"%f ",mis);
  156. int i = 00;
  157. memcpy(buffer,raster._buffer,raster._width * raster._height * sizeof(CELL::Rgba));
  158. raster.drawImage(0,0,image);
  159. Vertex vertexs[] =
  160. {
  161. {0.0f, 1.0f, -3.0f, 0.0f, 0.0f, CELL::Rgba(255,0,0,255)},
  162. {-1.0f, -1.0f, -3.0f, 1.0f, 1.0f, CELL::Rgba(0,255,0,255)},
  163. {1.0f, -1.0f, -3.0f, 1.0f, 0.0f, CELL::Rgba(0,0,255,255)},
  164. };
  165. CELL::matrix4 matScale;
  166. CELL::matrix4 matRot;
  167. CELL::matrix4 matAll;
  168. CELL::matrix4 matTrans;
  169. static float angle = 0;
  170. matRot.rotateZ(angle);
  171. angle += 1.0f;
  172. matScale.scale(0.5,.5,1);
  173. matTrans.translate(3,0,0);
  174. matAll = matRot * matScale * matTrans;
  175. raster.loadMatrix(matAll);
  176. image1->setWrapType(1);
  177. raster.bindTexture(image1);
  178. raster.vertexPointer(2,CELL::DT_FLOAT, sizeof(Vertex),&vertexs[0].x);
  179. raster.textureCoordPointer(2,CELL::DT_FLOAT,sizeof(Vertex),&vertexs[0].u);
  180. raster.colorPointer(4,CELL::DT_BYTE, sizeof(Vertex),&vertexs[0].color);
  181. raster.drawArrays(CELL::DM_TRIANGES,0,3);
  182. //TextOut(hMem,10,10,szBuf,strlen(szBuf));
  183. BitBlt(hDC,0,0,width,height,hMem,0,0,SRCCOPY);
  184. }
  185. delete image;
  186. delete image1;
  187. return 0;
  188. }