Hotfixes & try to fix window sizing but fail miserably

This commit is contained in:
Charlie 2024-07-09 19:53:26 +02:00
parent 52f68d5fe2
commit a9cbf7ee68
6 changed files with 37 additions and 21 deletions

View file

@ -6,6 +6,7 @@ ooga booga
- [Quickstart](#quickstart) - [Quickstart](#quickstart)
- [The "Build System"](#the-build-system) - [The "Build System"](#the-build-system)
- [Examples & Documentation](#examples--documentation) - [Examples & Documentation](#examples--documentation)
- [Known bugs](#known-bugs)
- [Licensing](#licensing) - [Licensing](#licensing)
## Getting started ## Getting started
@ -49,6 +50,9 @@ Simply add `#include "oogabooga/examples/some_example.c"` to build.c and compile
Other than examples, a great way to learn is to delve into the code of whatever module you're using. The codebase is written with this in mind. Other than examples, a great way to learn is to delve into the code of whatever module you're using. The codebase is written with this in mind.
## Known bugs
- Window positioning & sizing is fucky wucky
## Licensing ## Licensing
By default, the repository has an educational license that makes the engine free to use for personal projects. By default, the repository has an educational license that makes the engine free to use for personal projects.

View file

@ -134,14 +134,13 @@ Draw_Quad *draw_quad_projected(Draw_Quad quad, Matrix4 world_to_clip) {
quad.bottom_right = m4_transform(world_to_clip, v4(v2_expand(quad.bottom_right), 0, 1)).xy; quad.bottom_right = m4_transform(world_to_clip, v4(v2_expand(quad.bottom_right), 0, 1)).xy;
quad.image_min_filter = GFX_FILTER_MODE_NEAREST; quad.image_min_filter = GFX_FILTER_MODE_NEAREST;
quad.image_min_filter = GFX_FILTER_MODE_NEAREST; quad.image_mag_filter = GFX_FILTER_MODE_NEAREST;
if (!draw_frame.current) { if (!draw_frame.current) {
draw_frame.current = &first_block; draw_frame.current = &first_block;
draw_frame.current->low_z = F32_MAX; draw_frame.current->low_z = F32_MAX;
draw_frame.current->high_z = F32_MIN; draw_frame.current->high_z = F32_MIN;
draw_frame.current->num_quads = 0; draw_frame.current->num_quads = 0;
memset(draw_frame.current->quad_buffer, 0, sizeof(draw_frame.current->quad_buffer)); // #Temporary
draw_frame.num_blocks = 1; draw_frame.num_blocks = 1;
} }

View file

@ -5,7 +5,7 @@ int entry(int argc, char **argv) {
window.scaled_width = 1280; // We need to set the scaled size if we want to handle system scaling (DPI) window.scaled_width = 1280; // We need to set the scaled size if we want to handle system scaling (DPI)
window.scaled_height = 720; window.scaled_height = 720;
window.x = 200; window.x = 200;
window.y = 200; window.y = 90;
window.clear_color = hex_to_rgba(0x6495EDff); window.clear_color = hex_to_rgba(0x6495EDff);
while (!window.should_close) { while (!window.should_close) {

View file

@ -3,8 +3,8 @@
int entry(int argc, char **argv) { int entry(int argc, char **argv) {
window.title = STR("My epic game"); window.title = STR("My epic game");
window.width = 1280; window.scaled_width = 1280;
window.height = 720; window.scaled_height = 720;
window.x = 200; window.x = 200;
window.y = 200; window.y = 200;
@ -56,11 +56,10 @@ int entry(int argc, char **argv) {
} }
if (is_key_just_pressed(KEY_ARROW_LEFT)) { if (is_key_just_pressed(KEY_ARROW_LEFT)) {
window.scaled_width += 10;
window.x -= 10; window.x -= 10;
} }
if (is_key_just_pressed(KEY_ARROW_RIGHT)) { if (is_key_just_pressed(KEY_ARROW_RIGHT)) {
window.scaled_width += 10; window.x += 10;
} }
if (is_key_just_released('Q')) { if (is_key_just_released('Q')) {

View file

@ -566,7 +566,6 @@ void d3d11_process_draw_frame() {
log_verbose("Grew quad vbo to %d bytes.", d3d11_quad_vbo_size); log_verbose("Grew quad vbo to %d bytes.", d3d11_quad_vbo_size);
} }
memset(d3d11_staging_quad_buffer, 0, d3d11_quad_vbo_size);// #Temporary
if (draw_frame.num_blocks > 0) { if (draw_frame.num_blocks > 0) {
/// ///

View file

@ -966,8 +966,8 @@ void os_update() {
} }
if (last_window.scaled_width != window.scaled_width || last_window.scaled_height != window.scaled_height) { if (last_window.scaled_width != window.scaled_width || last_window.scaled_height != window.scaled_height) {
window.width = window.scaled_width/dpi_scale_factor; window.width = window.scaled_width*dpi_scale_factor;
window.height = window.scaled_height/dpi_scale_factor; window.height = window.scaled_height*dpi_scale_factor;
} }
BOOL ok; BOOL ok;
@ -984,10 +984,10 @@ void os_update() {
BOOL ok = AdjustWindowRectEx(&update_rect, style, FALSE, ex_style); BOOL ok = AdjustWindowRectEx(&update_rect, style, FALSE, ex_style);
assert(ok != 0, "AdjustWindowRectEx failed with error code %lu", GetLastError()); assert(ok != 0, "AdjustWindowRectEx failed with error code %lu", GetLastError());
u32 actual_x = update_rect.left;
u32 actual_y = screen_height - update_rect.top - window.height;
u32 actual_width = update_rect.right - update_rect.left; u32 actual_width = update_rect.right - update_rect.left;
u32 actual_height = update_rect.bottom - update_rect.top; u32 actual_height = update_rect.bottom - update_rect.top;
u32 actual_x = update_rect.left;
u32 actual_y = screen_height - update_rect.top - (update_rect.bottom - update_rect.top);
SetWindowPos(window._os_handle, NULL, actual_x, actual_y, actual_width, actual_height, SWP_NOZORDER | SWP_NOACTIVATE); SetWindowPos(window._os_handle, NULL, actual_x, actual_y, actual_width, actual_height, SWP_NOZORDER | SWP_NOACTIVATE);
} }
@ -996,28 +996,43 @@ void os_update() {
ok = GetClientRect(window._os_handle, &client_rect); ok = GetClientRect(window._os_handle, &client_rect);
assert(ok, "GetClientRect failed with error code %lu", GetLastError()); assert(ok, "GetClientRect failed with error code %lu", GetLastError());
// Convert the client area rectangle top-left corner to screen coordinates RECT adjusted_rect = client_rect;
ok = AdjustWindowRectEx(&adjusted_rect, style, FALSE, ex_style);
assert(ok != 0, "AdjustWindowRectEx failed with error code %lu", GetLastError());
RECT window_rect;
ok = GetWindowRect(window._os_handle, &window_rect);
assert(ok, "GetWindowRect failed with error code %lu", GetLastError());
/*u32 style_space_left = abs(client_rect.left-adjusted_rect.left);
u32 style_space_right = abs(client_rect.left-adjusted_rect.right);
u32 style_space_bottom = abs(client_rect.left-adjusted_rect.bottom);
u32 style_space_top = abs(client_rect.left-adjusted_rect.top);
framebuffer_rect.left += style_space_left;
framebuffer_rect.right -= style_space_right;
framebuffer_rect.top += style_space_top;
framebuffer_rect.bottom -= style_space_bottom;*/
POINT top_left; POINT top_left;
top_left.x = client_rect.left; top_left.x = client_rect.left;
top_left.y = client_rect.top; top_left.y = client_rect.top;
ok = ClientToScreen(window._os_handle, &top_left); ok = ClientToScreen(window._os_handle, &top_left);
assert(ok, "ClientToScreen failed with error code %lu", GetLastError()); assert(ok, "ClientToScreen failed with error code %lu", GetLastError());
// Convert the client area rectangle bottom-right corner to screen coordinates
POINT bottom_right; POINT bottom_right;
bottom_right.x = client_rect.right; bottom_right.x = client_rect.right;
bottom_right.y = client_rect.bottom; bottom_right.y = client_rect.bottom;
ok = ClientToScreen(window._os_handle, &bottom_right); ok = ClientToScreen(window._os_handle, &bottom_right);
assert(ok, "ClientToScreen failed with error code %lu", GetLastError()); assert(ok, "ClientToScreen failed with error code %lu", GetLastError());
window.x = (u32)top_left.x; window.pixel_width = (u32)(bottom_right.x - top_left.x);
window.y = (u32)(screen_height-bottom_right.y); window.pixel_height = (u32)(bottom_right.y - top_left.y);
window.pixel_width = (u32)(client_rect.right - client_rect.left); window.x = (u32)window_rect.left;
window.pixel_height = (u32)(client_rect.bottom - client_rect.top); window.y = screen_height-window_rect.bottom;
window.scaled_width = (u32)((client_rect.right - client_rect.left) * dpi_scale_factor); window.scaled_width = (u32)((bottom_right.x - top_left.x) * dpi_scale_factor);
window.scaled_height = (u32)((client_rect.bottom - client_rect.top) * dpi_scale_factor); window.scaled_height = (u32)((bottom_right.y - top_left.y) * dpi_scale_factor);
last_window = window; last_window = window;