From 222b68c0a30585ae1615aca83e980ee1fb6ebf6f Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Wed, 31 Jul 2024 01:12:45 +0300 Subject: [PATCH] flickering fixed ! --- apps/testgame/scenes/ingame.c | 4 ++-- src/main.c | 4 ++-- src/rendering.c | 2 +- src/rendering/internal_api.h | 1 + src/rendering/triangles.h | 4 +--- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/testgame/scenes/ingame.c b/apps/testgame/scenes/ingame.c index d4fc1d3..37fc972 100644 --- a/apps/testgame/scenes/ingame.c +++ b/apps/testgame/scenes/ingame.c @@ -77,8 +77,8 @@ static void ingame_tick(struct state *state) { set_camera(&cam); - for (int y = 64; --y;) - for (int x = 64; --x;) { + for (int y = 64; y--;) + for (int x = 64; x--;) { float d0 = sample_perlin_2d((t_fvec2){x, y}, 0.2, 5) * 8 - 6; float d1 = sample_perlin_2d((t_fvec2){x + 1, y}, 0.2, 5) * 8 - 6; float d2 = sample_perlin_2d((t_fvec2){x + 1, y - 1}, 0.2, 5) * 8 - 6; diff --git a/src/main.c b/src/main.c index b822438..82eb017 100644 --- a/src/main.c +++ b/src/main.c @@ -162,10 +162,10 @@ static void main_loop(void) { ctx.frame_accumulator -= ctx.desired_frametime; ctx.tick_count = (ctx.tick_count % ULLONG_MAX) + 1; + + render(); } } - - render(); } diff --git a/src/rendering.c b/src/rendering.c index 1148d29..470fd58 100644 --- a/src/rendering.c +++ b/src/rendering.c @@ -121,7 +121,7 @@ static void render_space(void) { glActiveTexture(GL_TEXTURE0); /* solid white, no modulation */ - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glColor4ub(255, 255, 255, 255); for (size_t i = 0; i < hmlenu(ctx.uncolored_mesh_batches); ++i) { draw_uncolored_space_traingle_batch(&ctx.uncolored_mesh_batches[i].value, diff --git a/src/rendering/internal_api.h b/src/rendering/internal_api.h index b3c8b03..358e5b5 100644 --- a/src/rendering/internal_api.h +++ b/src/rendering/internal_api.h @@ -57,6 +57,7 @@ union uncolored_space_triangle { t_fvec2 uv2; /* in pixels */ } primitive; + /* TODO: have it packed? */ /* structure that is passed in opengl vertex array */ struct uncolored_space_triangle_payload { t_fvec3 v0; diff --git a/src/rendering/triangles.h b/src/rendering/triangles.h index d3ebefc..5ed2de6 100644 --- a/src/rendering/triangles.h +++ b/src/rendering/triangles.h @@ -67,8 +67,6 @@ static void draw_uncolored_space_traingle_batch(struct mesh_batch *batch, const t_frect srcrect = textures_get_srcrect(&ctx.texture_cache, texture_key); const t_frect dims = textures_get_dims(&ctx.texture_cache, texture_key); - /* TODO: fast path for uvs mapped directly on srcrect corners? */ - const float wr = srcrect.w / dims.w; const float hr = srcrect.h / dims.h; const float xr = srcrect.x / dims.w; @@ -107,7 +105,7 @@ static void draw_uncolored_space_traingle_batch(struct mesh_batch *batch, (void *)offsetof(struct uncolored_space_triangle_payload, uv0)); /* commit for drawing */ - glDrawArrays(GL_TRIANGLES, 0, 3 * (int)primitives_len); + glDrawArrays(GL_TRIANGLES, 0, 3 * (GLint)primitives_len); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);