reinit repo after broken git
This commit is contained in:
132
src/app/app_win32.c
Normal file
132
src/app/app_win32.c
Normal file
@@ -0,0 +1,132 @@
|
||||
#include "core/core.h"
|
||||
#include "app.gen.h"
|
||||
|
||||
#include "core/core.c"
|
||||
#include "app.gen.c"
|
||||
|
||||
#pragma comment(linker, "/subsystem:windows")
|
||||
#pragma comment(lib, "gdi32.lib")
|
||||
#pragma comment(lib, "user32.lib")
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
|
||||
|
||||
b32 w32_good_scheduling = false;
|
||||
WNDCLASSW w32_wc;
|
||||
HWND w32_window_handle;
|
||||
HDC w32_dc;
|
||||
|
||||
void w32_on_key_down(app_key_t key) {
|
||||
}
|
||||
|
||||
void w32_on_key_up(app_key_t key) {
|
||||
}
|
||||
|
||||
LRESULT CALLBACK w32_window_proc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
switch (msg) {
|
||||
case WM_CLOSE: PostQuitMessage(0); break;
|
||||
case WM_KEYUP: w32_key_dispatch(wparam, w32_on_key_up); break;
|
||||
case WM_KEYDOWN: w32_key_dispatch(wparam, w32_on_key_down); break;
|
||||
default: return DefWindowProcW(wnd, msg, wparam, lparam);
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
|
||||
typedef enum W32_PROCESS_DPI_AWARENESS {
|
||||
W32_PROCESS_DPI_UNAWARE = 0,
|
||||
W32_PROCESS_SYSTEM_DPI_AWARE = 1,
|
||||
W32_PROCESS_PER_MONITOR_DPI_AWARE = 2
|
||||
} W32_PROCESS_DPI_AWARENESS;
|
||||
|
||||
typedef unsigned MU_TimeBeginPeriod(unsigned);
|
||||
typedef HRESULT MU_SetProcessDpiAwareness(W32_PROCESS_DPI_AWARENESS);
|
||||
|
||||
HMODULE shcore = LoadLibraryA("Shcore.dll");
|
||||
if (shcore) {
|
||||
MU_SetProcessDpiAwareness *set_dpi_awr = (MU_SetProcessDpiAwareness *)GetProcAddress(shcore, "SetProcessDpiAwareness");
|
||||
if (set_dpi_awr) {
|
||||
HRESULT hr = set_dpi_awr(W32_PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
assert(SUCCEEDED(hr) && "Failed to set dpi awareness");
|
||||
}
|
||||
}
|
||||
|
||||
HMODULE winmm = LoadLibraryA("winmm.dll");
|
||||
if (winmm) {
|
||||
MU_TimeBeginPeriod *timeBeginPeriod = (MU_TimeBeginPeriod *)GetProcAddress(winmm, "timeBeginPeriod");
|
||||
if (timeBeginPeriod) {
|
||||
if (timeBeginPeriod(1) == 0) {
|
||||
w32_good_scheduling = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WNDCLASSW wc = {0};
|
||||
{
|
||||
wc.lpfnWndProc = w32_window_proc;
|
||||
wc.hInstance = GetModuleHandleW(NULL);
|
||||
wc.lpszClassName = L"HelloClassName";
|
||||
wc.hCursor = LoadCursor(0, IDC_ARROW);
|
||||
wc.hIcon = NULL; // LoadIcon(wc.hInstance, IDI_APPLICATION);
|
||||
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
|
||||
ATOM result = RegisterClassW(&wc);
|
||||
assert(result != 0);
|
||||
w32_wc = wc;
|
||||
}
|
||||
|
||||
RECT window_rect = {0};
|
||||
{
|
||||
window_rect.left = 0;
|
||||
window_rect.right = 1280;
|
||||
window_rect.bottom = 732;
|
||||
window_rect.top = 12;
|
||||
AdjustWindowRectEx(&window_rect, WS_OVERLAPPEDWINDOW, false, 0);
|
||||
}
|
||||
w32_window_handle = CreateWindowW(w32_wc.lpszClassName, L"Zzz... Window, hello!", WS_OVERLAPPEDWINDOW, window_rect.left, window_rect.top, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top, NULL, NULL, hInstance, NULL);
|
||||
assert(w32_window_handle);
|
||||
|
||||
w32_dc = GetDC(w32_window_handle);
|
||||
assert(w32_dc);
|
||||
ShowWindow(w32_window_handle, SW_SHOW);
|
||||
|
||||
// @todo: rebuild on resize
|
||||
// Create a writable backbuffer bitmap
|
||||
uint32_t *mem = 0;
|
||||
BITMAPINFO bminfo = {0};
|
||||
{
|
||||
bminfo.bmiHeader.biSize = sizeof(bminfo.bmiHeader);
|
||||
bminfo.bmiHeader.biWidth = (LONG)1280;
|
||||
bminfo.bmiHeader.biHeight = (LONG)720;
|
||||
bminfo.bmiHeader.biPlanes = 1;
|
||||
bminfo.bmiHeader.biBitCount = 32;
|
||||
bminfo.bmiHeader.biCompression = BI_RGB; // AA RR GG BB
|
||||
bminfo.bmiHeader.biXPelsPerMeter = 1;
|
||||
bminfo.bmiHeader.biYPelsPerMeter = 1;
|
||||
}
|
||||
HBITMAP dib = CreateDIBSection(w32_dc, &bminfo, DIB_RGB_COLORS, (void **)&mem, 0, 0);
|
||||
HDC dib_dc = CreateCompatibleDC(w32_dc);
|
||||
|
||||
for (;;) {
|
||||
MSG msg;
|
||||
if (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||
if (msg.message == WM_QUIT) {
|
||||
break;
|
||||
}
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int y = 0; y < 720; y++) {
|
||||
for (int x = 0; x < 1280; x++) {
|
||||
mem[x + y * 1280] = 0xFFFF0000;
|
||||
}
|
||||
}
|
||||
|
||||
SelectObject(dib_dc, dib);
|
||||
BitBlt(w32_dc, 0, 0, 1280, 720, dib_dc, 0, 0, SRCCOPY);
|
||||
Sleep(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user