From 487014fcbc540db8941428aadc820fd14768d46e Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Tue, 30 Dec 2025 17:25:54 -0800 Subject: Pass texcoords to gfx --- src/main.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index e0b54c1..f1bb893 100644 --- a/src/main.c +++ b/src/main.c @@ -25,7 +25,9 @@ static constexpr int WindowWidth = 640; static constexpr int WindowHeight = 480; static constexpr sgVec2i WindowDims = (sgVec2i){.x = WindowWidth, .y = WindowHeight}; -static const R Fovy = (R)(90 * TO_RAD); +static constexpr R Fovy = (R)(90 * TO_RAD); +static constexpr R Near = 0.1f; +static constexpr R Far = 1000.0f; #define DEBUG_EVENT_LOOP 1 @@ -146,7 +148,8 @@ static void RenderIndexedModel(swgfx* gfx, const IndexedModel* model) { assert(model); const sgTriIdx* tris = (const sgTriIdx*)(model->data + model->offsetTris); const sgVec3* positions = (const sgVec3*) (model->data + model->offsetPositions); - sgTrianglesIndexedNonUniform(gfx, model->numTris, tris, positions); + const sgVec2* texcoords = (const sgVec2*)(model->data + model->offsetTexcoords); + sgTrianglesIndexedNonUniform(gfx, model->numTris, tris, positions, texcoords); } static void RenderModel(swgfx* gfx, const Model* model) { @@ -164,7 +167,11 @@ static void RenderTriangle2d(swgfx* gfx) { const sgVec2 p0 = (sgVec2){20, 20}; const sgVec2 p1 = (sgVec2){80, 20}; const sgVec2 p2 = (sgVec2){50, 50}; - const sgTri2 tri = (sgTri2){p0, p1, p2}; + const sgVec2 uv = (sgVec2){0,0}; // Not used. + const sgTri2 tri = (sgTri2){ + (sgVert2){p0, uv}, + (sgVert2){p1, uv}, + (sgVert2){p2, uv}}; sgTriangles2(gfx, 1, &tri); } @@ -273,7 +280,7 @@ static bool Initialize(State* state) { return false; } - const char* model_path = "/home/jeanne/blender/box.mdl"; + const char* model_path = "/home/jeanne/blender/box_textured.mdl"; if (!(state->model = read_file(model_path))) { fprintf(stderr, "Failed to load model: [%s]\n", model_path); return false; @@ -282,8 +289,8 @@ static bool Initialize(State* state) { Camera* camera = &state->camera; camera->fovy = Fovy; camera->aspect = Aspect; - camera->near = 0.1f; - camera->far = 1000.f; + camera->near = Near; + camera->far = Far; camera->spatial = spatial3_make(); camera->spatial.p = vec3_make(0, 1, 10); -- cgit v1.2.3