From 5ff767e916c3854486977a0ef317c357283bfc74 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 8 May 2025 20:48:12 +1000 Subject: [PATCH] pattermon rendered (many things to rework/fix) --- src/game.c | 14 +++++++++----- src/game.h | 4 ++-- src/shaders/glsl/gui.frag.glsl | 5 ++++- src/shaders/glsl/gui.vert.glsl | 6 ++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/game.c b/src/game.c index 7bc8df2..98e32ce 100644 --- a/src/game.c +++ b/src/game.c @@ -59,6 +59,7 @@ static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count) gHandleInputs(inputs, i_count); + /* if (gButton(ctx, "Show 2", 150.0f, 150.0f, 200.0f, 200.0f)) { gWindow(ctx, "Window 2", 500.0f, 500.0f, 600.0f, 600.0f); @@ -73,12 +74,14 @@ static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count) { gWindow(ctx, "Window 3", 250.0f, 500.0f, 400.0f, 650.0f); } - + */ rViewportSize(&ctx->pc.res); rDescHandle pattermon = rTextureCreateAndUpload(PATTERMON_OBESE); + gWindow(ctx, "Pattermon", 100.0f, 100.0f, 300.0f, 300.0f, pattermon); + rawptr vert_buffer = rBufferGUIVertMapping(); rawptr idx_buffer = rBufferGUIIdxMapping(); @@ -226,12 +229,12 @@ static b32 gButton(gGameCtx *ctx, char *label, f32 x0, f32 y0, f32 x1, f32 y1) btn->pressed = !btn->pressed; } - gRect(&ctx->gui, btn->p0, btn->p1, (Vec4){ .r = 0.1f, .g = 0.9f, .b = 0.4f, .a = 1.0f }); + //gRect(&ctx->gui, btn->p0, btn->p1, (Vec4){ .r = 0.1f, .g = 0.9f, .b = 0.4f, .a = 1.0f }); return btn->pressed; } -static b32 gWindow(gGameCtx *ctx, char *title, f32 x0, f32 y0, f32 x1, f32 y1) +static b32 gWindow(gGameCtx *ctx, char *title, f32 x0, f32 y0, f32 x1, f32 y1, rDescHandle handle) { gWindowWidget *win = NULL; u32 id = HashFromString(String8CStr(title)); @@ -306,17 +309,18 @@ static b32 gWindow(gGameCtx *ctx, char *title, f32 x0, f32 y0, f32 x1, f32 y1) ctx->gui.has_grabbed = true; } - gRect(&ctx->gui, win->p0, win->p1, (Vec4){ .r = 0.1f, .g = 0.3f, .b = 0.8f, .a = 1.0f }); + gRect(&ctx->gui, win->p0, win->p1, (Vec4){ .r = 0.1f, .g = 0.3f, .b = 0.8f, .a = 1.0f }, handle); return true; } -static void gRect(gUICtx *ctx, Vec2 p0, Vec2 p1, Vec4 col) +static void gRect(gUICtx *ctx, Vec2 p0, Vec2 p1, Vec4 col, rDescHandle handle) { ctx->vertices[ctx->vertices_len].p0 = p0; ctx->vertices[ctx->vertices_len].p1 = p1; ctx->vertices[ctx->vertices_len].col = col; + ctx->vertices[ctx->vertices_len].tex_idx = handle.desc_index; ctx->vertices_len += 1; diff --git a/src/game.h b/src/game.h index c096451..9d2599c 100644 --- a/src/game.h +++ b/src/game.h @@ -57,6 +57,6 @@ static void gHandleInputs(pGameInput *inputs, u32 count); // ::Game::GUI::Functions::Header:: static inline void gPrepareGUICtx(gGameCtx *ctx); -static void gRect(gUICtx *ctx, Vec2 p0, Vec2 p1, Vec4 col); -static b32 gWindow(gGameCtx *ctx, c8 *title, f32 x0, f32 y0, f32 x1, f32 y1); +static void gRect(gUICtx *ctx, Vec2 p0, Vec2 p1, Vec4 col, rDescHandle handle); +static b32 gWindow(gGameCtx *ctx, c8 *title, f32 x0, f32 y0, f32 x1, f32 y1, rDescHandle handle); static b32 gButton(gGameCtx *ctx, c8 *label, f32 x0, f32 y0, f32 x1, f32 y1); diff --git a/src/shaders/glsl/gui.frag.glsl b/src/shaders/glsl/gui.frag.glsl index dbc5066..ca4247e 100644 --- a/src/shaders/glsl/gui.frag.glsl +++ b/src/shaders/glsl/gui.frag.glsl @@ -2,14 +2,17 @@ #extension GL_EXT_buffer_reference : require #extension GL_GOOGLE_include_directive : require +#extension GL_EXT_nonuniform_qualifier : require #include "structures.glsl" layout (location = 0) in vec4 in_color; +layout (location = 1) in vec2 in_uv; +layout (location = 2) flat in uint in_image; layout (location = 0) out vec4 out_frag_col; void main() { - out_frag_col = in_color; + out_frag_col = texture(sampler2D(Textures[in_image], SamplerNearest), in_uv); } diff --git a/src/shaders/glsl/gui.vert.glsl b/src/shaders/glsl/gui.vert.glsl index e9164a7..8cf57e8 100644 --- a/src/shaders/glsl/gui.vert.glsl +++ b/src/shaders/glsl/gui.vert.glsl @@ -2,6 +2,7 @@ #extension GL_EXT_buffer_reference : require #extension GL_GOOGLE_include_directive : require +#extension GL_EXT_nonuniform_qualifier : require #include "structures.glsl" @@ -11,6 +12,8 @@ layout (location = 2) in vec4 in_col; layout (location = 3) in uint in_image; layout (location = 0) out vec4 out_color; +layout (location = 1) out vec2 out_uv; +layout (location = 2) out uint out_image; void main() { @@ -20,7 +23,10 @@ void main() gl_VertexIndex == 2 ? vec2(in_gui_pos_1.x, in_gui_pos_1.y) : gl_VertexIndex == 3 ? vec2(in_gui_pos_1.x, in_gui_pos_0.y) : vec2(0.0, 0.0); + out_uv = vec2(2 * dst_pos.x / PC.res.x - 1, 2 * dst_pos.y / PC.res.y - 1); out_color = in_col; + out_image = in_image; + gl_Position = vec4(2 * dst_pos.x / PC.res.x - 1, 2 * dst_pos.y / PC.res.y - 1, 0,