From 1013506095f3e47c6156e56d9cc2bfa25b22e9da Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Sat, 15 Jan 2022 10:53:59 -0500 Subject: [PATCH] make use of new shader init interface in example --- src/main.cpp | 78 +++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 50 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b7e7701..6278b4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,75 +10,50 @@ loadScene(RenderState* rs) // 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 - // NOTE: load model and mesh + // NOTE: load model model* tex_cube = getModelByPath(&rs->assets, "../data/textured_cube.gltf"); - assert(tex_cube); - const mesh& texmesh = tex_cube->meshes[0]; + if (!tex_cube) return false; - // NOTE: load shader + // NOTE: load new shader, or get one of the defaults shader_program* s_default = getShaderByName("default", rs->gl_ctx); - assert(s_default); + if (!s_default) return false; // NOTE: init new render group - RenderGroup* debug_cube_group = getFreeRenderGroup(rs); - assert(debug_cube_group); - initRenderGroup(debug_cube_group, rs->rg_arena, s_default, 1, - "orange_cubes"); - - // NOTE: init entity - Entity* e = getFreeEntity(debug_cube_group); - 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 } - }; + RenderGroup* textured_cubes = getFreeRenderGroup(rs); + assert(textured_cubes); + initRenderGroup(textured_cubes, rs->rg_arena, s_default, 256, + "textured_cubes"); - const u32 NUM_CUBES = 4; + // NOTE: init entities + const u32 NUM_CUBES = 5; 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), }; - 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++) { - Entity* e = getFreeEntity(orange_cubes); - assert(e != nullptr); - - if (!initEntity(e, rs->gl_ctx, rs->rg_arena, tex_cube, - 2, debug_mappings, "debug_box")) + Entity* e = getFreeEntity(textured_cubes); + assert(e); + char cube_name[256] = {0}; + snprintf(cube_name, 256, "textured_cube%d", i); + + arenaCopyCStr(rs->rg_arena, cube_name); + 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; } setEntityPosition(e, cube_locs[i]); } -#endif return true; } @@ -102,7 +77,10 @@ render_cb_pre(RenderState* rs) for (u32 j = 0; j < rg.num_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)); } } }