ADD: Apply Projection matrices
This commit is contained in:
parent
6f0d8852fa
commit
0871202db9
@ -6,9 +6,10 @@ in vec2 textureCoords;
|
||||
out vec2 pass_textureCoords;
|
||||
|
||||
uniform mat4 transformationMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = transformationMatrix * vec4(position, 1.0f);
|
||||
gl_Position = projectionMatrix * transformationMatrix * vec4(position, 1.0f);
|
||||
pass_textureCoords = textureCoords;
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ public:
|
||||
void close() {running = false;}
|
||||
|
||||
static Application& getInstance();
|
||||
[[nodiscard]] Window& getWindow() const {return *window;}
|
||||
private:
|
||||
bool running = true;
|
||||
std::unique_ptr<Window> window;
|
||||
|
||||
@ -36,7 +36,7 @@ void GameLayer::onAttach()
|
||||
RawModel model = loader.loadToVAO(vertices, textureCoords, indices);
|
||||
ModelTexture texture = ModelTexture(loader.loadTexture("assets/textures/texture.png"));
|
||||
texturedModel = TexturedModel(std::make_shared<RawModel>(model), std::make_shared<ModelTexture>(texture));
|
||||
entity = std::make_unique<Entity>(Entity(std::make_shared<TexturedModel>(texturedModel), glm::vec3(-1,0,0), 0,0,0, 1.f));
|
||||
entity = std::make_unique<Entity>(Entity(std::make_shared<TexturedModel>(texturedModel), glm::vec3(0,0,-1), 0,0,0, 1.f));
|
||||
}
|
||||
|
||||
void GameLayer::onDetach()
|
||||
@ -46,6 +46,7 @@ void GameLayer::onDetach()
|
||||
|
||||
void GameLayer::onUpdate()
|
||||
{
|
||||
entity->increasePosition(0,0,-0.002f);
|
||||
renderer.renderFrame(*entity);
|
||||
}
|
||||
|
||||
|
||||
@ -4,8 +4,10 @@
|
||||
|
||||
#include "Renderer.h"
|
||||
|
||||
#include "../core/Application.h"
|
||||
#include "../toolbox/MathUtils.h"
|
||||
#include "glad/glad.h"
|
||||
#include "glm/ext/matrix_clip_space.hpp"
|
||||
#include "model/TexturedModel.h"
|
||||
|
||||
void Renderer::prepare() {
|
||||
@ -38,3 +40,16 @@ void Renderer::renderRawModel(const Entity& entity) {
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
|
||||
glm::mat4 Renderer::createProjectionMatrix() {
|
||||
float aspectRatio = static_cast<float>(Application::getInstance().getWindow().GetWidth()) / static_cast<float>(Application::getInstance().getWindow().GetHeight());
|
||||
|
||||
glm::mat4 projection = glm::perspective(
|
||||
glm::radians(FOV),
|
||||
aspectRatio,
|
||||
NEAR_PLANE,
|
||||
FAR_PLANE
|
||||
);
|
||||
|
||||
return projection;
|
||||
}
|
||||
|
||||
@ -12,11 +12,23 @@
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
Renderer() : projectionMatrix(createProjectionMatrix()) {
|
||||
staticShader.start();
|
||||
staticShader.loadProjectionMatrix(projectionMatrix);
|
||||
staticShader.stop();
|
||||
};
|
||||
void prepare();
|
||||
void renderFrame(const Entity &entity);
|
||||
private:
|
||||
void renderRawModel(const Entity &entity);
|
||||
StaticShader staticShader;
|
||||
|
||||
glm::mat4 projectionMatrix;
|
||||
constexpr static float FOV = 70.0f;
|
||||
constexpr static float NEAR_PLANE = 0.1f;
|
||||
constexpr static float FAR_PLANE = 1000.0f;
|
||||
|
||||
static glm::mat4 createProjectionMatrix();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -13,6 +13,10 @@ void StaticShader::loadTransformationMatrix(glm::mat4 matrix) {
|
||||
loadMatrix(location_transformationMatrix, matrix);
|
||||
}
|
||||
|
||||
void StaticShader::loadProjectionMatrix(glm::mat4 matrix) {
|
||||
loadMatrix(location_projectionMatrix, matrix);
|
||||
}
|
||||
|
||||
void StaticShader::bindAttributes() const {
|
||||
bindAttribute(0, "position");
|
||||
bindAttribute(1, "textureCoords");
|
||||
@ -20,6 +24,7 @@ void StaticShader::bindAttributes() const {
|
||||
|
||||
void StaticShader::getAllUniformLocations() {
|
||||
location_transformationMatrix = getUniformLocation("transformationMatrix");
|
||||
location_projectionMatrix = getUniformLocation("projectionMatrix");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -12,11 +12,13 @@ class StaticShader: public ShaderProgram
|
||||
public:
|
||||
StaticShader();
|
||||
void loadTransformationMatrix(glm::mat4 matrix);
|
||||
void loadProjectionMatrix(glm::mat4 matrix);
|
||||
private:
|
||||
inline static const std::string VERTEX_FILE = "assets/shaders/vertexShader.glsl";
|
||||
inline static const std::string FRAGMENT_FILE = "assets/shaders/fragmentShader.glsl";
|
||||
|
||||
int location_transformationMatrix;
|
||||
int location_projectionMatrix;
|
||||
|
||||
protected:
|
||||
void bindAttributes() const override;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user