summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2026-02-12 17:44:30 -0800
committer3gg <3gg@shellblade.net>2026-02-12 17:44:30 -0800
commite3e9f5b6fb9173ea38ab4b37b137dd17ffe761ad (patch)
treed88313f4a25a6a485b45870a39a12a908408ec0c
parenta023fcefd28312d7055709b77de5ec7b74c508fb (diff)
Use the texture register
-rw-r--r--src/main.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index d0696d0..1fd39e0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -247,9 +247,8 @@ static void RenderModel(swgfx* gfx, const sgImage* textures, const Model* model)
247 const ModelObject* object = &objects[i]; 247 const ModelObject* object = &objects[i];
248 // TODO: This indexing into the textures array assumes that we have loaded a 248 // TODO: This indexing into the textures array assumes that we have loaded a
249 // single model. Generalize later. 249 // single model. Generalize later.
250 assert((size_t)object->material < MaxTextures); 250 assert((size_t)object->material < SWGFX_MAX_TEXTURES);
251 const sgImage* texture = &textures[object->material]; 251 sgTextureActivate(gfx, (sgTextureId)object->material);
252 sgTexture(gfx, texture, sgBilinear);
253 switch (model->type) { 252 switch (model->type) {
254 case ModelTypeIndexed: RenderIndexedModel(gfx, &model->indexed, object); break; 253 case ModelTypeIndexed: RenderIndexedModel(gfx, &model->indexed, object); break;
255 case ModelTypeFlat: /* TODO: Render flat models. */ break; 254 case ModelTypeFlat: /* TODO: Render flat models. */ break;
@@ -361,13 +360,14 @@ static bool Resize(State* state) {
361 360
362static bool LoadTexture(State* state, const char* path) { 361static bool LoadTexture(State* state, const char* path) {
363 assert(state); 362 assert(state);
364 if (state->numTextures >= MaxTextures) { 363 if ((state->numTextures >= MaxTextures) || (state->numTextures >= SWGFX_MAX_TEXTURES)) {
365 fprintf(stderr, "Cannot load texture. Maximum number of textures loaded\n"); 364 fprintf(stderr, "Cannot load texture. Maximum number of textures loaded\n");
366 return false; 365 return false;
367 } 366 }
368 // TODO: This indexing into the textures array assumes that we have loaded a 367 // TODO: This indexing into the textures array assumes that we have loaded a
369 // single model. Generalize later. 368 // single model. Generalize later.
370 sgImage* texture = &state->textures[state->numTextures++]; 369 const size_t id = state->numTextures++;
370 sgImage* texture = &state->textures[id];
371 int channels = 0; 371 int channels = 0;
372 constexpr int desired_channels = 4; 372 constexpr int desired_channels = 4;
373 texture->pixels = (sgPixel*)stbi_load(path, &texture->width, &texture->height, &channels, desired_channels); 373 texture->pixels = (sgPixel*)stbi_load(path, &texture->width, &texture->height, &channels, desired_channels);
@@ -378,6 +378,7 @@ static bool LoadTexture(State* state, const char* path) {
378 assert(channels == desired_channels); 378 assert(channels == desired_channels);
379 // Gamma-correct for lighting. 379 // Gamma-correct for lighting.
380 sgGamma(state->gfx, texture->pixels, texture->width, texture->height); 380 sgGamma(state->gfx, texture->pixels, texture->width, texture->height);
381 sgTextureRegister(state->gfx, (sgTextureId)id, texture, sgBilinear);
381 return true; 382 return true;
382} 383}
383 384