|
@@ -5,6 +5,8 @@
|
|
|
#include <windowsx.h>
|
|
#include <windowsx.h>
|
|
|
#include <winuser.h>
|
|
#include <winuser.h>
|
|
|
|
|
|
|
|
|
|
+#include "log.h"
|
|
|
|
|
+
|
|
|
// int _main() {
|
|
// int _main() {
|
|
|
// return 0;
|
|
// return 0;
|
|
|
// }
|
|
// }
|
|
@@ -21,27 +23,79 @@ void OnSize(HWND hwnd, UINT flag, int width, int height) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|
|
- State* pState = NULL;
|
|
|
|
|
- if (uMsg == WM_CREATE) {
|
|
|
|
|
- CREATESTRUCT* pCreate = (CREATESTRUCT*) lParam;
|
|
|
|
|
- pState = (State*) pCreate->lpCreateParams;
|
|
|
|
|
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) pState);
|
|
|
|
|
- } else {
|
|
|
|
|
- LONG_PTR ptr = GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
|
|
|
|
- pState = (State*) ptr;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // State* pState = NULL;
|
|
|
|
|
+ // if (uMsg == WM_CREATE) {
|
|
|
|
|
+ // CREATESTRUCT* pCreate = (CREATESTRUCT*) lParam;
|
|
|
|
|
+ // pState = (State*) pCreate->lpCreateParams;
|
|
|
|
|
+ // SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) pState);
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // LONG_PTR ptr = GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
|
|
|
|
+ // pState = (State*) ptr;
|
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
switch (uMsg) {
|
|
switch (uMsg) {
|
|
|
- case WM_LBUTTONDOWN:
|
|
|
|
|
- {
|
|
|
|
|
- printf("State: msg: %s, num: %d\n", pState->msg, pState->num);
|
|
|
|
|
|
|
+ // case WM_LBUTTONDOWN: {
|
|
|
|
|
+ // printf("State: msg: %s, num: %d\n", pState->msg, pState->num);
|
|
|
|
|
+ //
|
|
|
|
|
+ // printf("lParam: %llx\n", lParam);
|
|
|
|
|
+ // int mouse_x = GET_X_LPARAM(lParam);
|
|
|
|
|
+ // printf("mouse_x: %x\n", mouse_x);
|
|
|
|
|
+ // int mouse_y = GET_Y_LPARAM(lParam);
|
|
|
|
|
+ // printf("mouse_y: %x\n", mouse_y);
|
|
|
|
|
+ // printf("x: %d y: %d\n", mouse_x, mouse_y);
|
|
|
|
|
+ //
|
|
|
|
|
+ // return 0;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ case WM_CREATE: {
|
|
|
|
|
+ const PIXELFORMATDESCRIPTOR pfd = {
|
|
|
|
|
+ sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
|
+ 1,
|
|
|
|
|
+ PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
|
|
|
|
|
+ PFD_TYPE_RGBA,
|
|
|
|
|
+ 32, // Color depth
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 24, // Depth buffer bits
|
|
|
|
|
+ 8, // Stencil buffer bits
|
|
|
|
|
+ 0,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ HDC hdc = GetWindowDC(hwnd);
|
|
|
|
|
+ if (hdc == NULL) {
|
|
|
|
|
+ LOG_ERROR("Failed to get window DC");
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ const int pixel_format = ChoosePixelFormat(hdc, &pfd);
|
|
|
|
|
+ if (SetPixelFormat(hdc, pixel_format, &pfd) == FALSE) {
|
|
|
|
|
+ LOG_ERRORF("Failed to set pixel format. Error: %d", GetLastError());
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- printf("lParam: %llx\n", lParam);
|
|
|
|
|
- int mouse_x = GET_X_LPARAM(lParam);
|
|
|
|
|
- printf("mouse_x: %x\n", mouse_x);
|
|
|
|
|
- int mouse_y = GET_Y_LPARAM(lParam);
|
|
|
|
|
- printf("mouse_y: %x\n", mouse_y);
|
|
|
|
|
- printf("x: %d y: %d\n", mouse_x, mouse_y);
|
|
|
|
|
|
|
+ HGLRC gl_ctx = wglCreateContext(hdc);
|
|
|
|
|
+ if (gl_ctx == NULL) {
|
|
|
|
|
+ LOG_ERRORF("Failed to create OpenGL context. Error: %d", GetLastError());
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (wglMakeCurrent(hdc, gl_ctx) == FALSE) {
|
|
|
|
|
+ LOG_ERRORF("Failed to make OpenGL context current. Error: %d", GetLastError());
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // glClearColor(1.0, 1.0, 0.0, 1.0);
|
|
|
|
|
+ // glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -62,31 +116,29 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
- case WM_SIZE:
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ case WM_SIZE: {
|
|
|
int width = LOWORD(lParam);
|
|
int width = LOWORD(lParam);
|
|
|
int height = HIWORD(lParam);
|
|
int height = HIWORD(lParam);
|
|
|
OnSize(hwnd, (UINT) wParam, width, height);
|
|
OnSize(hwnd, (UINT) wParam, width, height);
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- case WM_PAINT:
|
|
|
|
|
- {
|
|
|
|
|
- PAINTSTRUCT ps;
|
|
|
|
|
- HDC hdc = BeginPaint(hwnd, &ps);
|
|
|
|
|
-
|
|
|
|
|
- FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW + 1));
|
|
|
|
|
- RECT blue = {
|
|
|
|
|
- .bottom = 100,
|
|
|
|
|
- .left = 0,
|
|
|
|
|
- .right = 100,
|
|
|
|
|
- .top = 0
|
|
|
|
|
- };
|
|
|
|
|
- FillRect(hdc, &blue, (HBRUSH) (COLOR_BACKGROUND + 1));
|
|
|
|
|
-
|
|
|
|
|
- EndPaint(hwnd, &ps);
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // case WM_PAINT: {
|
|
|
|
|
+ // PAINTSTRUCT ps;
|
|
|
|
|
+ // HDC hdc = BeginPaint(hwnd, &ps);
|
|
|
|
|
+ //
|
|
|
|
|
+ // FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW + 1));
|
|
|
|
|
+ // RECT blue = {
|
|
|
|
|
+ // .bottom = 100,
|
|
|
|
|
+ // .left = 0,
|
|
|
|
|
+ // .right = 100,
|
|
|
|
|
+ // .top = 0
|
|
|
|
|
+ // };
|
|
|
|
|
+ // FillRect(hdc, &blue, (HBRUSH) (COLOR_BACKGROUND + 1));
|
|
|
|
|
+ //
|
|
|
|
|
+ // EndPaint(hwnd, &ps);
|
|
|
|
|
+ // return 0;
|
|
|
|
|
+ // }
|
|
|
}
|
|
}
|
|
|
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
|
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
|
|
}
|
|
}
|
|
@@ -99,6 +151,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
|
|
|
wc.lpfnWndProc = WindowProc;
|
|
wc.lpfnWndProc = WindowProc;
|
|
|
wc.hInstance = hInstance;
|
|
wc.hInstance = hInstance;
|
|
|
wc.lpszClassName = CLASS_NAME;
|
|
wc.lpszClassName = CLASS_NAME;
|
|
|
|
|
+ wc.style = CS_OWNDC;
|
|
|
|
|
|
|
|
RegisterClass(&wc);
|
|
RegisterClass(&wc);
|
|
|
|
|
|
|
@@ -124,8 +177,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
if (hwnd == NULL) {
|
|
if (hwnd == NULL) {
|
|
|
- printf("ERROR: hwnd was NULL\n");
|
|
|
|
|
- return 0;
|
|
|
|
|
|
|
+ LOG_ERROR("ERROR: hwnd was NULL\n");
|
|
|
|
|
+ return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ShowWindow(hwnd, nCmdShow);
|
|
ShowWindow(hwnd, nCmdShow);
|