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.

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