commit d9e0c3a

uint  ·  2026-06-22 23:01:19 +0000 UTC
parent ce9b0c9
Implement win32 framebuffer creation, destruction
1 files changed,  +113, -12
+113, -12
  1@@ -3,6 +3,59 @@
  2 #include "maus.h"
  3 #include "maus_win.h"
  4 
  5+static bool fb_create(Maus* mw);
  6+static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
  7+
  8+static bool fb_create(Maus* mw)
  9+{
 10+	MausBackend* be = &mw->backend;
 11+	be->hbm = NULL;
 12+	mw->fb = NULL;
 13+	mw->stride = 0;
 14+
 15+	BITMAPINFO bmi = {0};
 16+	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 17+	bmi.bmiHeader.biWidth = mw->width;
 18+	bmi.bmiHeader.biHeight = -mw->height;
 19+	bmi.bmiHeader.biPlanes = 1;
 20+	bmi.bmiHeader.biBitCount = 32;
 21+	bmi.bmiHeader.biCompression = BI_RGB;
 22+
 23+	HDC dc = GetDC(NULL);
 24+	be->memdc = CreateCompatibleDC(dc);
 25+	be->hbm = CreateDIBSection(dc, &bmi, DIB_RGB_COLORS, (void**)&mw->fb, NULL, 0);
 26+	ReleaseDC(NULL, dc);
 27+
 28+	if (!be->hbm || !mw->fb) {
 29+		if (be->memdc)
 30+			DeleteDC(be->memdc);
 31+		maus_log(stderr, "CreateDIBSection failed");
 32+		return false;
 33+	}
 34+
 35+	SelectObject(be->memdc, be->hbm);
 36+
 37+	mw->stride = mw->width;
 38+	return true;
 39+}
 40+
 41+static void fb_destroy(Maus* mw)
 42+{
 43+	MausBackend* be = &mw->backend;
 44+
 45+	if (be->memdc) {
 46+		DeleteDC(be->memdc);
 47+		be->memdc = NULL;
 48+	}
 49+	if (be->hbm) {
 50+		DeleteObject(be->hbm);
 51+		be->hbm = NULL;
 52+	}
 53+
 54+	mw->fb = NULL;
 55+	mw->stride = 0;
 56+}
 57+
 58 static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
 59 {
 60 	if (msg == WM_DESTROY) {
 61@@ -13,11 +66,31 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
 62 	return DefWindowProc(hwnd, msg, wp, lp);
 63 }
 64 
 65-void maus_clear(Maus* mw, MausColor col);
 66-void maus_clipboard_set_text(Maus* mw, const char* text);
 67-char* maus_clipboard_get_text(Maus* mw);
 68-void maus_close(Maus* mw);
 69-bool maus_close_window(Maus* mw);
 70+void maus_clear(Maus* mw, MausColor col)
 71+{
 72+
 73+}
 74+
 75+void maus_clipboard_set_text(Maus* mw, const char* text)
 76+{
 77+
 78+}
 79+
 80+char* maus_clipboard_get_text(Maus* mw)
 81+{
 82+
 83+}
 84+
 85+void maus_close(Maus* mw)
 86+{
 87+
 88+}
 89+
 90+bool maus_close_window(Maus* mw)
 91+{
 92+
 93+}
 94+
 95 
 96 bool maus_create_window(Maus* mw)
 97 {
 98@@ -54,13 +127,23 @@ bool maus_create_window(Maus* mw)
 99 Maus* maus_init(const char* title, int x, int y, int width, int height)
100 {
101 	Maus* mw = calloc(1, sizeof(Maus));
102+	MausBackend* be = &mw->backend;
103+
104 	mw->frame_time_last = maus_get_time_ns();
105 	mw->title = title;
106 	mw->width = width;
107 	mw->height = height;
108 	mw->x = x;
109 	mw->y = y;
110-	mw->fb = NULL;
111+	be->hInst = GetModuleHandle(NULL);
112+	be->hwnd = NULL;
113+	be->hbm = NULL;
114+
115+	if (!fb_create(mw)) {
116+		maus_log(stderr, "failed to create framebuffer");
117+		free(mw);
118+		return NULL;
119+	}
120 
121 	mw->bfb = calloc(mw->stride * mw->height, sizeof(uint32_t));
122 	if (!mw->bfb) {
123@@ -73,10 +156,28 @@ Maus* maus_init(const char* title, int x, int y, int width, int height)
124 	return mw;
125 }
126 
127-bool maus_event_poll(Maus* mw, MausEvent* ev);
128-void maus_event_wait(Maus* mw, MausEvent* ev);
129-void maus_present(Maus* mw);
130-bool maus_resize(Maus* mw, uint32_t width, uint32_t height);
131-void maus_target_fps(Maus* mw, uint32_t fps);
132-void maus_cur_set_mode(Maus* mw, MausCursorState state);
133+bool maus_event_poll(Maus* mw, MausEvent* ev)
134+{
135+
136+}
137+
138+void maus_event_wait(Maus* mw, MausEvent* ev)
139+{
140+
141+}
142+
143+void maus_present(Maus* mw)
144+{
145+
146+}
147+
148+bool maus_resize(Maus* mw, uint32_t width, uint32_t height)
149+{
150+
151+}
152+
153+void maus_cur_set_mode(Maus* mw, MausCursorState state)
154+{
155+
156+}
157