win32 drawing text

This commit is contained in:
Krzosa Karol
2025-01-08 09:34:53 +01:00
parent 7c282bacb2
commit 189902dae6
17 changed files with 11794 additions and 46 deletions

View File

@@ -1,15 +1,15 @@
#include "core/core_inc.h"
#include "app.gen.h"
#include "core/core_inc.c"
#include "app.gen.c"
#include "app_win32_opengl.c"
#include "glad/glad.h"
#include "glad/glad.c"
#pragma comment(linker, "/subsystem:windows")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "winmm.lib")
fn void app_init(void);
fn b32 app_update(app_event_list_t events);
gb b32 w32_good_scheduling;
gb WNDCLASSW w32_wc;
gb HWND w32_window_handle;
@@ -179,12 +179,17 @@ fn LRESULT CALLBACK w32_window_proc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lp
return 0;
}
app_event_list_t w32_get_events(ma_arena_t *arena, b32 wait) {
app_event_list_t w32_get_events(ma_arena_t *arena, b32 wait, b32 *waited) {
w32_event_arena = arena;
zero_struct(&w32_event_list);
*waited = false;
MSG msg;
if (wait) {
if (PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE) == 0) {
*waited = true;
}
GetMessageW(&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessageW(&msg);
@@ -331,7 +336,13 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
ShowWindow(w32_window_handle, SW_SHOW);
}
// w32_canvas_t canvas = w32_create_canvas(w32_window_handle);
if (!gladLoadGLLoader((GLADloadproc)w32_load_opengl_fn)) {
fatalf("couldn't load opengl!");
}
if (wglSwapIntervalEXT) {
wglSwapIntervalEXT(1); // vsync
}
f64 refresh_rate = 60;
DEVMODEW devmodew = {0};
@@ -339,16 +350,23 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
refresh_rate = (f64)devmodew.dmDisplayFrequency;
}
app_init();
f64 time_frame_start = w32_seconds_now();
f64 time_delta = 1.0 / refresh_rate;
f64 time_total = 0.0;
f64 time_update = 0.0;
b32 wait_for_events = false;
u64 consecutive_missed_frames = 0;
u64 missed_frames = 0;
u64 frame = 0;
for (;;) {
app_event_list_t event_list = w32_get_events(tcx.temp, false);
b32 waited_for_events = false;
app_event_list_t event_list = w32_get_events(tcx.temp, wait_for_events, &waited_for_events);
if (waited_for_events) {
// delta_time = 0.0001
}
for (app_event_t *ev = event_list.first; ev; ev = ev->next) {
if (ev->kind == app_event_kind_key_down && ev->key == app_key_escape) {
@@ -356,18 +374,15 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
}
}
// w32_try_resizing_canvas(&canvas, w32_window_handle);
// debugf("time_update: %f", time_update);
#if 0
for (i32 y = 0; y < canvas.window_size.y; y++) {
for (i32 x = 0; x < canvas.window_size.x; x++) {
canvas.memory[x + y * (int)canvas.window_size.x] = 0xFFFF0000;
}
if (event_list.len == 0) {
w32_push_event((app_event_t){.kind = app_event_kind_update});
event_list = w32_event_list;
}
#endif
// w32_present_canvas(&canvas);
b32 animating = app_update(event_list);
wait_for_events = !animating;
SwapBuffers(w32_dc);
ma_set0(tcx.temp);
///////////////////////////////
@@ -378,7 +393,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
if (time_update < time_delta) {
consecutive_missed_frames = 0;
// @todo: we are currently busy looping when we don't get the good schduling
// @todo: we are currently busy looping when we don't get the good scheduling
// is that actually a good tactic??
if (w32_good_scheduling) {
f64 time_to_sleep = time_delta - time_update;