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.

185 lines
5.0 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,z;
  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::CELLTimestamp tms;
  114. tms.update();
  115. double mis = tms.getElapsedTimeInMicroSec();
  116. char szBuf[128];
  117. sprintf(szBuf,"%f ",mis);
  118. int i = 00;
  119. memcpy(buffer,raster._buffer,raster._width * raster._height * sizeof(CELL::Rgba));
  120. raster.drawImage(0,0,image);
  121. Vertex vertexs[] =
  122. {
  123. {10, 10, 0, 0.0f, 0.0f, CELL::Rgba(255,255,255,255)},
  124. {110, 110, 0, 1.0f, 1.0f, CELL::Rgba(255,255,255,255)},
  125. {110, 10, 0, 1.0f, 0.0f, CELL::Rgba(255,255,255,255)},
  126. {10, 10, 0, 0.0f, 0.0f, CELL::Rgba(255,255,255,255)},
  127. {110, 110, 0, 1.0f, 1.0f, CELL::Rgba(255,255,255,255)},
  128. {10, 110, 0, 0.0f, 1.0f, CELL::Rgba(255,255,255,255)},
  129. };
  130. raster.loadIdentity();
  131. image1->setWrapType(1);
  132. raster.bindTexture(image1);
  133. raster.vertexPointer(2,CELL::DT_FLOAT, sizeof(Vertex),&vertexs[0].x);
  134. raster.textureCoordPointer(2,CELL::DT_FLOAT,sizeof(Vertex),&vertexs[0].u);
  135. //raster.colorPointer(4,CELL::DT_BYTE, sizeof(Vertex),&vertexs[0].color);
  136. raster.drawArrays(CELL::DM_TRIANGES,0,6);
  137. //TextOut(hMem,10,10,szBuf,strlen(szBuf));
  138. BitBlt(hDC,0,0,width,height,hMem,0,0,SRCCOPY);
  139. }
  140. delete image;
  141. delete image1;
  142. return 0;
  143. }