#include #include #include "../deps/include/glad/glad.h" LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CLOSE: PostQuitMessage(0); break; case WM_LBUTTONDOWN: printf("AAA\n"); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } int main() { // Register the window class WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "GLSample", NULL }; RegisterClassEx(&wc); // Create the window HWND hWnd = CreateWindowEx( 0, "GLSample", "OpenGL Sample", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 256, 256, NULL, NULL, GetModuleHandle(NULL), NULL ); // Enable OpenGL HDC hDC = GetDC(hWnd); PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; int iFormat = ChoosePixelFormat(hDC, &pfd); SetPixelFormat(hDC, iFormat, &pfd); // Create the OpenGL context HGLRC hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); gladLoadGLLoader((GLADloadproc)wglGetProcAddress); // Main loop MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); // Clear the screen glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // Draw a triangle glBegin(GL_TRIANGLES); glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(-0.5f, -0.5f); glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(0.5f, -0.5f); glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(0.0f, 0.5f); glEnd(); // Swap buffers SwapBuffers(hDC); } // Disable OpenGL wglMakeCurrent(NULL, NULL); wglDeleteContext(hRC); ReleaseDC(hWnd, hDC); // Clean up UnregisterClass("GLSample", GetModuleHandle(NULL)); return msg.wParam; }