From 07442b35158cd7de03315a17694f3f3026207960 Mon Sep 17 00:00:00 2001 From: 0undefined Date: Tue, 11 Nov 2025 00:21:42 +0100 Subject: Quad & IBO tests --- resources/quad.frag | 14 ++++++++------ resources/quad.vert | 13 ++++++++----- state_mainstate/src/mainstate.c | 17 ++++++++++++++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/resources/quad.frag b/resources/quad.frag index 3e85ecf..73869cb 100644 --- a/resources/quad.frag +++ b/resources/quad.frag @@ -1,13 +1,15 @@ #version 330 core -in vec3 fragColor; +in vec2 UV; -out vec4 color; +out vec3 color; -//uniform sampler2D textureSampler; +uniform sampler2D textureSampler; void main() { - color.x = fragColor.x; - color.y = fragColor.y; - color.z = fragColor.z; + vec3 c = texture(textureSampler, UV).rgb; + color = vec3( + c.x / 2 + UV.x / 2, + c.y / 2 + UV.y / 2, + c.z); } diff --git a/resources/quad.vert b/resources/quad.vert index f73ad12..3365748 100644 --- a/resources/quad.vert +++ b/resources/quad.vert @@ -1,18 +1,21 @@ #version 330 core layout(location = 0) in vec2 pos; +layout(location = 1) in vec2 uv; -out vec3 fragColor; +out vec2 UV; uniform mat4 MVP; void main() { gl_Position = - MVP * vec4( pos.x, 1, pos.y, 1); + MVP * + vec4( pos.x, 1, pos.y, 1); + UV = uv; //vec4(pos.x, 1.0, pos.y, 1.0); - fragColor.x = gl_Position.x; - fragColor.y = gl_Position.y; - fragColor.z = gl_Position.z; + //fragColor.x = gl_Position.x; + //fragColor.y = gl_Position.y; + //fragColor.z = gl_Position.z; } diff --git a/state_mainstate/src/mainstate.c b/state_mainstate/src/mainstate.c index eea1f18..2f22ed3 100644 --- a/state_mainstate/src/mainstate.c +++ b/state_mainstate/src/mainstate.c @@ -25,6 +25,7 @@ enum GameResources { MyDitherFragShader, MyDitherShader, MyTexture, + MyQuadTexture, MyGrass, MyStone, @@ -53,6 +54,7 @@ static f32 crate_normals[36*3]; // TODO: Fix rendering positions on models with IBOs static f32 quad[8]; static u16 quad_ibo[6]; +static f32 quad_uv[8]; #define COUNT(a) sizeof(a) / sizeof(a[0]) /* this is an unfortunate way of declaring this, unfortunately we _really_ don't @@ -72,8 +74,9 @@ ShaderBuffer shaderbuf2[] = { SHADERBUFFER_NEW(f32, COUNT(crate_normals), 3, crate_normals, staticdraw), }; ShaderBuffer shaderbuf_quad[] = { - SHADERBUFFER_NEW(f32, COUNT(quad), 2, quad, staticdraw | ShaderBuffer_Type_vertexPosition), - SHADERBUFFER_NEW(u16, COUNT(quad_ibo), 3, quad_ibo, staticdraw | ShaderBuffer_Type_vertexIndex), + SHADERBUFFER_NEW(f32, COUNT(quad), 2, quad, staticdraw | ShaderBuffer_Type_vertexPosition), + SHADERBUFFER_NEW(f32, COUNT(quad_uv), 2, quad_uv, staticdraw), + SHADERBUFFER_NEW(u16, COUNT(quad_ibo), 3, quad_ibo, staticdraw | ShaderBuffer_Type_vertexIndex), }; #undef COUNT @@ -194,6 +197,7 @@ void mainstate_init(mainstate_state *state, void* arg) { [MyDitherShader] = Declare_ShaderProgram( dither_shader, sizeof(dither_shader) / sizeof(dither_shader[0])), [MyTexture] = Declare_Texture("resources/atlas.png"), + [MyQuadTexture] = Declare_Texture("resources/quad.png"), [MyGrass] = Declare_Texture("resources/grass.png"), [MyStone] = Declare_Texture("resources/stone.png"), @@ -277,7 +281,7 @@ void mainstate_init(mainstate_state *state, void* arg) { exit(EXIT_FAILURE); } - gen_terrain(state->world, WORLD_HEIGHT, WORLD_LENGTH, WORLD_WIDTH); + gen_terrain(state->world, WORLD_HEIGHT/2, WORLD_LENGTH, WORLD_WIDTH); for (isize i = 0; i < WORLD_SIZE; i++) { if (state->world[i] == BLOCK_none) continue; @@ -433,6 +437,13 @@ static u16 quad_ibo[] = { 2, 3, 0, }; +static f32 quad_uv[] = { + 0.f, 0.f, + 1.f, 0.f, + 1.f, 1.f, + 0.f, 1.f, +}; + static f32 crate_texture_coords[] = { // BEHIND 0 49.f*px, 1.0f, -- cgit v1.3