X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fmain.cc;h=affeff79119f4c4bbf866ea3295c13cf36c9918b;hb=86c912d603be75ac8b2fdb2229f1696e9c0c01d9;hp=cbe6ed606e99414fe9f69a29c3c3feb284ff1e19;hpb=829221c492640e3523538efe87483fd16899cb03;p=demo diff --git a/src/main.cc b/src/main.cc index cbe6ed6..affeff7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,4 +1,5 @@ #include +#include #include #include @@ -61,7 +62,7 @@ static OrbitCamera *camera; static float fog_density; -static int num_cows = 400; +static int num_cows = 1; static float cow_gap = 4; static Scene *cow_scene; static MorphRenderer *cow_rend; @@ -69,6 +70,7 @@ static MorphRenderer *cow_rend; static Terrain terrain; static TerrainParams p; static Texture *skybox_tex; +static Texture *irradiance_tex; static Texture *terrain_tex; static Material terrain_mat; static Renderer *terrain_rend; @@ -79,7 +81,7 @@ int main(int argc, char **argv) { Gfx_API api; - for(int i=0; iload("data/cubemap/cubemap.hdr"); - //irr_tex->load("data/cubemap/irradiance.hdr"); terrain_rend->set_sky_tex(skybox_tex); + irradiance_tex = gfx_create_texture(); + irradiance_tex->load("data/cubemap/irradiance.hdr"); + terrain_rend->set_diffuse_sky_tex(irradiance_tex); + if(!terrain_rend->create()) { fprintf(stderr, "terrain fail\n"); return false; @@ -207,7 +214,7 @@ static bool init(Gfx_API api) Object *cow = new Object; *cow = *cow0; - if (!gen_poisson(cow_pos, cow_gap, disk_radius)) + if(!gen_poisson(cow_pos, cow_gap, disk_radius)) goto cowgen_end; Vec2 pos = cow_pos.back(); float y = terrain.get_height(Vec3(pos.x, 1, pos.y)); @@ -230,8 +237,11 @@ static void cleanup() delete cow_scene; delete cow_rend; + delete skybox_tex; + delete irradiance_tex; delete terrain_tex; delete terrain_rend; + gfx_cleanup(); } @@ -254,12 +264,20 @@ static void clbk_key(GLFWwindow *win, int key, int scancode, int action, int mod break; // case 'F': - // fog_density = fog_density < 1 - 0.0009 ? fog_density + 0.0001 : 1; - // break; + // fog_density = fog_density < 1 - 0.0009 ? fog_density + 0.0001 : 1; + // break; // case 'U': - // fog_density = fog_density > 0.0001 ? fog_density - 0.0001 : 0; - // break; + // fog_density = fog_density > 0.0001 ? fog_density - 0.0001 : 0; + // break; + + case 'P': + gfx_wireframe(true); + break; + + case 'F': + gfx_wireframe(false); + break; default: break; @@ -298,7 +316,7 @@ static void clbk_motion(GLFWwindow *win, double x, double y) cam_dist = 0.0; } } - } +} static void clbk_mouse(GLFWwindow *win, int bn, int action, int mods) { @@ -308,6 +326,7 @@ static void clbk_mouse(GLFWwindow *win, int bn, int action, int mods) static void clbk_reshape(GLFWwindow *win, int width, int height) { + gfx_reshape(width, height); gfx_viewport(0, 0, width, height); aspect = (float)width / (float)height; mprojection = calc_projection_matrix(45, aspect, 0.5, 1000.0); @@ -348,17 +367,20 @@ static void display() camera->set_orbit_params(cam_theta, cam_phi, cam_dist); camera->set_position(cam_pos.x, cam_pos.y, cam_pos.z); + gfx_begin_drawing(); + gfx_clear(0.1, 0.1, 0.1); terrain_rend->draw(); cow_rend->draw(); + + gfx_end_drawing(); } static bool gen_poisson(std::vector &points, float min_dist, float radius) { /* poisson radius */ - for (int i = 0; i < 1000; i++) - { + for(int i = 0; i < 1000; i++) { float angle = (float)rand() / (float)RAND_MAX * 2 * M_PI; float r = sqrt((float)rand() / (float)RAND_MAX) * radius; @@ -366,7 +388,7 @@ static bool gen_poisson(std::vector &points, float min_dist, float radius) p.x = cos(angle) * r; p.y = sin(angle) * r; - bool valid = true; + bool valid = true; for(size_t j=0; j &points, float min_dist, float radius) } } return false; -} \ No newline at end of file +}