no clue :) just to push it
[demo] / src / main.cc
index 491dd9c..aeb57a6 100644 (file)
@@ -1,4 +1,5 @@
 #include <GL/glew.h>
+#include <GLFW/glfw3.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -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;
@@ -71,6 +72,7 @@ static TerrainParams p;
 static Texture *skybox_tex;
 static Texture *irradiance_tex;
 static Texture *terrain_tex;
+static Texture *dirt_tex;
 static Material terrain_mat;
 static Renderer *terrain_rend;
 
@@ -80,7 +82,7 @@ int main(int argc, char **argv)
 {
        Gfx_API api;
 
-       for(int i=0; i<argc; ++i) {
+       for(int i=1; i<argc; i++) {
                if(strcmp(argv[i], "-opengl") == 0) {
                        api = GFX_GL;
                        printf("Backend: OpenGL.\n");
@@ -100,6 +102,9 @@ int main(int argc, char **argv)
                return 1;
        }
 
+       //TODO
+       //return 0;
+
        glfwSetKeyCallback(win, clbk_key);
        glfwSetCursorPosCallback(win, clbk_motion);
        glfwSetMouseButtonCallback(win, clbk_mouse);
@@ -111,12 +116,11 @@ int main(int argc, char **argv)
        while(!glfwWindowShouldClose(win)) {
                display();
 
-               glfwSwapBuffers(win);
+               gfx_swapbuffers();
                glfwPollEvents();
        }
 
        cleanup();
-       // atexit(cleanup);
        return 0;
 }
 
@@ -133,7 +137,13 @@ static bool init(Gfx_API api)
 
        terrain_tex = gfx_create_texture();
        if(!terrain_tex->load("data/grass.jpeg")) {
-               fprintf(stderr, "Failed to load ground texture.\n");
+               fprintf(stderr, "Failed to load ground grass texture.\n");
+               return false;
+       }
+
+       dirt_tex = gfx_create_texture();
+       if(!dirt_tex->load("data/dirt.jpg")) {
+               fprintf(stderr, "Failed to load ground dirt texture.\n");
                return false;
        }
 
@@ -143,11 +153,11 @@ static bool init(Gfx_API api)
                return false;
        }
 
-       p.xsz = 200;
-       p.ysz = 200;
-       p.max_height = 30;
-       p.xtiles = 40;
-       p.ytiles = 40;
+       p.xsz = 20;//200;
+       p.ysz = 20; //200;
+       p.max_height = 3;//30;
+       p.xtiles = 4;//40;
+       p.ytiles = 4;//40;
        p.tile_usub = 10;
        p.tile_vsub = 10;
        p.num_octaves = 3;
@@ -211,7 +221,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));
@@ -261,12 +271,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;
@@ -305,7 +323,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)
 {
@@ -315,6 +333,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);
@@ -355,17 +374,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<Vec2> &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;
 
@@ -373,7 +395,7 @@ static bool gen_poisson(std::vector<Vec2> &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.size(); j++) {
                        if(length_sq(points[j] - p) < min_dist * min_dist) {
                                valid = false;
@@ -386,4 +408,4 @@ static bool gen_poisson(std::vector<Vec2> &points, float min_dist, float radius)
                }
        }
        return false;
-}
\ No newline at end of file
+}