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.

94 lines
2.1 KiB

  1. #include <windows.h>
  2. #include "glew.h"
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #include <string>
  7. #include <sstream>
  8. #include <vector>
  9. #include <functional>
  10. #include <map>
  11. #include "Glm/glm.hpp"
  12. #include "Glm/ext.hpp"
  13. #include "util.h"
  14. #include "Scene.h"
  15. #pragma comment(lib, "opengl32.lib")
  16. #pragma comment(lib, "glew32.lib")
  17. /**
  18. *Ϣ
  19. */
  20. LRESULT CALLBACK GLWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  21. {
  22. switch (msg)
  23. {
  24. case WM_CLOSE:
  25. PostQuitMessage(0);
  26. return 0;
  27. }
  28. return DefWindowProc(hwnd, msg, wParam, lParam);
  29. }
  30. INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  31. {
  32. /*ע�ᴰ��*/
  33. WNDCLASSEX wndclass;
  34. wndclass.cbClsExtra = 0;
  35. wndclass.cbSize = sizeof(WNDCLASSEX);
  36. wndclass.cbWndExtra = 0;
  37. wndclass.hbrBackground = NULL;
  38. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  39. wndclass.hIcon = NULL;
  40. wndclass.hIconSm = NULL;
  41. wndclass.hInstance = hInstance;
  42. wndclass.lpfnWndProc = GLWindowProc;
  43. wndclass.lpszClassName = L"GLWindow";
  44. wndclass.lpszMenuName = NULL;
  45. wndclass.style = CS_VREDRAW | CS_HREDRAW;
  46. ATOM atom = RegisterClassEx(&wndclass);
  47. if (!atom) {
  48. MessageBox(NULL, L"Register Fail", L"Error", MB_OK);
  49. return 0;
  50. }
  51. /*��������*/
  52. RECT rect;
  53. rect.left = 0;
  54. rect.right = 1280;
  55. rect.top = 0;
  56. rect.bottom = 720;
  57. AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, NULL);
  58. int windowWidth = rect.right - rect.left;
  59. int windowHeight = rect.bottom - rect.top;
  60. HWND hwnd = CreateWindowEx(NULL, L"GLWindow", L"OpenGL Window", WS_OVERLAPPEDWINDOW,
  61. 100, 100, windowWidth, windowHeight,
  62. NULL, NULL, hInstance, NULL);
  63. HDC dc = GetDC(hwnd);
  64. ShowWindow(hwnd, SW_SHOW);
  65. UpdateWindow(hwnd);
  66. InitRenderableBuffer(dc, 1280, 720);
  67. Init(1280,720);
  68. MSG msg;
  69. while (true)
  70. {
  71. if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  72. {
  73. if (msg.message == WM_QUIT)
  74. {
  75. break;
  76. }
  77. TranslateMessage(&msg);
  78. DispatchMessage(&msg);
  79. }
  80. Render();
  81. ASwapBuffers(dc);
  82. }
  83. return 0;
  84. }