Browse Source

Fix CMake build

Phyks (Lucas Verney) 4 years ago
parent
commit
670c89ac98

+ 5
- 5
src/core/SkiMapRenderer.cc View File

@@ -48,9 +48,9 @@ void SkiMapRenderer::on_surface_changed(void) {
48 48
     // Set the camera position and orientation
49 49
     mat4x4_look_at(
50 50
             view_matrix_,
51
-            config::DEFAULT_EYE,
52
-            config::DEFAULT_CENTER,
53
-            config::DEFAULT_UP);
51
+            const_cast<float*>(config::DEFAULT_EYE),
52
+            const_cast<float*>(config::DEFAULT_CENTER),
53
+            const_cast<float*>(config::DEFAULT_UP));
54 54
 
55 55
     // Enable culling
56 56
     glEnable(GL_CULL_FACE);
@@ -63,5 +63,5 @@ void SkiMapRenderer::on_draw_frame(void) {
63 63
     // Clear the buffers
64 64
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
65 65
 
66
-    terrain_.draw(view_matrix_, projection_matrix, directional_light_);
67
-};
66
+    terrain_.draw(view_matrix_, projection_matrix_, directional_light_);
67
+}

+ 1
- 1
src/core/SkiMapRenderer.h View File

@@ -6,7 +6,7 @@
6 6
 
7 7
 // Local includes
8 8
 #include "Renderer.h"
9
-#include "TerrainProgram.h"
9
+#include "Terrain.h"
10 10
 
11 11
 
12 12
 class SkiMapRenderer: public Renderer {

+ 23
- 17
src/core/Terrain.cc View File

@@ -3,6 +3,7 @@
3 3
 
4 4
 // Local includes
5 5
 #include "config.h"
6
+#include "Buffer.h"
6 7
 
7 8
 
8 9
 TerrainProgram::TerrainProgram(
@@ -22,7 +23,7 @@ Terrain::Terrain(
22 23
         const std::string vertex_shader_filename,
23 24
         const std::string fragment_shader_filename)
24 25
     : program_(vertex_shader_filename, fragment_shader_filename)
25
-    , material(config::TERRAIN_MATERIAL)
26
+    , material_(config::TERRAIN_MATERIAL)
26 27
     , model_matrix_()
27 28
     , terrainData_()
28 29
     , buffer_id_(0)
@@ -34,10 +35,12 @@ Terrain::Terrain(
34 35
     // TODO[Lucas] Handle terrain data + buffer initialization + compute normal
35 36
 
36 37
     // Initialize the buffer
37
-    buffer_length_ = sizeof(table_data);
38
+    // TODO[Lucas] buffer_length_ = sizeof(table_data);
39
+    buffer_length_ = 0;
38 40
     // The buffer pointer by buffer_id_ contains X, Y, Z components for a
39 41
     // vertex, followed by X, Y, Z component for the normal associated to this
40 42
     // vertex, tightly packed in a 1D array.
43
+    GLvoid* table_data = NULL;
41 44
     buffer_id_ = create_vbo(buffer_length_, table_data, GL_STATIC_DRAW);
42 45
 }
43 46
 
@@ -49,8 +52,8 @@ void Terrain::draw(
49 52
     // Compute the necessary matrices
50 53
     mat4x4 model_view_projection_matrix = {};
51 54
     mat4x4 model_view_matrix = {};
52
-    mat4x4_mul(model_view_matrix, view_matrix_, model_matrix_);
53
-    mat4x4_mul(model_view_projection_matrix, projection_matrix_, model_view_matrix_);
55
+    mat4x4_mul(model_view_matrix, view_matrix, model_matrix_);
56
+    mat4x4_mul(model_view_projection_matrix, projection_matrix, model_view_matrix);
54 57
 
55 58
     // Use the TerrainProgram
56 59
     glUseProgram(program_.get_program_id());
@@ -68,33 +71,33 @@ void Terrain::draw(
68 71
             (GLfloat*) model_view_matrix);  // values
69 72
     // Directional light uniform
70 73
     {
71
-        GLint loc = get_location("u_directional_light.direction");
74
+        GLint loc = program_.get_location("u_directional_light.direction");
72 75
         glUniform3f(
73 76
                 loc,
74 77
                 directional_light.direction[0],
75 78
                 directional_light.direction[1],
76 79
                 directional_light.direction[2]);
77
-        loc = get_location("u_directional_light.halfplane");
80
+        loc = program_.get_location("u_directional_light.halfplane");
78 81
         glUniform3f(
79 82
                 loc,
80 83
                 directional_light.halfplane[0],
81 84
                 directional_light.halfplane[1],
82 85
                 directional_light.halfplane[2]);
83
-        loc = get_location("u_directional_light.ambient_color");
86
+        loc = program_.get_location("u_directional_light.ambient_color");
84 87
         glUniform4f(
85 88
                 loc,
86 89
                 directional_light.ambient_color[0],
87 90
                 directional_light.ambient_color[1],
88 91
                 directional_light.ambient_color[2],
89 92
                 directional_light.ambient_color[3]);
90
-        loc = get_location("u_directional_light.diffuse_color");
93
+        loc = program_.get_location("u_directional_light.diffuse_color");
91 94
         glUniform4f(
92 95
                 loc,
93 96
                 directional_light.diffuse_color[0],
94 97
                 directional_light.diffuse_color[1],
95 98
                 directional_light.diffuse_color[2],
96 99
                 directional_light.diffuse_color[3]);
97
-        loc = get_location("u_directional_light.specular_color");
100
+        loc = program_.get_location("u_directional_light.specular_color");
98 101
         glUniform4f(
99 102
                 loc,
100 103
                 directional_light.specular_color[0],
@@ -104,25 +107,28 @@ void Terrain::draw(
104 107
     }
105 108
     // Material uniform
106 109
     {
107
-        GLint loc = get_location("u_material.ambient_factor");
110
+        GLint loc = program_.get_location("u_material.ambient_factor");
108 111
         glUniform4f(
109 112
                 loc,
110 113
                 material_.ambient_factor[0],
111 114
                 material_.ambient_factor[1],
112
-                material_.ambient_factor[2]);
113
-        GLint loc = get_location("u_material.diffuse_factor");
115
+                material_.ambient_factor[2],
116
+                material_.ambient_factor[3]);
117
+        loc = program_.get_location("u_material.diffuse_factor");
114 118
         glUniform4f(
115 119
                 loc,
116 120
                 material_.diffuse_factor[0],
117 121
                 material_.diffuse_factor[1],
118
-                material_.diffuse_factor[2]);
119
-        GLint loc = get_location("u_material.specular_factor");
122
+                material_.diffuse_factor[2],
123
+                material_.diffuse_factor[3]);
124
+        loc = program_.get_location("u_material.specular_factor");
120 125
         glUniform4f(
121 126
                 loc,
122 127
                 material_.specular_factor[0],
123 128
                 material_.specular_factor[1],
124
-                material_.specular_factor[2]);
125
-        GLint loc = get_location("u_material.shininess");
129
+                material_.specular_factor[2],
130
+                material_.specular_factor[3]);
131
+        loc = program_.get_location("u_material.shininess");
126 132
         glUniform1f(loc, material_.shininess);
127 133
     }
128 134
 
@@ -150,7 +156,7 @@ void Terrain::draw(
150 156
             BUFFER_OFFSET(3 * sizeof(GLfloat)));  // offset for the first component
151 157
     glEnableVertexAttribArray(program_.get_location("a_normal"));
152 158
     // Draw the points in the buffer
153
-    glDrawArrays(GL_TRIANGLE, 0, buffer_length_);
159
+    glDrawArrays(GL_TRIANGLES, 0, buffer_length_);
154 160
     // Unbind buffer
155 161
     glBindBuffer(GL_ARRAY_BUFFER, 0);
156 162
 }

+ 4
- 0
src/core/Terrain.h View File

@@ -1,11 +1,15 @@
1 1
 #ifndef SKIMAP_CORE_TERRAIN_H_
2 2
 #define SKIMAP_CORE_TERRAIN_H_
3 3
 
4
+// System includes
5
+#include <vector>
6
+
4 7
 // 3rd party includes
5 8
 #include "linmath/linmath.h"
6 9
 
7 10
 // Local haders
8 11
 #include "platform_gl.h"
12
+#include "Program.h"
9 13
 
10 14
 namespace terrain_shader {
11 15
     typedef struct {

+ 18
- 10
src/core/config.h View File

@@ -9,25 +9,33 @@
9 9
 
10 10
 
11 11
 namespace config {
12
-    const char* VERTEX_SHADER_FILENAME = "";
13
-    const char* FRAGMENT_SHADER_FILENAME = "";
12
+    static const char* VERTEX_SHADER_FILENAME = "";
13
+    static const char* FRAGMENT_SHADER_FILENAME = "";
14 14
 
15
-    const vec4 CLEAR_COLOR = {0.0f, 0.63f, 0.9f, 1.0f};
15
+    static const vec4 CLEAR_COLOR = {0.0f, 0.63f, 0.9f, 1.0f};
16 16
 
17
-    const float FOV = 45;
18
-    const float NEAR = 1.0f;
19
-    const float FAR = 100.0f;
17
+    static const float FOV = 45;
18
+    static const float NEAR = 1.0f;
19
+    static const float FAR = 100.0f;
20 20
 
21
-    const vec3 DEFAULT_EYE = {0.0f, 1.2f, 2.2f};
22
-    const vec3 DEFAULT_CENTER = {0.0f, 0.0f, 0.0f};
23
-    const vec3 DEFAULT_UP = {0.0f, 1.0f, 0.0f};  // Traditionnally, y is the camera vertical
21
+    static const vec3 DEFAULT_EYE = {0.0f, 1.2f, 2.2f};
22
+    static const vec3 DEFAULT_CENTER = {0.0f, 0.0f, 0.0f};
23
+    static const vec3 DEFAULT_UP = {0.0f, 1.0f, 0.0f};  // Traditionnally, y is the camera vertical
24 24
 
25
-    const terrain_shader::Material_t TERRAIN_MATERIAL = {
25
+    static const terrain_shader::Material_t TERRAIN_MATERIAL = {
26 26
         {1.0f, 1.0f, 1.0f},  // ambient factor
27 27
         {1.0f, 1.0f, 1.0f},  // diffuse factor
28 28
         {0.0f, 0.0f, 0.0f},  // specular factor
29 29
         0.0f  // shininess
30 30
     };
31
+
32
+    static const terrain_shader::DirectionalLight_t DIRECTIONAL_LIGHT = {
33
+        {0.0f, 0.0f, 0.0f},
34
+        {0.0f, 0.0f, 0.0f},
35
+        {0.0f, 0.0f, 0.0f, 0.0f},
36
+        {0.0f, 0.0f, 0.0f, 0.0f},
37
+        {0.0f, 0.0f, 0.0f, 0.0f}
38
+    };
31 39
 }
32 40
 
33 41
 #endif  // SKIMAP_CORE_CONFIG_H_

+ 1
- 1
src/framework/Buffer.cc View File

@@ -1,5 +1,5 @@
1 1
 // Associated header
2
-#include "buffer.h"
2
+#include "Buffer.h"
3 3
 
4 4
 // System includes
5 5
 #include <cstddef>

src/framework/buffer.h → src/framework/Buffer.h View File

@@ -4,6 +4,7 @@
4 4
 // Local includes
5 5
 #include "platform_gl.h"
6 6
 
7
+inline void* BUFFER_OFFSET(int i) { return (void*)(i); }
7 8
 
8 9
 GLuint create_vbo(const GLsizeiptr size, const GLvoid* data, const GLenum usage);
9 10
 

+ 0
- 67
src/framework/Heightmap.cc View File

@@ -1,67 +0,0 @@
1
-// System includes
2
-#include <cstddef>
3
-#include <iostream>
4
-
5
-// 3rd party includes
6
-#include <xtiffio.h>
7
-#include <geotiffio.h>
8
-
9
-enum {
10
-    VERSION = 0, MAJOR, MINOR
11
-};
12
-
13
-
14
-int main(int argc, char*argv[]) {
15
-    if(argc < 2)
16
-    {
17
-        std::cerr << "Required arguments: filename" << std::endl;
18
-        return -1;
19
-    }
20
-
21
-    // Open TIFF descriptor to read GeoTIFF tags
22
-    TIFF *tif = XTIFFOpen(argv[1], "r");  // TIFF-level description
23
-    if (NULL == tif) {
24
-        // TODO[Error]
25
-    }
26
-
27
-    // Open GTIF Key parser; keys will be read at this time.
28
-    GTIF *gtif = GTIFNew(tif);  // GeoTIFF-level description
29
-    if (NULL == gtif) {
30
-        // TODO[Error]
31
-    }
32
-
33
-    // Get the GeoTIFF directory info
34
-    int versions[3] = {};
35
-    GTIFFDirectoryInfo(gtif, versions, 0);
36
-    if (versions[MAJOR] > 1) {
37
-        // TODO[Error] This file is too new
38
-    }
39
-    geocode_t model;  // All key-codes are of this type
40
-    if (0 != GTIFKeyGet(gtif, GTModelTypeGeoKey, &model, 0, 1)) {
41
-        // TODO[Error] Unable to find a model type
42
-    }
43
-
44
-    // ASCII keys are variable-length; compute size
45
-    int size = 0;
46
-    int cit_length = GTIFKeyInfo(gtif, GTCitationGeoKey, &size, &type);
47
-    if (cit_length > 0) {
48
-        char *citation = (char *) malloc(size * cit_length);
49
-        if (NULL == citation) {
50
-            // TODO[Error]
51
-        }
52
-        GTIFKeyGet(gtif, GTCitationGeoKey, citation, 0, cit_length);
53
-        printf("Citation:%s\n", citation);
54
-    }
55
-
56
-    // Get some TIFF info on this image
57
-    int width = 0;
58
-    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
59
-
60
-    // Get rid of the key parser
61
-    GTIFFree(gtif);
62
-
63
-    // Close the TIFF file descriptor
64
-    XTIFFClose(tif);
65
-
66
-    return 0;
67
-}

+ 6
- 6
src/framework/Program.cc View File

@@ -21,13 +21,13 @@ Program::Program(
21 21
     fragment_shader_source << ifs.rdbuf();
22 22
 
23 23
     // Build the program
24
-    build_program(
24
+    build(
25 25
             vertex_shader_source.str().c_str(),
26 26
             fragment_shader_source.str().c_str());
27
-};
27
+}
28 28
 
29 29
 
30
-GLuint get_program_id(void) const {
30
+GLuint Program::get_program_id(void) const {
31 31
     return program_id_;
32 32
 }
33 33
 
@@ -84,7 +84,7 @@ GLuint Program::link(const GLuint vertex_shader, const GLuint fragment_shader) {
84 84
 
85 85
 
86 86
 void Program::build(
87
-        const GLchar* vertex_shader_source;
87
+        const GLchar* vertex_shader_source,
88 88
         const GLchar* fragment_shader_source) {
89 89
     if ((NULL == vertex_shader_source) || (NULL == fragment_shader_source)) {
90 90
         // TODO[Error]
@@ -101,5 +101,5 @@ void Program::build(
101 101
             fragment_shader_source);
102 102
 
103 103
     // Link both of them and set the program id
104
-    program_id_ = link_program(vertex_shader, fragment_shader);
105
-};
104
+    program_id_ = link(vertex_shader, fragment_shader);
105
+}

+ 4
- 1
src/framework/Program.h View File

@@ -1,6 +1,9 @@
1 1
 #ifndef SKIMAP_FRAMEWORK_PROGRAM_H_
2 2
 #define SKIMAP_FRAMEWORK_PROGRAM_H_
3 3
 
4
+//System includes
5
+#include <string>
6
+
4 7
 // Local haders
5 8
 #include "platform_gl.h"
6 9
 
@@ -65,7 +68,7 @@ class Program {
65 68
          * (assumed to be NULL-terminated).
66 69
          */
67 70
         void build(
68
-                const GLchar* vertex_shader_source;
71
+                const GLchar* vertex_shader_source,
69 72
                 const GLchar* fragment_shader_source);
70 73
 };
71 74
 

+ 1
- 1
src/framework/Renderer.cc View File

@@ -8,7 +8,7 @@ Renderer::Renderer(int width, int height)
8 8
     // Initialize matrices with identity
9 9
     mat4x4_identity(projection_matrix_);
10 10
     mat4x4_identity(view_matrix_);
11
-};
11
+}
12 12
 
13 13
 
14 14
 Renderer::~Renderer(void) {

+ 5
- 0
src/platform/emscripten/CMakeLists.txt View File

@@ -1,6 +1,11 @@
1 1
 SET (CMAKE_CXX_COMPILER "em++")
2 2
 SET (CMAKE_USE_RELATIVE_PATHS TRUE)
3 3
 
4
+# Use C++11, use GLFW 3 and preload asset files, exposing them at the root
5
+SET (CMAKE_CXX_FLAGS "-std=c++11  -s USE_GLFW=3 --preload-file ${PROJECT_SOURCE_DIR}/res/raw/@/")
6
+# In debug, compile with warnings and pedantic
7
+SET (CMAKE_CXX_FLAGS_DEBUG "-Wall -pedantic")
8
+
4 9
 FILE (GLOB SKIMAP_PLATFORM_EMSCRIPTEN_SRC *.cc)
5 10
 
6 11
 add_executable (out.html

+ 12
- 9
src/platform/emscripten/main.cc View File

@@ -1,14 +1,16 @@
1 1
 // System includes
2 2
 #include <cstdlib>
3 3
 #include <cstdio>
4
-#include <GL/glfw.h>
4
+#define GLFW_INCLUDE_ES2
5
+#include <GLFW/glfw3.h>
5 6
 #include <emscripten/emscripten.h>
6 7
 
7 8
 // Local includes
8
-#include "Surface.h"
9
+#include "SkiMapRenderer.h"
9 10
 
10 11
 namespace {
11
-    SkiMapSurface* surface = NULL;
12
+    SkiMapRenderer* surface_ = NULL;
13
+    GLFWwindow* window_ = NULL;
12 14
 
13 15
     int init_gl(int width, int height) {
14 16
         if (glfwInit() != GL_TRUE) {
@@ -16,8 +18,9 @@ namespace {
16 18
             return GL_FALSE;
17 19
         }
18 20
 
19
-        if (glfwOpenWindow(width, height, 8, 8, 8, 8, 16, 0, GLFW_WINDOW) != GL_TRUE) {
20
-            printf("glfwOpenWindow() failed\n");
21
+        window_ = glfwCreateWindow(width, height, "SkiMap", NULL, NULL);
22
+        if (NULL == window_) {
23
+            // TODO[Error]
21 24
             return GL_FALSE;
22 25
         }
23 26
 
@@ -26,9 +29,9 @@ namespace {
26 29
 
27 30
 
28 31
     void do_frame(void) {
29
-        if (NULL != surface) {
30
-            surface->on_draw_frame();
31
-            glfwSwapBuffers();
32
+        if (NULL != surface_) {
33
+            surface_->on_draw_frame();
34
+            glfwSwapBuffers(window_);
32 35
         }
33 36
     }
34 37
 
@@ -44,7 +47,7 @@ int main()
44 47
     const int width = 480, height = 800;
45 48
 
46 49
 	if (GL_TRUE == init_gl(width, height)) {
47
-        surface = new SkiMapSurface(width, height);
50
+        surface_ = new SkiMapRenderer(width, height);
48 51
 		emscripten_set_main_loop(do_frame, 0, 1);
49 52
 	}
50 53
 

+ 5
- 0
src/platform/emscripten/platform_gl.h View File

@@ -1,2 +1,7 @@
1 1
 // Contains the path where the OpenGL headers are stored
2
+#ifndef SKIMAP_PLATFORM_EMSCRIPTEN_GL_H_
3
+#define SKIMAP_PLATFORM_EMSCRIPTEN_GL_H_
4
+
2 5
 #include <GLES2/gl2.h>
6
+
7
+#endif  // SKIMAP_PLATFORM_EMSCRIPTEN_GL_H_