X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fmain.cc;h=7061bb67509bae8b5d369b75759f2a1960711d9a;hb=d1a2cf93cf54898bb4ad442da94fc61f2617cf9f;hp=2727f4b1d546f4eab7fd2022bff0ef78027f018c;hpb=63d7f3b0e70ab5e3d530c579b1881967c96b0b92;p=demo diff --git a/src/main.cc b/src/main.cc index 2727f4b..7061bb6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -5,6 +7,7 @@ #include +#include "gfxapi.h" #include "global.h" /* TODO: fix those */ @@ -13,14 +16,14 @@ #include "object.h" #include "renderer.h" #include "scene.h" -#include "shader_manager.h" +#include "texture.h" #include "opengl/opengl.h" #include "vulkan/vk.h" /* static functions */ -static bool init(); +static bool init(Gfx_API api); static void cleanup(); static void display(); @@ -33,7 +36,6 @@ static void clbk_reshape(GLFWwindow *win, int width, int height); /* global variables */ -bool use_vulkan = false; Mat4 mprojection; GLFWwindow *win; @@ -47,27 +49,39 @@ float dist = 4; ShaderManager *sdr_man; /* variables */ + static float aspect; -static Scene *scene; static OrbitCamera *camera; -static Renderer *rdefault; // default renderer + +static Scene *scene_cow; +static Renderer *rcow; + +static Scene *scene_ground; +static Renderer *rground; // default renderer +static Texture *gskybox; + +/* *** */ int main(int argc, char **argv) { + Gfx_API api; + for(int i=0; iset_orbit_params(phi, theta, dist); - scene = new Scene; - if(!scene->load("data/spot/spot.obj")) { - fprintf(stderr, "Failed to load scene.\n"); + scene_ground = new Scene; + if(!scene_ground->load("data/ground.obj")) { + fprintf(stderr, "Failed to load scene: ground.obj.\n"); + return false; + } + + scene_cow = new Scene; + if(!scene_cow->load("data/spot/spot.obj")) { + fprintf(stderr, "Failed to load scene: spot.obj.\n"); return false; } - rdefault = new Renderer; - rdefault->camera = camera; - rdefault->scene = scene; + rground = new Renderer; + rground->camera = camera; + rground->scene = scene_ground; - if(!rdefault->create()) { + if(!rground->create()) { fprintf(stderr, "Failed to create default renderer.\n"); return false; } + gskybox = gfx_create_texture(); + gskybox->load("data/cubemap/cubemap.jpg"); + rground->set_sky_tex(gskybox); + + rcow = new Renderer; + rcow->camera = camera; + rcow->scene = scene_cow; + + if(!rcow->create()) { + fprintf(stderr, "Failed to create renderer for cows.\n"); + return false; + } + // TODO delete: debugging - for(size_t i=0; iobjects.size(); ++i) { + for(size_t i=0; iobjects.size(); ++i) { printf("object: %d\n", (int)i); - printf("mesh: %s\n", scene->objects[i]->mesh->name.c_str()); - printf("material: %s\n", scene->objects[i]->material->name.c_str()); + printf("mesh: %s\n", scene_ground->objects[i]->mesh->name.c_str()); + printf("material: %s\n", scene_ground->objects[i]->material->name.c_str()); printf("transform:\n"); - scene->objects[i]->transform.print(); + scene_ground->objects[i]->transform.print(); } return true; } @@ -138,14 +165,14 @@ static void cleanup() { delete sdr_man; delete camera; - delete rdefault; - if(use_vulkan) { - cleanup_vulkan(); - } - else { - cleanup_opengl(); - } + delete scene_cow; + delete rcow; + + delete scene_ground; + delete rground; + + gfx_cleanup(); } static void clbk_key(GLFWwindow *win, int key, int scancode, int action, int mods) @@ -177,7 +204,7 @@ static void clbk_motion(GLFWwindow *win, double x, double y) } if(button[1]) { - dist += dy; + dist += dy * 0.1; if(dist < 0.0) { dist = 0.0; } @@ -192,15 +219,9 @@ static void clbk_mouse(GLFWwindow *win, int bn, int action, int mods) static void clbk_reshape(GLFWwindow *win, int width, int height) { - if(use_vulkan) { - //TODO - return; - } - else { - glViewport(0, 0, width, height); - aspect = (float)width / (float)height; - mprojection = calc_projection_matrix(45, aspect, 0.5, 1000.0); - } + gfx_viewport(0, 0, width, height); + aspect = (float)width / (float)height; + mprojection = calc_projection_matrix(45, aspect, 0.5, 1000.0); win_h = height; win_w = width; @@ -209,5 +230,9 @@ static void clbk_reshape(GLFWwindow *win, int width, int height) static void display() { camera->set_orbit_params(phi, theta, dist); - rdefault->draw(); + + gfx_clear(0.76, 0.3, 0.43); + + rground->draw(); + rcow->draw(); } \ No newline at end of file