diff --git a/src/game.cpp b/src/game.cpp index 1ac05a5..27bb59c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -34,7 +34,7 @@ void Game::Setup(int w, int h) { #endif *m_logger << LOGGER_INFO << "Initializing display" << LOGGER_ENDL; - SDL_Init(SDL_INIT_EVERYTHING); + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); diff --git a/src/renderer/camera.cpp b/src/renderer/camera.cpp index 973cc70..0da4d09 100644 --- a/src/renderer/camera.cpp +++ b/src/renderer/camera.cpp @@ -1,6 +1,9 @@ #include "camera.hpp" -Camera::Camera() { +Camera::Camera(int w, int h) { + + projMatrix = glm::perspective(glm::radians(45.0f), (float)w / float(h), 0.1f, 1000.0f); + roll = 0.0f; pitch = 0.0f; yaw = 0.0f; @@ -32,6 +35,10 @@ glm::mat4 Camera::GetViewMatrix() { return viewMatrix; } +glm::mat4 Camera::GetProjectionMatrix() { + return projMatrix; +} + glm::vec3 Camera::GetPos() { return eyeVector; } diff --git a/src/renderer/camera.hpp b/src/renderer/camera.hpp index 5e8d28b..4e8ab79 100644 --- a/src/renderer/camera.hpp +++ b/src/renderer/camera.hpp @@ -5,10 +5,11 @@ class Camera { public: - Camera(); + Camera(int w, int h); void UpdateView(); glm::mat4 GetViewMatrix(); + glm::mat4 GetProjectionMatrix(); glm::vec3 GetPos(); void HandleMouse(SDL_Event e); @@ -21,7 +22,10 @@ public: private: float roll, pitch, yaw; glm::vec3 eyeVector = {}; + glm::mat4 viewMatrix = {}; + glm::mat4 projMatrix = {}; + }; #endif diff --git a/src/renderer/face.cpp b/src/renderer/face.cpp index 8a7f449..67f22a0 100644 --- a/src/renderer/face.cpp +++ b/src/renderer/face.cpp @@ -3,7 +3,7 @@ #include "shader.hpp" #include "camera.hpp" -Face::Face(FaceDirection direction, int textureID, int asdf) { +Face::Face(FaceDirection direction, int textureID) { Direction = direction; Texture = textureID; @@ -103,8 +103,6 @@ Face::Face(FaceDirection direction, int textureID, int asdf) { } - m_vao = asdf; - glGenVertexArrays(1, &m_vao); glBindVertexArray(m_vao); @@ -135,29 +133,18 @@ Face::Face(FaceDirection direction, int textureID, int asdf) { } -void Face::GetMesh(std::vector& verts, std::vector& uvs) { - -} - -void Face::Render(std::shared_ptr camera, std::shared_ptr shader) { - - shader->Use(); - glBindVertexArray(m_vao); - - glm::mat4 model = glm::mat4(1.0f); - GLint uniTrans = glGetUniformLocation(shader->Program, "model"); - glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(model)); - - GLint uniView = glGetUniformLocation(shader->Program, "view"); - glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(camera->GetViewMatrix())); - - // Projection matrice - glm::mat4 proj = glm::perspective(glm::radians(45.0f), 1080.0f / 720.0f, 0.1f, 1000.0f); - // Get uniform and send it to the GPU - GLint uniProj = glGetUniformLocation(shader->Program, "proj"); - glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(proj)); - - - glDrawArrays(GL_TRIANGLES, 0, m_verticies.size()); +void Face::GetMesh(std::vector& verts, std::vector& uvs) { + + verts = m_verticies; + + std::vector UVs; + + for (auto& uv : m_uvs) { + + UVs.push_back({ uv.x, uv.y, (float)Texture }); + + } + + uvs = UVs; } diff --git a/src/renderer/face.hpp b/src/renderer/face.hpp index 3ce0ca0..946963a 100644 --- a/src/renderer/face.hpp +++ b/src/renderer/face.hpp @@ -17,10 +17,9 @@ enum FaceDirection { class Face { public: - Face(FaceDirection direction, int textureID, int id); + Face(FaceDirection direction, int textureID); - void GetMesh(std::vector& verts, std::vector& uvs); - void Render(std::shared_ptr camera, std::shared_ptr shader); + void GetMesh(std::vector& verts, std::vector& uvs); int Texture = 0; @@ -31,9 +30,6 @@ private: std::vector m_verticies; std::vector m_uvs; - GLuint m_vao = 0; - GLuint m_vbo = 0; - }; #endif diff --git a/src/renderer/voxel.cpp b/src/renderer/voxel.cpp index e69de29..edac215 100644 --- a/src/renderer/voxel.cpp +++ b/src/renderer/voxel.cpp @@ -0,0 +1,32 @@ +#include "voxel.hpp" + +#include "shader.hpp" +#include "camera.hpp" + +#include "face.hpp" + +Voxel::Voxel(int x, int y, int z) { + + m_model = glm::translate(glm::mat4(1.0f), { (float)x, (float)y, (float)z }); + + + +} + +void Voxel::Render(std::shared_ptr camera, std::shared_ptr shader) { + + shader->Use(); + glBindVertexArray(m_vao); + + GLint uniTrans = glGetUniformLocation(shader->Program, "model"); + glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(m_model)); + + GLint uniView = glGetUniformLocation(shader->Program, "view"); + glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(camera->GetViewMatrix())); + + GLint uniProj = glGetUniformLocation(shader->Program, "proj"); + glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(camera->GetProjectionMatrix())); + + glDrawArrays(GL_TRIANGLES, 0, m_verticies.size()); + +} diff --git a/src/renderer/voxel.hpp b/src/renderer/voxel.hpp index 5977763..ec92b05 100644 --- a/src/renderer/voxel.hpp +++ b/src/renderer/voxel.hpp @@ -1,7 +1,26 @@ #ifndef MINECRAFT_RENDERER_VOXEL_H_ #define MINECRAFT_RENDERER_VOXEL_H_ +#include "../common.hpp" + +class Camera; +class Shader; + +class Face; + class Voxel { + Voxel(int x, int y, int z); + + void Render(std::shared_ptr camera, std::shared_ptr shader); + +private: + + GLuint m_vao = 0; + GLuint m_vbo = 0; + + glm::mat4 m_model; + + };