forked from Hopson97/Minecraft-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Episode 27 - Chunk Renderer and Shader
- Loading branch information
Showing
12 changed files
with
148 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#version 330 | ||
|
||
out vec4 colour; | ||
|
||
in vec2 passTextureCoords; | ||
|
||
uniform sampler2D ourTexture; | ||
|
||
uniform float time; | ||
|
||
void main() | ||
{ | ||
colour = texture(ourTexture, passTextureCoords); | ||
} |
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,18 @@ | ||
#version 330 | ||
|
||
layout (location = 0) in vec3 inVertexPosition; | ||
layout (location = 1) in vec2 inTextureCoords; | ||
|
||
out vec2 passTextureCoords; | ||
|
||
uniform mat4 viewMatrix; | ||
uniform mat4 projMatrix; | ||
|
||
void main() | ||
{ | ||
gl_Position = projMatrix * viewMatrix * | ||
vec4 (inVertexPosition.xyz, | ||
1.0); | ||
|
||
passTextureCoords = inTextureCoords; | ||
} |
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,28 @@ | ||
#include "RChunk.h" | ||
|
||
#include "../Camera.h" | ||
#include "../World/Chunk/Chunk_Section.h" | ||
|
||
namespace Renderer | ||
{ | ||
void Chunk_Renderer::draw(const Chunk::Chunk_Section& chunk) | ||
{ | ||
m_chunks.push_back(&chunk); | ||
} | ||
|
||
void Chunk_Renderer::update(const Camera& camera) | ||
{ | ||
m_shader.bind(); | ||
|
||
m_shader.setViewMatrix(camera.getViewMatrix()); | ||
m_shader.setProjMatrix(camera.getProjectionMatrix()); | ||
|
||
for (auto& chunk : m_chunks) | ||
{ | ||
|
||
} | ||
|
||
m_chunks.clear(); | ||
} | ||
|
||
} |
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,32 @@ | ||
#ifndef RCHUNK_H_INCLUDED | ||
#define RCHUNK_H_INCLUDED | ||
|
||
#include <vector> | ||
#include <SFML/System/Clock.hpp> | ||
|
||
#include "../Shaders/Chunk_Shader.h" | ||
|
||
namespace Chunk | ||
{ | ||
class Chunk_Section; | ||
} | ||
|
||
struct Camera; | ||
|
||
namespace Renderer | ||
{ | ||
class Chunk_Renderer | ||
{ | ||
public: | ||
void draw (const Chunk::Chunk_Section& chunk); | ||
|
||
void update(const Camera& camera); | ||
|
||
private: | ||
std::vector<const Chunk::Chunk_Section*> m_chunks; | ||
|
||
Shader::Chunk_Shader m_shader; | ||
}; | ||
} | ||
|
||
#endif // RCHUNK_H_INCLUDED |
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,13 @@ | ||
#include "Chunk_Shader.h" | ||
|
||
namespace Shader | ||
{ | ||
Chunk_Shader::Chunk_Shader() | ||
: Simple_Shader ("Chunk_Vertex", "Chunk_Fragment") | ||
{ | ||
getUniformLocations(); | ||
} | ||
|
||
void Chunk_Shader::getUniformLocations() | ||
{ } | ||
} |
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,18 @@ | ||
#ifndef CHUNK_SHADER_H_INCLUDED | ||
#define CHUNK_SHADER_H_INCLUDED | ||
|
||
#include "Simple_Shader.h" | ||
|
||
namespace Shader | ||
{ | ||
class Chunk_Shader : public Simple_Shader | ||
{ | ||
public: | ||
Chunk_Shader(); | ||
|
||
private: | ||
void getUniformLocations() override; | ||
}; | ||
} | ||
|
||
#endif // CHUNK_SHADER_H_INCLUDED |
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