aboutsummaryrefslogtreecommitdiff
path: root/09-september/LoadResources.c
blob: 5c42f79ed7d4906070c9ed91303332310db2a36b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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();
}