Browse Source

make use of new shader init interface in example

main
cinnaboot 5 years ago
parent
commit
1013506095
  1. 76
      src/main.cpp

76
src/main.cpp

@ -10,75 +10,50 @@ loadScene(RenderState* rs)
// TODO: come up with an easy to use interface for loading a model, setting // TODO: come up with an easy to use interface for loading a model, setting
// up the buffer to attrib mappings, and initializing a render group // up the buffer to attrib mappings, and initializing a render group
// NOTE: load model and mesh // NOTE: load model
model* tex_cube = getModelByPath(&rs->assets, "../data/textured_cube.gltf"); model* tex_cube = getModelByPath(&rs->assets, "../data/textured_cube.gltf");
assert(tex_cube); if (!tex_cube) return false;
const mesh& texmesh = tex_cube->meshes[0];
// NOTE: load shader // NOTE: load new shader, or get one of the defaults
shader_program* s_default = getShaderByName("default", rs->gl_ctx); shader_program* s_default = getShaderByName("default", rs->gl_ctx);
assert(s_default); if (!s_default) return false;
// NOTE: init new render group // NOTE: init new render group
RenderGroup* debug_cube_group = getFreeRenderGroup(rs); RenderGroup* textured_cubes = getFreeRenderGroup(rs);
assert(debug_cube_group); assert(textured_cubes);
initRenderGroup(debug_cube_group, rs->rg_arena, s_default, 1, initRenderGroup(textured_cubes, rs->rg_arena, s_default, 256,
"orange_cubes"); "textured_cubes");
// NOTE: init entity // NOTE: init entities
Entity* e = getFreeEntity(debug_cube_group); const u32 NUM_CUBES = 5;
assert(e);
initEntity(e,
rs->gl_ctx,
rs->rg_arena,
tex_cube,
s_default->num_vertex_attribs,
s_default->attrib_mappings,
"textured_box");
scaleEntity(e, 5);
#if 0
shader_program* s_debug = getShaderByName("debug", rs->gl_ctx);
if (!s_debug) return false;
GLVertexAttrib* db_pos_attrib = getVertexAttribByName(s_debug, "position");
GLVertexAttrib* db_normal_attrib = getVertexAttribByName(s_debug, "normal");
if (!db_pos_attrib || !db_normal_attrib) return false;
GLBufferToAttribMapping debug_mappings[2] = {
{ "position", db_pos_attrib, texmesh.vertices },
{ "normal", db_normal_attrib, texmesh.normals }
};
const u32 NUM_CUBES = 4;
glm::vec3 cube_locs[NUM_CUBES] = { glm::vec3 cube_locs[NUM_CUBES] = {
glm::vec3( 0, 0, 0),
glm::vec3(-10, 10, 0), glm::vec3(-10, 10, 0),
glm::vec3(-10, -10, 0), glm::vec3(-10, -10, 0),
glm::vec3( 10, 10, 0), glm::vec3( 10, 10, 0),
glm::vec3( 10, -10, 0), glm::vec3( 10, -10, 0),
}; };
RenderGroup* orange_cubes = getFreeRenderGroup(rs);
assert(orange_cubes != nullptr);
initRenderGroup(orange_cubes, rs->rg_arena, s_debug, NUM_CUBES,
"debug_cubes");
for (u32 i = 0; i < NUM_CUBES; i++) { for (u32 i = 0; i < NUM_CUBES; i++) {
Entity* e = getFreeEntity(orange_cubes); Entity* e = getFreeEntity(textured_cubes);
assert(e != nullptr); assert(e);
char cube_name[256] = {0};
snprintf(cube_name, 256, "textured_cube%d", i);
if (!initEntity(e, rs->gl_ctx, rs->rg_arena, tex_cube, arenaCopyCStr(rs->rg_arena, cube_name);
2, debug_mappings, "debug_box")) if (!initEntity(e,
rs->gl_ctx,
rs->rg_arena,
tex_cube,
s_default->num_vertex_attribs,
s_default->attrib_mappings,
cube_name))
{ {
// FIXME: this doesn't actually do anything
freeRenderGroup(orange_cubes, rs->rg_arena);
return false; return false;
} }
setEntityPosition(e, cube_locs[i]); setEntityPosition(e, cube_locs[i]);
} }
#endif
return true; return true;
} }
@ -102,7 +77,10 @@ render_cb_pre(RenderState* rs)
for (u32 j = 0; j < rg.num_entities; j++) { for (u32 j = 0; j < rg.num_entities; j++) {
Entity& e = rg.entities[j]; Entity& e = rg.entities[j];
rotateEntity(&e, glm::vec3(0, 1, 0), (float) M_PI / (3 * 60)); float direction = (j % 2 == 0) ? 1 : -1;
rotateEntity(&e,
glm::vec3(0, 1, 0),
direction * (float) M_PI / (3 * 60));
} }
} }
} }

Loading…
Cancel
Save