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.

194 lines
5.3 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. raster.setViewPort(0,0,width,height);
  93. raster.setPerspective(60,(float)(width)/(float)(height),0.1,1000);
  94. struct Vertex
  95. {
  96. float x,y,z;
  97. float u,v;
  98. CELL::Rgba color;
  99. };
  100. MSG msg = {0};
  101. while(true)
  102. {
  103. if (msg.message == WM_DESTROY
  104. ||msg.message == WM_CLOSE
  105. ||msg.message == WM_QUIT)
  106. {
  107. break;
  108. }
  109. if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  110. {
  111. TranslateMessage( &msg );
  112. DispatchMessage( &msg );
  113. }
  114. raster.clear();
  115. CELL::CELLTimestamp tms;
  116. tms.update();
  117. double mis = tms.getElapsedTimeInMicroSec();
  118. char szBuf[128];
  119. sprintf(szBuf,"%f ",mis);
  120. int i = 00;
  121. memcpy(buffer,raster._buffer,raster._width * raster._height * sizeof(CELL::Rgba));
  122. raster.drawImage(0,0,image);
  123. static float angles = 22;
  124. CELL::matrix4 matRot;
  125. matRot.rotateX(angles);
  126. angles += 1;
  127. Vertex vertexs[] =
  128. {
  129. {-1.0f, 0.0f, -5.0f, 0.0f, 0.0f, CELL::Rgba(255,0,0,255)},
  130. {0.0f, 1.0f, -5.0f, 1.0f, 1.0f, CELL::Rgba(0,255,0,255)},
  131. {1.0f, 0.0f, -5.0f, 1.0f, 0.0f, CELL::Rgba(0,0,255,255)},
  132. {10, 10, 0, 0.0f, 0.0f, CELL::Rgba(255,255,255,255)},
  133. {110, 110, 0, 1.0f, 1.0f, CELL::Rgba(255,255,255,255)},
  134. {10, 110, 0, 0.0f, 1.0f, CELL::Rgba(255,255,255,255)},
  135. };
  136. raster.loadMatrix(matRot);
  137. image1->setWrapType(1);
  138. raster.bindTexture(image1);
  139. raster.vertexPointer(2,CELL::DT_FLOAT, sizeof(Vertex),&vertexs[0].x);
  140. raster.textureCoordPointer(2,CELL::DT_FLOAT,sizeof(Vertex),&vertexs[0].u);
  141. raster.colorPointer(4,CELL::DT_BYTE, sizeof(Vertex),&vertexs[0].color);
  142. raster.drawArrays(CELL::DM_TRIANGES,0,3);
  143. //TextOut(hMem,10,10,szBuf,strlen(szBuf));
  144. BitBlt(hDC,0,0,width,height,hMem,0,0,SRCCOPY);
  145. }
  146. delete image;
  147. delete image1;
  148. return 0;
  149. }