diff options
| author | kkard2 <[email protected]> | 2025-09-21 14:09:45 +0200 |
|---|---|---|
| committer | kkard2 <[email protected]> | 2025-09-21 14:09:45 +0200 |
| commit | 9463e07e2813cea94b9fd430b2fad938cad82673 (patch) | |
| tree | 9791406e72f3b266d023390c6ead8baa45db647a /platform_win32.c | |
| parent | 7ce5bb498bfe95a912f690e9d17c148114f02de0 (diff) | |
add perspective matrix and mesh drawing
Diffstat (limited to 'platform_win32.c')
| -rw-r--r-- | platform_win32.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/platform_win32.c b/platform_win32.c index a8facc4..b8bb4b3 100644 --- a/platform_win32.c +++ b/platform_win32.c @@ -22,16 +22,23 @@ static size_t pixels_buffer_count; static sponge_Texture canvas; +static float *depths; static BITMAPINFO bmi; -int update_canvas(sponge_Texture *canvas, uint32_t new_width, uint32_t new_height) { +int update_canvas(sponge_Texture *canvas, float **depths, uint32_t new_width, uint32_t new_height) { size_t new_count = new_width * new_height; if (new_count > pixels_buffer_count) { sponge_Color32 *new_pixels_buffer = malloc(new_count * sizeof(uint32_t)); - if (!new_pixels_buffer) + float *new_depths = malloc(new_count * sizeof(float)); + if (!new_pixels_buffer || !new_depths) { + free(new_pixels_buffer); + free(new_pixels_buffer); return 0; + } free(canvas->pixels); + free(*depths); canvas->pixels = new_pixels_buffer; + *depths = new_depths; pixels_buffer_count = new_count; } canvas->width = new_width; @@ -73,7 +80,7 @@ LRESULT __stdcall WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) uint32_t width = LOWORD(lParam); uint32_t height = HIWORD(lParam); // TODO(kard): handle properly? (what does that even mean) - assert(update_canvas(&canvas, width, height)); + assert(update_canvas(&canvas, &depths, width, height)); } case WM_MOUSEMOVE: { int32_t x = GET_X_LPARAM(lParam); @@ -118,7 +125,7 @@ int __stdcall WinMain( if (hwnd == NULL) return 1; - update_canvas(&canvas, DEFAULT_WIDTH, DEFAULT_HEIGHT); + update_canvas(&canvas, &depths, DEFAULT_WIDTH, DEFAULT_HEIGHT); ShowWindow(hwnd, nShowCmd); @@ -154,7 +161,7 @@ int __stdcall WinMain( if (!running) break; if (sponge_texture_valid(canvas)) - draw_frame(canvas); + draw_frame_3d(canvas, depths); QueryPerformanceCounter(&qpc_end); qpc_draw.QuadPart = qpc_end.QuadPart - qpc_start.QuadPart; |
