aboutsummaryrefslogtreecommitdiff
path: root/09-september/LoadResources.c
diff options
context:
space:
mode:
authorThomas Guillermo Albers Raviola <thomas@thomaslabs.org>2026-01-16 23:02:32 +0100
committerThomas Guillermo Albers Raviola <thomas@thomaslabs.org>2026-01-16 23:02:32 +0100
commit6b8af9cf83851c075c6c9514b1deaa931c2b19a4 (patch)
tree428986b49c32e21d3f7a3c2dfa41858ae0153209 /09-september/LoadResources.c
Initial commit
Diffstat (limited to '09-september/LoadResources.c')
-rw-r--r--09-september/LoadResources.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/09-september/LoadResources.c b/09-september/LoadResources.c
new file mode 100644
index 0000000..5c42f79
--- /dev/null
+++ b/09-september/LoadResources.c
@@ -0,0 +1,136 @@
+#include "game.h"
+
+void CleanUp(Game *game)
+{
+ Terrain_Destroy(game->terrain);
+ Particles_Shutdown();
+ Render_Shutdown();
+}
+
+void LoadResources(Game *game)
+{
+ Render_Init(game->window);
+ Particles_Init();
+
+ Uint32 start = SDL_GetTicks();
+
+ game->shaderProgram = shader_new("shader_program", "resources/shaders/shader.vert",
+ "resources/shaders/shader.frag");
+
+ game->terrainProgram = shader_new("terrain_program", "resources/shaders/terrainShader.vert",
+ "resources/shaders/terrainShader.frag");
+
+ game->skyboxProgram = shader_new("skybox_program", "resources/shaders/skyboxShader.vert",
+ "resources/shaders/skyboxShader.frag");
+
+ game->particlesProgram = shader_new("particles_program", "resources/shaders/particlesShader.vert",
+ "resources/shaders/particlesShader.frag");
+ glUseProgram(game->shaderProgram->id);
+
+ Model *entsMesh = model_obj_new("resources/barrel.obj");
+
+ Texture *entsTexture = texture_new("resources/textures/barrel.png");
+ game->normalMap[0] = texture_new("resources/textures/bricks_normal.png");
+ game->normalMap[1] = texture_new("resources/textures/normal_map.png");
+ game->defaultNormalMap = texture_new("resources/textures/default_normal_map.png");
+
+
+ Player_Init(&game->player);
+ game->player.entity.texture = entsTexture;
+ game->player.entity.model = entsMesh;
+
+ {
+ Vec3 position = { 0.0f, 0.0f, 0.0f };
+ float rotation[3] = { 0.0f, 0.0f, 0.0f };
+ game->ents[0].position = position;
+ game->ents[0].rotX = rotation[0];
+ game->ents[0].rotY = rotation[1];
+ game->ents[0].rotZ = rotation[2];
+ game->ents[0].model = model_obj_new("resources/plane3.obj");
+ game->ents[0].texture = texture_new("resources/textures/bricks.png");
+ game->ents[0].index = 0;
+ game->ents[0].scale[0] = 1.0f;
+ game->ents[0].scale[1] = 1.0f;
+ game->ents[0].scale[2] = 1.0f;
+ }
+
+ {
+ Vec3 position = { -400.0f, 0.0f, -400.0f };
+ Texture *blendmap = texture_new("resources/textures/blendmap.png");
+ TerrainTexturePack pack =
+ {
+ {
+ texture_new("resources/textures/soil1.png"),
+ texture_new("resources/textures/soil2.png"),
+ texture_new("resources/textures/soil4.png"),
+ texture_new("resources/textures/soil3.png"),
+ }
+ };
+
+ game->terrain = Terrain_Create(800, 800, "resources/textures/heightmap.png", blendmap, &pack);
+ game->terrain->position = position;
+ }
+
+ {
+ game->sky.rotation = 0.0f;
+ game->sky.cube = mesh_make_skybox(500.0f);
+ const char *paths[6] =
+ {
+ "resources/textures/right.png",
+ "resources/textures/left.png",
+ "resources/textures/top.png",
+ "resources/textures/bottom.png",
+ "resources/textures/back.png",
+ "resources/textures/front.png"
+ };
+ game->sky.texture = texture_cubemap_new(paths);
+ }
+
+ ParticleSystem *sys = Particles_AddSystem();
+ game->s = sys;
+ sys->texture = texture_new("resources/textures/particleStar.png");
+ sys->position = game->player.entity.position;
+ sys->texture->number_of_rows = 1;
+ sys->emit_rate = 1;
+ sys->weight = 0.1f;
+ sys->life_length = 1.0f;
+ sys->speed = 10.0f;
+
+ /* Shader Layouts */
+ Shader *s = game->shaderProgram;
+
+ s->Texture = shader_get_uniform_location(s, "Texture");
+ s->modelToWorld = shader_get_uniform_location(s, "M_model");
+ s->totalTransform = shader_get_uniform_location(s, "M_MVP");
+ s->lightPosition = shader_get_uniform_location(s, "lightPosition");
+ s->lightColor = shader_get_uniform_location(s, "lightColor");
+ s->lightAttenuation = shader_get_uniform_location(s, "attenuation");
+ s->Normal_Map = shader_get_uniform_location(s, "normalMap");
+ s->extra0 = shader_get_uniform_location(s, "number_of_rows");
+ s->extra1 = shader_get_uniform_location(s, "offset");
+
+ s = game->terrainProgram;
+ s->modelToWorld = shader_get_uniform_location(s, "M_model");
+ s->totalTransform = shader_get_uniform_location(s, "M_MVP");
+ s->lightPosition = shader_get_uniform_location(s, "lightPosition");
+ s->lightColor = shader_get_uniform_location(s, "lightColor");
+ s->lightAttenuation = shader_get_uniform_location(s, "attenuation");
+
+ s->extra0 = shader_get_uniform_location(s, "Texture_Background");
+ s->extra1 = shader_get_uniform_location(s, "Texture_R");
+ s->extra2 = shader_get_uniform_location(s, "Texture_G");
+ s->extra3 = shader_get_uniform_location(s, "Texture_B");
+ s->extra4 = shader_get_uniform_location(s, "Texture_BlendMap");
+
+ s = game->skyboxProgram;
+ s->totalTransform = shader_get_uniform_location(s, "M_MVP");
+ s->Texture = shader_get_uniform_location(s, "cubeMap");
+
+ s = game->particlesProgram;
+ s->Texture = shader_get_uniform_location(s, "Texture");
+ s->extra0 = shader_get_uniform_location(s, "number_of_rows");
+
+ fprintf(stderr, "Loading time: %u (ms)\n", SDL_GetTicks() - start);
+
+ Util_CheckGLError();
+}