-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a basic grid renderer for XZ plane. #56
- Loading branch information
1 parent
90ee242
commit c288758
Showing
7 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#version 330 core | ||
|
||
in vec4 FragmentColour; | ||
out vec4 Colour; | ||
|
||
void main() | ||
{ | ||
Colour = FragmentColour; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#version 420 core | ||
|
||
layout (location = 0) in vec3 VertexPosition; | ||
|
||
layout(shared) uniform ViewProperties | ||
{ | ||
mat4 view; | ||
mat4 projection; | ||
} viewProperties; | ||
|
||
uniform vec4 colour; | ||
|
||
out vec4 FragmentColour; | ||
|
||
void main() | ||
{ | ||
gl_Position = viewProperties.projection * viewProperties.view * vec4(VertexPosition, 1.0); | ||
FragmentColour = colour; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "GridRenderer.hpp" | ||
|
||
namespace OpenGL | ||
{ | ||
GridRenderer::GridRenderer() noexcept | ||
: m_line_points{} | ||
, m_colour{1.f, 1.f, 1.f, 0.7f} | ||
, m_grid_shader{"grid"} | ||
, m_line_VAO{} | ||
, m_line_VBO{} | ||
{ | ||
constexpr int Count = 1000; | ||
constexpr int Size = 100; // #Todo Should be camera z-far | ||
m_line_points.reserve(Count * 8); | ||
|
||
// XZ-plane | ||
for (auto i = -Count; i <= Count; i++) | ||
{ | ||
m_line_points.push_back({glm::vec3{-Size, 0.f, i}}); | ||
m_line_points.push_back({glm::vec3{Size, 0.f, i}}); | ||
m_line_points.push_back({glm::vec3{i, 0.f, Size}}); | ||
m_line_points.push_back({glm::vec3{i, 0.f, -Size}}); | ||
} | ||
|
||
m_line_VAO.bind(); | ||
m_line_VBO.set_data(m_line_points); | ||
} | ||
void GridRenderer::draw() | ||
{ | ||
if (!m_line_points.empty()) | ||
{ | ||
m_grid_shader.use(); | ||
m_grid_shader.set_uniform("colour", m_colour); | ||
toggle_cull_face(false); | ||
set_depth_test(true); | ||
set_depth_test_type(DepthTestType::Less); | ||
set_polygon_mode(PolygonMode::Fill); | ||
|
||
m_line_VAO.bind(); | ||
m_line_VBO.bind(); | ||
draw_arrays(PrimitiveMode::Lines, 0, static_cast<GLsizei>(m_line_points.size() * 2)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "OpenGL/Types.hpp" | ||
#include "OpenGL/Shader.hpp" | ||
|
||
#include "glm/vec3.hpp" | ||
#include "glm/vec4.hpp" | ||
|
||
#include <array> | ||
#include <vector> | ||
|
||
namespace OpenGL | ||
{ | ||
class GridRenderer | ||
{ | ||
struct GridVert | ||
{ | ||
constexpr inline static std::array<VertexAttribute, 1> Attributes = { VertexAttribute::Position3D }; | ||
glm::vec3 m_position = glm::vec3{0.f}; | ||
}; | ||
|
||
std::vector<GridVert> m_line_points; | ||
glm::vec4 m_colour; | ||
Shader m_grid_shader; | ||
VAO m_line_VAO; | ||
VBO m_line_VBO; | ||
|
||
public: | ||
GridRenderer() noexcept; | ||
void draw(); | ||
}; | ||
} |