3D ski maps. WIP.

Terrain.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef SKIMAP_CORE_TERRAIN_H_
  2. #define SKIMAP_CORE_TERRAIN_H_
  3. // System includes
  4. #include <vector>
  5. // 3rd party includes
  6. #include "linmath/linmath.h"
  7. // Local haders
  8. #include "platform_gl.h"
  9. #include "Heightmap.h"
  10. #include "Program.h"
  11. namespace terrain_shader {
  12. typedef struct {
  13. vec3 direction;
  14. vec3 halfplane;
  15. vec4 ambient_color;
  16. vec4 diffuse_color;
  17. vec4 specular_color;
  18. } DirectionalLight_t;
  19. typedef struct {
  20. vec4 ambient_factor;
  21. vec4 diffuse_factor;
  22. vec4 specular_factor;
  23. GLfloat shininess;
  24. } Material_t;
  25. }
  26. class TerrainProgram: public Program {
  27. public:
  28. /**
  29. * Construct a TerrainProgram object, loading shaders from the given
  30. * source files.
  31. *
  32. * @param vertex_shader_filename Path to the vertex shader file.
  33. * @param fragment_shader_filename Path to the fragment shader file.
  34. */
  35. explicit TerrainProgram(
  36. const std::string vertex_shader_filename,
  37. const std::string fragment_shader_filename);
  38. /**
  39. * Getter for the locations of the uniforms and attributes in the shader.
  40. */
  41. GLint get_location(const GLchar* uniform_or_attrib) const;
  42. };
  43. class Terrain {
  44. public:
  45. /**
  46. * Construct a Terrain object.
  47. *
  48. * @param vertex_shader_filename Path to the vertex shader file, to
  49. * pass to the TerrainProgram constructor.
  50. * @param fragment_shader_filename Path to the fragment shader file, to
  51. * pass to the TerrainProgram constructor.
  52. * @see TerrainProgram::TerrainProgram
  53. */
  54. explicit Terrain(
  55. const std::string vertex_shader_filename,
  56. const std::string fragment_shader_filename);
  57. /**
  58. * Actually draw the terrain.
  59. *
  60. * @param view_matrix the view matrix passed by the renderer.
  61. * @param projection_matrix the view matrix passed by the renderer.
  62. * @param directional_light the directional light structure to pass
  63. * to the shader.
  64. */
  65. void draw(
  66. mat4x4 view_matrix,
  67. mat4x4 projection_matrix,
  68. terrain_shader::DirectionalLight_t directional_light);
  69. private:
  70. TerrainProgram program_; /**< Shaders program associated with terrain. */
  71. terrain_shader::Material_t material_; /**< Terrain material. */
  72. mat4x4 model_matrix_; /**< Model matrix to position the terrain. */
  73. Heightmap heightmap_; /** The actual terrain data. */
  74. GLuint buffer_id_; /**< GL id of the buffer to store the terrain data. */
  75. int buffer_length_; /**< The length of the buffer to store the terrain data. */
  76. };
  77. #endif // SKIMAP_CORE_TERRAIN_H_