From b5f0f9119d5daa56f4f84a06c76dd3a40ac8a75c Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Thu, 15 Aug 2024 23:45:30 -0400 Subject: [PATCH] Inverted sky --- haloo3d | 2 +- scene.c | 12 +++++++----- scene_freecam.c | 24 +++++++++++++++--------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/haloo3d b/haloo3d index d19e5e7..cca7ec4 160000 --- a/haloo3d +++ b/haloo3d @@ -1 +1 @@ -Subproject commit d19e5e7fbd3b1024c178f0c1c575ecb16625ffcb +Subproject commit cca7ec456909732e051a00aef5319dd452955299 diff --git a/scene.c b/scene.c index a83bc8b..7a767ff 100644 --- a/scene.c +++ b/scene.c @@ -73,10 +73,12 @@ int main(int argc, char **argv) { haloo3d_fb textures[NUMOBJECTS]; haloo3d_obj_loadfile(models, argv[1]); haloo3d_img_loadppmfile(textures, argv[2]); - haloo3d_gen_1pxgradient(textures + 1, 0xF44F, 0xF001, 32); + haloo3d_fb_init_tex(textures + 1, 32, 32); + haloo3d_apply_vgradient(textures + 1, 0xF001, 0xF44F); haloo3d_gen_skybox(models + 1); uint16_t checkcols[2] = {0xF0A0, 0xF270}; - haloo3d_gen_checkerboard(textures + 2, checkcols, 2, 32); + haloo3d_fb_init_tex(textures + 2, 32, 32); + haloo3d_apply_alternating(textures + 2, checkcols, 2); haloo3d_gen_sloped(models + 2, PLANESIZE, 1.0, 1.25); haloo3d_fb_init_tex(textures + 3, 8, 8); memcpy(textures[3].buffer, redflower, sizeof(uint16_t) * 64); @@ -111,7 +113,7 @@ int main(int argc, char **argv) { } else { // Setup the flowers haloo3d_objin_init(objects + i, models + FLOWERIND, textures + FLOWERIND); objects[i].cullbackface = 0; - objects[i].scale = 0.5; + vec3(objects[i].scale.v, 0.5, 0.5, 0.5); int rvi = rand() % models[2].numvertices; vec3_assign(objects[i].pos.v, models[2].vertices[rvi].v); objects[i].pos.y += 0.5; @@ -124,7 +126,7 @@ int main(int argc, char **argv) { objects[2].lighting = &light; #endif objects[0].pos.y = 1; - objects[1].scale = SKYSCALE; + vec3(objects[1].scale.v, SKYSCALE, SKYSCALE, SKYSCALE); // Now we create a framebuffer to draw the triangle into haloo3d_fb fb; @@ -205,7 +207,7 @@ int main(int argc, char **argv) { // Setup final model matrix and the precalced vertices vec3_add(tmp1.v, objects[i].pos.v, objects[i].lookvec.v); haloo3d_my_lookat(matrixmodel, objects[i].pos.v, tmp1.v, camera.up.v); - haloo3d_mat4_scale(matrixmodel, objects[i].scale); + haloo3d_mat4_scalev(matrixmodel, objects[i].scale.v); mat4_multiply(matrix3d, matrixscreen, matrixmodel); haloo3d_precalc_verts(objects[i].model, matrix3d, vert_precalc); rendersettings.texture = objects[i].texture; diff --git a/scene_freecam.c b/scene_freecam.c index c8ed4dd..04618fd 100644 --- a/scene_freecam.c +++ b/scene_freecam.c @@ -71,10 +71,12 @@ int main(int argc, char **argv) { haloo3d_fb textures[NUMOBJECTS]; haloo3d_obj_loadfile(models, argv[1]); haloo3d_img_loadppmfile(textures, argv[2]); - haloo3d_gen_1pxgradient(textures + 1, 0xF44F, 0xF001, 32); + haloo3d_fb_init_tex(textures + 1, 32, 32); + haloo3d_apply_vgradient(textures + 1, 0xF001, 0xF44F); haloo3d_gen_skybox(models + 1); uint16_t checkcols[2] = {0xF0A0, 0xF270}; - haloo3d_gen_checkerboard(textures + 2, checkcols, 2, 32); + haloo3d_fb_init_tex(textures + 2, 32, 32); + haloo3d_apply_alternating(textures + 2, checkcols, 2); haloo3d_gen_sloped(models + 2, PLANESIZE, 1.0, 1.25); haloo3d_fb_init_tex(textures + 3, 8, 8); memcpy(textures[3].buffer, redflower, sizeof(uint16_t) * 64); @@ -112,7 +114,7 @@ int main(int argc, char **argv) { } else { // Setup the flowers haloo3d_objin_init(objects + i, models + FLOWERIND, textures + FLOWERIND); objects[i].cullbackface = 0; - objects[i].scale = 0.5; + vec3(objects[i].scale.v, 0.5, 0.5, 0.5); int rvi = rand() % models[2].numvertices; vec3_assign(objects[i].pos.v, models[2].vertices[rvi].v); objects[i].pos.y += 0.5; @@ -125,7 +127,7 @@ int main(int argc, char **argv) { objects[2].lighting = &light; #endif objects[0].pos.y = 1; - objects[1].scale = SKYSCALE; + vec3(objects[1].scale.v, SKYSCALE, SKYSCALE, SKYSCALE); // Now we create a framebuffer to draw the triangle into haloo3d_fb fb; @@ -158,6 +160,9 @@ int main(int argc, char **argv) { float msperframe = 1000.0 / TARGETFPS; int totaldrawn = 0; + haloo3d_trirender rendersettings; + haloo3d_trirender_init(&rendersettings); + eprintf("Scene has %d tris, %d verts\n", totalfaces, totalverts); // Init unigi system @@ -192,7 +197,7 @@ int main(int argc, char **argv) { case unigi_enum_event_input_mouse_move: camera.yaw += ROTSPEED * event.data.input_mouse_move.rel_x; camera.pitch += ROTSPEED * event.data.input_mouse_move.rel_y; - CLAMP(camera.pitch, LOOKLOCK, MPI - LOOKLOCK); + camera.pitch = CLAMP(camera.pitch, LOOKLOCK, MPI - LOOKLOCK); break; case unigi_enum_event_input_mouse_button: mouseheld[event.data.input_mouse_button.button] = @@ -233,7 +238,7 @@ int main(int argc, char **argv) { // Setup final model matrix and the precalced vertices vec3_add(tmp1.v, objects[i].pos.v, objects[i].lookvec.v); haloo3d_my_lookat(matrixmodel, objects[i].pos.v, tmp1.v, camera.up.v); - haloo3d_mat4_scale(matrixmodel, objects[i].scale); + haloo3d_mat4_scalev(matrixmodel, objects[i].scale.v); mat4_multiply(matrix3d, matrixscreen, matrixmodel); haloo3d_precalc_verts(objects[i].model, matrix3d, vert_precalc); // Iterate over object faces @@ -242,22 +247,23 @@ int main(int argc, char **argv) { haloo3d_make_facef(objects[i].model->faces[fi], vert_precalc, objects[i].model->vtexture, face); int tris = haloo3d_facef_clip(face, outfaces); + rendersettings.texture = objects[i].texture; for (int ti = 0; ti < tris; ti++) { int backface = !haloo3d_facef_finalize(outfaces[ti]); if (objects[i].cullbackface && backface) { continue; } totaldrawn++; - mfloat_t intensity = 1.0; + rendersettings.intensity = 1.0; if (objects[i].lighting) { haloo3d_obj_facef(objects[i].model, objects[i].model->faces[fi], baseface); - intensity = + rendersettings.intensity = haloo3d_calc_light(objects[i].lighting->v, MINLIGHT, baseface); } // We still have to convert the points into the view haloo3d_facef_viewport_into(outfaces[ti], WIDTH, HEIGHT); - TRIFUNC(&fb, objects[i].texture, intensity, outfaces[ti]); + TRIFUNC(&fb, &rendersettings, outfaces[ti]); } } }