diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-30 17:25:54 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-30 17:25:54 -0800 |
| commit | 487014fcbc540db8941428aadc820fd14768d46e (patch) | |
| tree | 16fad56ccf852f50dd8b3d59da262d3d1bdba893 /src/main.c | |
| parent | fdaa55621fc7f815c236520ff65033eb8c8c6ca0 (diff) | |
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 19 |
1 files changed, 13 insertions, 6 deletions
| @@ -25,7 +25,9 @@ static constexpr int WindowWidth = 640; | |||
| 25 | static constexpr int WindowHeight = 480; | 25 | static constexpr int WindowHeight = 480; |
| 26 | static constexpr sgVec2i WindowDims = (sgVec2i){.x = WindowWidth, .y = WindowHeight}; | 26 | static constexpr sgVec2i WindowDims = (sgVec2i){.x = WindowWidth, .y = WindowHeight}; |
| 27 | 27 | ||
| 28 | static const R Fovy = (R)(90 * TO_RAD); | 28 | static constexpr R Fovy = (R)(90 * TO_RAD); |
| 29 | static constexpr R Near = 0.1f; | ||
| 30 | static constexpr R Far = 1000.0f; | ||
| 29 | 31 | ||
| 30 | #define DEBUG_EVENT_LOOP 1 | 32 | #define DEBUG_EVENT_LOOP 1 |
| 31 | 33 | ||
| @@ -146,7 +148,8 @@ static void RenderIndexedModel(swgfx* gfx, const IndexedModel* model) { | |||
| 146 | assert(model); | 148 | assert(model); |
| 147 | const sgTriIdx* tris = (const sgTriIdx*)(model->data + model->offsetTris); | 149 | const sgTriIdx* tris = (const sgTriIdx*)(model->data + model->offsetTris); |
| 148 | const sgVec3* positions = (const sgVec3*) (model->data + model->offsetPositions); | 150 | const sgVec3* positions = (const sgVec3*) (model->data + model->offsetPositions); |
| 149 | sgTrianglesIndexedNonUniform(gfx, model->numTris, tris, positions); | 151 | const sgVec2* texcoords = (const sgVec2*)(model->data + model->offsetTexcoords); |
| 152 | sgTrianglesIndexedNonUniform(gfx, model->numTris, tris, positions, texcoords); | ||
| 150 | } | 153 | } |
| 151 | 154 | ||
| 152 | static void RenderModel(swgfx* gfx, const Model* model) { | 155 | static void RenderModel(swgfx* gfx, const Model* model) { |
| @@ -164,7 +167,11 @@ static void RenderTriangle2d(swgfx* gfx) { | |||
| 164 | const sgVec2 p0 = (sgVec2){20, 20}; | 167 | const sgVec2 p0 = (sgVec2){20, 20}; |
| 165 | const sgVec2 p1 = (sgVec2){80, 20}; | 168 | const sgVec2 p1 = (sgVec2){80, 20}; |
| 166 | const sgVec2 p2 = (sgVec2){50, 50}; | 169 | const sgVec2 p2 = (sgVec2){50, 50}; |
| 167 | const sgTri2 tri = (sgTri2){p0, p1, p2}; | 170 | const sgVec2 uv = (sgVec2){0,0}; // Not used. |
| 171 | const sgTri2 tri = (sgTri2){ | ||
| 172 | (sgVert2){p0, uv}, | ||
| 173 | (sgVert2){p1, uv}, | ||
| 174 | (sgVert2){p2, uv}}; | ||
| 168 | sgTriangles2(gfx, 1, &tri); | 175 | sgTriangles2(gfx, 1, &tri); |
| 169 | } | 176 | } |
| 170 | 177 | ||
| @@ -273,7 +280,7 @@ static bool Initialize(State* state) { | |||
| 273 | return false; | 280 | return false; |
| 274 | } | 281 | } |
| 275 | 282 | ||
| 276 | const char* model_path = "/home/jeanne/blender/box.mdl"; | 283 | const char* model_path = "/home/jeanne/blender/box_textured.mdl"; |
| 277 | if (!(state->model = read_file(model_path))) { | 284 | if (!(state->model = read_file(model_path))) { |
| 278 | fprintf(stderr, "Failed to load model: [%s]\n", model_path); | 285 | fprintf(stderr, "Failed to load model: [%s]\n", model_path); |
| 279 | return false; | 286 | return false; |
| @@ -282,8 +289,8 @@ static bool Initialize(State* state) { | |||
| 282 | Camera* camera = &state->camera; | 289 | Camera* camera = &state->camera; |
| 283 | camera->fovy = Fovy; | 290 | camera->fovy = Fovy; |
| 284 | camera->aspect = Aspect; | 291 | camera->aspect = Aspect; |
| 285 | camera->near = 0.1f; | 292 | camera->near = Near; |
| 286 | camera->far = 1000.f; | 293 | camera->far = Far; |
| 287 | camera->spatial = spatial3_make(); | 294 | camera->spatial = spatial3_make(); |
| 288 | camera->spatial.p = vec3_make(0, 1, 10); | 295 | camera->spatial.p = vec3_make(0, 1, 10); |
| 289 | 296 | ||
