voxeling and that
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<glm::vec3>& verts, std::vector<glm::vec2>& uvs) {
|
||||
|
||||
}
|
||||
|
||||
void Face::Render(std::shared_ptr<Camera> camera, std::shared_ptr<Shader> 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<glm::vec3>& verts, std::vector<glm::vec3>& uvs) {
|
||||
|
||||
verts = m_verticies;
|
||||
|
||||
std::vector<glm::vec3> UVs;
|
||||
|
||||
for (auto& uv : m_uvs) {
|
||||
|
||||
UVs.push_back({ uv.x, uv.y, (float)Texture });
|
||||
|
||||
}
|
||||
|
||||
uvs = UVs;
|
||||
|
||||
}
|
||||
|
||||
@@ -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<glm::vec3>& verts, std::vector<glm::vec2>& uvs);
|
||||
void Render(std::shared_ptr<Camera> camera, std::shared_ptr<Shader> shader);
|
||||
void GetMesh(std::vector<glm::vec3>& verts, std::vector<glm::vec3>& uvs);
|
||||
|
||||
int Texture = 0;
|
||||
|
||||
@@ -31,9 +30,6 @@ private:
|
||||
std::vector<glm::vec3> m_verticies;
|
||||
std::vector<glm::vec2> m_uvs;
|
||||
|
||||
GLuint m_vao = 0;
|
||||
GLuint m_vbo = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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> camera, std::shared_ptr<Shader> 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());
|
||||
|
||||
}
|
||||
|
||||
@@ -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> camera, std::shared_ptr<Shader> shader);
|
||||
|
||||
private:
|
||||
|
||||
GLuint m_vao = 0;
|
||||
GLuint m_vbo = 0;
|
||||
|
||||
glm::mat4 m_model;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user