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.

141 lines
3.6 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. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
  21. {
  22. // 1 ע�ᴰ����
  23. ::WNDCLASSEXA winClass;
  24. winClass.lpszClassName = "Raster";
  25. winClass.cbSize = sizeof(::WNDCLASSEX);
  26. winClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
  27. winClass.lpfnWndProc = windowProc;
  28. winClass.hInstance = hInstance;
  29. winClass.hIcon = 0;
  30. winClass.hIconSm = 0;
  31. winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  32. winClass.hbrBackground = (HBRUSH)(BLACK_BRUSH);
  33. winClass.lpszMenuName = NULL;
  34. winClass.cbClsExtra = 0;
  35. winClass.cbWndExtra = 0;
  36. RegisterClassExA(&winClass);
  37. // 2 ��������
  38. HWND hWnd = CreateWindowExA(
  39. NULL,
  40. "Raster",
  41. "Raster",
  42. WS_OVERLAPPEDWINDOW,
  43. 0,
  44. 0,
  45. 480,
  46. 320,
  47. 0,
  48. 0,
  49. hInstance,
  50. 0
  51. );
  52. UpdateWindow( hWnd );
  53. ShowWindow(hWnd,SW_SHOW);
  54. RECT rt = {0};
  55. GetClientRect(hWnd,&rt);
  56. int width = rt.right - rt.left;
  57. int height = rt.bottom - rt.top;
  58. void* buffer = 0;
  59. HDC hDC = GetDC(hWnd);
  60. HDC hMem = ::CreateCompatibleDC(hDC);
  61. BITMAPINFO bmpInfor;
  62. bmpInfor.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  63. bmpInfor.bmiHeader.biWidth = width;
  64. bmpInfor.bmiHeader.biHeight = -height;
  65. bmpInfor.bmiHeader.biPlanes = 1;
  66. bmpInfor.bmiHeader.biBitCount = 32;
  67. bmpInfor.bmiHeader.biCompression = BI_RGB;
  68. bmpInfor.bmiHeader.biSizeImage = 0;
  69. bmpInfor.bmiHeader.biXPelsPerMeter = 0;
  70. bmpInfor.bmiHeader.biYPelsPerMeter = 0;
  71. bmpInfor.bmiHeader.biClrUsed = 0;
  72. bmpInfor.bmiHeader.biClrImportant = 0;
  73. HBITMAP hBmp = CreateDIBSection(hDC,&bmpInfor,DIB_RGB_COLORS,(void**)&buffer,0,0);
  74. SelectObject(hMem,hBmp);
  75. CELL::Raster raster(width,height,buffer);
  76. MSG msg = {0};
  77. while(true)
  78. {
  79. if (msg.message == WM_DESTROY
  80. ||msg.message == WM_CLOSE
  81. ||msg.message == WM_QUIT)
  82. {
  83. break;
  84. }
  85. if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  86. {
  87. TranslateMessage( &msg );
  88. DispatchMessage( &msg );
  89. }
  90. raster.clear();
  91. CELL::int2 pt[3] =
  92. {
  93. CELL::int2(230,-80),
  94. CELL::int2(10,280),
  95. CELL::int2(600,280),
  96. };
  97. CELL::Rgba color1(255,0,0);
  98. CELL::Rgba color2(0,255,0);
  99. CELL::Rgba color3(0,0,255);
  100. CELL::CELLTimestamp tms;
  101. tms.update();
  102. raster.drawTriangle(pt[0],pt[1],pt[2],color1,color2,color3);
  103. double mis = tms.getElapsedTimeInMicroSec();
  104. char szBuf[128];
  105. sprintf(szBuf,"%f ",mis);
  106. int i = 00;
  107. memcpy(buffer,raster._buffer,raster._width * raster._height * sizeof(CELL::Rgba));
  108. TextOut(hMem,10,10,szBuf,strlen(szBuf));
  109. BitBlt(hDC,0,0,width,height,hMem,0,0,SRCCOPY);
  110. }
  111. return 0;
  112. }