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.

99 lines
2.3 KiB

  1. #include "ggl.h"
  2. #include "scene.h"
  3. #pragma comment(lib, "opengl32.lib")
  4. #pragma comment(lib, "glew32.lib")
  5. /**
  6. *Ϣ
  7. */
  8. LRESULT CALLBACK GLWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  9. {
  10. switch (msg)
  11. {
  12. case WM_CLOSE:
  13. PostQuitMessage(0);
  14. return 0;
  15. }
  16. return DefWindowProc(hwnd, msg, wParam, lParam);
  17. }
  18. INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  19. {
  20. /*ע�ᴰ��*/
  21. WNDCLASSEX wndclass;
  22. wndclass.cbClsExtra = 0;
  23. wndclass.cbSize = sizeof(WNDCLASSEX);
  24. wndclass.cbWndExtra = 0;
  25. wndclass.hbrBackground = NULL;
  26. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  27. wndclass.hIcon = NULL;
  28. wndclass.hIconSm = NULL;
  29. wndclass.hInstance = hInstance;
  30. wndclass.lpfnWndProc = GLWindowProc;
  31. wndclass.lpszClassName = L"GLWindow";
  32. wndclass.lpszMenuName = NULL;
  33. wndclass.style = CS_VREDRAW | CS_HREDRAW;
  34. ATOM atom = RegisterClassEx(&wndclass);
  35. if (!atom) {
  36. MessageBox(NULL, L"Register Fail", L"Error", MB_OK);
  37. return 0;
  38. }
  39. /*��������*/
  40. RECT rect;
  41. rect.left = 0;
  42. rect.right = 800;
  43. rect.top = 0;
  44. rect.bottom = 600;
  45. AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, NULL);
  46. int windowWidth = rect.right - rect.left;
  47. int windowHeight = rect.bottom - rect.top;
  48. HWND hwnd = CreateWindowEx(NULL, L"GLWindow", L"OpenGL Window", WS_OVERLAPPEDWINDOW,
  49. 100, 100, windowWidth, windowHeight,
  50. NULL, NULL, hInstance, NULL);
  51. /*ѡ�����ظ�ʽ*/
  52. HDC dc = GetDC(hwnd);
  53. PIXELFORMATDESCRIPTOR pfd;
  54. memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
  55. pfd.nVersion = 1;
  56. pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  57. pfd.cColorBits = 32;
  58. pfd.cDepthBits = 24;
  59. pfd.cStencilBits = 8;
  60. pfd.iPixelType = PFD_TYPE_RGBA;
  61. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  62. int pixelFormat = ChoosePixelFormat(dc, &pfd);
  63. SetPixelFormat(dc, pixelFormat, &pfd);
  64. /*����OpenGL��Ⱦ����*/
  65. HGLRC rc = wglCreateContext(dc);
  66. wglMakeCurrent(dc, rc);
  67. /*����OpenGL�߼�api*/
  68. glewInit();
  69. /*��ʼ������*/
  70. Init();
  71. SetViewPortSize(800.0f, 600.0f);
  72. ShowWindow(hwnd, SW_SHOW);
  73. UpdateWindow(hwnd);
  74. MSG msg;
  75. while (true)
  76. {
  77. if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  78. {
  79. if (msg.message == WM_QUIT)
  80. {
  81. break;
  82. }
  83. TranslateMessage(&msg);
  84. DispatchMessage(&msg);
  85. }
  86. Draw();
  87. SwapBuffers(dc);
  88. }
  89. return 0;
  90. }