flickering fixed !

This commit is contained in:
veclav talica 2024-07-31 01:12:45 +03:00
parent b7eae98d0d
commit 222b68c0a3
5 changed files with 7 additions and 8 deletions

View File

@ -77,8 +77,8 @@ static void ingame_tick(struct state *state) {
set_camera(&cam); set_camera(&cam);
for (int y = 64; --y;) for (int y = 64; y--;)
for (int x = 64; --x;) { for (int x = 64; x--;) {
float d0 = sample_perlin_2d((t_fvec2){x, y}, 0.2, 5) * 8 - 6; 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 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; float d2 = sample_perlin_2d((t_fvec2){x + 1, y - 1}, 0.2, 5) * 8 - 6;

View File

@ -162,10 +162,10 @@ static void main_loop(void) {
ctx.frame_accumulator -= ctx.desired_frametime; ctx.frame_accumulator -= ctx.desired_frametime;
ctx.tick_count = (ctx.tick_count % ULLONG_MAX) + 1; ctx.tick_count = (ctx.tick_count % ULLONG_MAX) + 1;
render();
} }
} }
render();
} }

View File

@ -121,7 +121,7 @@ static void render_space(void) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
/* solid white, no modulation */ /* 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) { for (size_t i = 0; i < hmlenu(ctx.uncolored_mesh_batches); ++i) {
draw_uncolored_space_traingle_batch(&ctx.uncolored_mesh_batches[i].value, draw_uncolored_space_traingle_batch(&ctx.uncolored_mesh_batches[i].value,

View File

@ -57,6 +57,7 @@ union uncolored_space_triangle {
t_fvec2 uv2; /* in pixels */ t_fvec2 uv2; /* in pixels */
} primitive; } primitive;
/* TODO: have it packed? */
/* structure that is passed in opengl vertex array */ /* structure that is passed in opengl vertex array */
struct uncolored_space_triangle_payload { struct uncolored_space_triangle_payload {
t_fvec3 v0; t_fvec3 v0;

View File

@ -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 srcrect = textures_get_srcrect(&ctx.texture_cache, texture_key);
const t_frect dims = textures_get_dims(&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 wr = srcrect.w / dims.w;
const float hr = srcrect.h / dims.h; const float hr = srcrect.h / dims.h;
const float xr = srcrect.x / dims.w; 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)); (void *)offsetof(struct uncolored_space_triangle_payload, uv0));
/* commit for drawing */ /* 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_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);