blob: 2bca4a1741c2c52c49c61a9688e79aa8a69eb320 (
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
|
#include "texture_view.h"
#include <gfx/render_backend.h>
#include <gfx/scene.h>
#include <gfx/util/geometry.h>
#include <gfx/util/shader.h>
#include <gfx/util/texture.h>
#include <math/camera.h>
#include <assert.h>
#include <stdlib.h>
// Default texture to load if no texture is provided.
static const char* CLOUDS1_TEXTURE = "/assets/skybox/clouds1/clouds1_west.bmp";
bool boot(State* state, Game* game) {
assert(game);
// Usage: [texture file]
const char* texture_file = game->argc > 1 ? game->argv[1] : CLOUDS1_TEXTURE;
RenderBackend* render_backend = gfx_get_render_backend(game->gfx);
Texture* texture = gfx_load_texture(
render_backend, &(LoadTextureCmd){
.origin = TextureFromFile,
.type = LoadTexture,
.filtering = LinearFiltering,
.mipmaps = false,
.data.texture.filepath = mstring_make(texture_file)});
ShaderProgram* shader = gfx_make_view_texture_shader(render_backend);
if (!shader) {
return false;
}
Geometry* geometry = gfx_make_quad_11(render_backend);
if (!geometry) {
return false;
}
MaterialDesc material_desc = (MaterialDesc){0};
material_desc.uniforms[0] = (ShaderUniform){
.type = UniformTexture,
.value.texture = texture,
.name = sstring_make("Texture")};
material_desc.num_uniforms = 1;
Material* material = gfx_make_material(&material_desc);
if (!material) {
return false;
}
MeshDesc mesh_desc = (MeshDesc){0};
mesh_desc.geometry = geometry;
mesh_desc.material = material;
mesh_desc.shader = shader;
Mesh* mesh = gfx_make_mesh(&mesh_desc);
if (!mesh) {
return false;
}
SceneObject* object = gfx_make_object();
if (!object) {
return false;
}
gfx_add_object_mesh(object, mesh);
SceneNode* node = gfx_make_object_node(object);
SceneNode* root = gfx_get_scene_root(game->scene);
gfx_set_node_parent(node, root);
return true;
}
|