Compare commits
2 Commits
6dc659a4e2
...
9ffb3c116a
Author | SHA1 | Date | |
---|---|---|---|
9ffb3c116a | |||
b8a0410d25 |
@ -1,29 +0,0 @@
|
|||||||
#include "chunk.hpp"
|
|
||||||
|
|
||||||
namespace polygun::engine {
|
|
||||||
Chunk::Chunk() {
|
|
||||||
for (int x = 0; x < CHUNK_SIZE; x++) {
|
|
||||||
for (int y = 0; y < CHUNK_SIZE; y++) {
|
|
||||||
for (int z = 0; z < CHUNK_SIZE; z++) {
|
|
||||||
chunk_data[x][y][z] = 1 ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Chunk::~Chunk() {
|
|
||||||
delete chunk_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Chunk::add_node(int node_to_add, glm::vec3 pos) {
|
|
||||||
chunk_data[(int)pos.x][(int)pos.y][(int)pos.z] = node_to_add;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Chunk::is_air(glm::vec3 pos) {
|
|
||||||
return chunk_data[(int)pos.x][(int)pos.y][(int)pos.z] == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Chunk::get_node(glm::vec3 pos) {
|
|
||||||
return chunk_data[(int)pos.x][(int)pos.y][(int)pos.z];
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "../audio/audio.hpp"
|
#include "../audio/audio.hpp"
|
||||||
|
|
||||||
#include "chunk_renderer.hpp"
|
#include "game/world/chunk_renderer.hpp"
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include "vendor/imgui.h"
|
#include "vendor/imgui.h"
|
||||||
@ -230,6 +230,7 @@ namespace polygun::engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// imgui
|
// imgui
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
0
src/game/renderer/mesh.cpp
Normal file
0
src/game/renderer/mesh.cpp
Normal file
10
src/game/renderer/mesh.hpp
Normal file
10
src/game/renderer/mesh.hpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef POLUGUN_RENDERER_MESH_HPP
|
||||||
|
#define POLUGUN_RENDERER_MESH_HPP
|
||||||
|
|
||||||
|
#include "../core.hpp"
|
||||||
|
|
||||||
|
namespace polygun::renderer {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // POLUGUN_RENDERER_MESH_HPP
|
76
src/game/renderer/vertex_array.hpp
Normal file
76
src/game/renderer/vertex_array.hpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#ifndef POLYGUN_RENDERER_VERTEX_ARRAY_HPP
|
||||||
|
#define POLYGUN_RENDERER_VERTEX_ARRAY_HPP
|
||||||
|
|
||||||
|
#include "../core.hpp"
|
||||||
|
|
||||||
|
namespace polygun::renderer {
|
||||||
|
class VertexArray {
|
||||||
|
public:
|
||||||
|
VertexArray(): m_vao(0), m_ebo(0), m_vbo(0), m_num_of_indices(0),
|
||||||
|
m_num_of_vertices(0) {}
|
||||||
|
|
||||||
|
VertexArray(Vertex* vertices, GLsizei v_size, GLuint* indices = nullptr, GLsizei i_size = 0):
|
||||||
|
m_num_of_indices(i_size), m_num_of_vertices(v_size) {
|
||||||
|
glGenVertexArrays(1, &m_vao);
|
||||||
|
glGenBuffers(1, &m_vbo);
|
||||||
|
glGenBuffers(1, &m_ebo);
|
||||||
|
|
||||||
|
glBindVertexArray(m_vao);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, m_num_of_vertices * sizeof(Vertex), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ebo);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_num_of_indices * sizeof(GLuint), indices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
// Positions
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)0);
|
||||||
|
// Normals
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, Normal));
|
||||||
|
// Texcoords
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, TexCoords));
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
m_num_of_vertices /= sizeof(Vertex);
|
||||||
|
}
|
||||||
|
|
||||||
|
~VertexArray() {
|
||||||
|
glDeleteVertexArrays(1, &m_vao);
|
||||||
|
glDeleteBuffers(1, &m_vbo);
|
||||||
|
glDeleteBuffers(1, &m_ebo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_attrib(GLuint index, GLint size, GLsizei stride, GLvoid* ptr) {
|
||||||
|
glEnableVertexAttribArray(index);
|
||||||
|
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, size, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bind() {
|
||||||
|
GLCALL(glBindVertexArray(m_vao));
|
||||||
|
}
|
||||||
|
|
||||||
|
void unbind() {
|
||||||
|
GLCALL(glBindVertexArray(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_elements(GLenum mode = GL_TRIANGLE_STRIP) {
|
||||||
|
GLCALL(glBindVertexArray(m_vao));
|
||||||
|
GLCALL(glDrawElements(mode, m_num_of_indices, GL_UNSIGNED_INT, 0));
|
||||||
|
GLCALL(glBindVertexArray(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_arrays(GLenum mode = GL_TRIANGLES) {
|
||||||
|
GLCALL(glBindVertexArray(m_vao));
|
||||||
|
GLCALL(glDrawArrays(mode, 0, m_num_of_vertices));
|
||||||
|
GLCALL(glBindVertexArray(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
GLuint m_vao, m_vbo, m_ebo;
|
||||||
|
GLsizei m_num_of_indices, m_num_of_vertices;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // POLYGUN_RENDERER_VERTEX_ARRAY_HPP
|
71
src/game/world/chunk.cpp
Normal file
71
src/game/world/chunk.cpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include "chunk.hpp"
|
||||||
|
|
||||||
|
namespace polygun::engine {
|
||||||
|
Chunk::Chunk() {
|
||||||
|
for (int x = 0; x < CHUNK_SIZE; x++) {
|
||||||
|
for (int y = 0; y < CHUNK_SIZE; y++) {
|
||||||
|
for (int z = 0; z < CHUNK_SIZE; z++) {
|
||||||
|
chunk_data[x][y][z] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Chunk::~Chunk() {
|
||||||
|
delete chunk_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chunk::add_node(int node_to_add, glm::vec3 pos) {
|
||||||
|
chunk_data[(int)pos.x][(int)pos.y][(int)pos.z] = node_to_add;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Chunk::is_air(glm::vec3 pos) {
|
||||||
|
return chunk_data[(int)pos.x][(int)pos.y][(int)pos.z] == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Chunk::get_node(glm::vec3 pos) {
|
||||||
|
return chunk_data[(int)pos.x][(int)pos.y][(int)pos.z];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Chunk::is_neighbour_air(glm::vec3 pos) {
|
||||||
|
if (pos.x+1 == CHUNK_SIZE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (pos.x-1 == CHUNK_SIZE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (pos.y+1 == CHUNK_SIZE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (pos.y-1 == CHUNK_SIZE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (pos.z+1 == CHUNK_SIZE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (pos.z-1 == CHUNK_SIZE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos.x+1 == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (pos.x-1 == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (pos.y+1 == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (pos.y-1 == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (pos.z+1 == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (pos.z-1 == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ namespace polygun::engine {
|
|||||||
void add_node(int node_to_add, glm::vec3 pos);
|
void add_node(int node_to_add, glm::vec3 pos);
|
||||||
bool is_air(glm::vec3 pos);
|
bool is_air(glm::vec3 pos);
|
||||||
int get_node(glm::vec3 pos);
|
int get_node(glm::vec3 pos);
|
||||||
|
bool is_neighbour_air(glm::vec3 pos);
|
||||||
|
|
||||||
static const int CHUNK_SIZE = 32;
|
static const int CHUNK_SIZE = 32;
|
||||||
|
|
@ -2,7 +2,7 @@
|
|||||||
#define POLYGUN_ENGINE_CHUNK_RENDERER_HPP
|
#define POLYGUN_ENGINE_CHUNK_RENDERER_HPP
|
||||||
|
|
||||||
#include "chunk.hpp"
|
#include "chunk.hpp"
|
||||||
#include "engine.hpp"
|
#include "game/engine/engine.hpp"
|
||||||
|
|
||||||
namespace polygun::engine {
|
namespace polygun::engine {
|
||||||
class ChunkRenderer {
|
class ChunkRenderer {
|
Loading…
x
Reference in New Issue
Block a user