Some fixes (still not functional)

This commit is contained in:
karl 2021-03-19 19:42:35 +01:00
parent 835520edb8
commit 641d77d2db
4 changed files with 35 additions and 5 deletions

View File

@ -6,14 +6,20 @@ MCRenderer::MCRenderer()
: render_shader(Shader("Shader/mc.vs", "Shader/mc.fs", "Shader/mc.gs")), : render_shader(Shader("Shader/mc.vs", "Shader/mc.fs", "Shader/mc.gs")),
noise_shader(Shader("Shader/noise.vs", "Shader/noise.fs")), noise(Framebuffer3D(64, 64, 64)), noise_shader(Shader("Shader/noise.vs", "Shader/noise.fs")), noise(Framebuffer3D(64, 64, 64)),
camera(Camera(90, 1920, 1080, 0.1, 100.0)) { camera(Camera(90, 1920, 1080, 0.1, 100.0)) {
float rectangle_data[6][2] = {{-1.0f, -1.0f}, {-1.0, 1.0}, {1.0, -1.0}, float rectangle_data[12] = {-1.0f, -1.0f, //
{1.0f, 1.0f}, {-1.0, 1.0}, {1.0, -1.0}}; -1.0, 1.0, //
1.0, -1.0, //
1.0f, 1.0f, //
-1.0, 1.0, //
1.0, -1.0};
vertex_rectangle.set_data(sizeof(rectangle_data), rectangle_data, 0); vertex_rectangle.set_data(6, rectangle_data, GL_STATIC_DRAW);
} }
void MCRenderer::render(float delta) { void MCRenderer::render(float delta) {
// Create the noise // Create the noise
glViewport(0, 0, 64, 64);
noise_shader.use(); noise_shader.use();
noise.bind_and_clear(); noise.bind_and_clear();
@ -30,11 +36,17 @@ void MCRenderer::render(float delta) {
// Actual rendering // Actual rendering
glViewport(0, 0, 1920, 1080); glViewport(0, 0, 1920, 1080);
render_shader.use();
// Bind the screen framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDrawBuffer(GL_BACK);
glClearColor(0.6f, 0.9f, 0.9f, 1.0f); glClearColor(0.6f, 0.9f, 0.9f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
render_shader.use(); // Set the camera position
camera.translate(glm::vec3(-32.0, -32.0, -32.0));
// Bind the camera to the rendering shader // Bind the camera to the rendering shader
render_shader.setMat4("proj", camera.get_projection()); render_shader.setMat4("proj", camera.get_projection());
@ -44,6 +56,7 @@ void MCRenderer::render(float delta) {
noise.bind_to(0); noise.bind_to(0);
// Draw all layers as polygons // Draw all layers as polygons
mc_points.bind();
glDrawArrays(GL_POINTS, 0, 64 * 64 * 64); glDrawArrays(GL_POINTS, 0, 64 * 64 * 64);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
} }

View File

@ -18,5 +18,7 @@ class MCRenderer {
Framebuffer3D noise; Framebuffer3D noise;
VertexBuffer vertex_rectangle; VertexBuffer vertex_rectangle;
VertexBuffer mc_points;
Camera camera; Camera camera;
}; };

View File

@ -8,11 +8,24 @@ VertexBuffer::VertexBuffer() {
void VertexBuffer::set_data(unsigned int size, const void *data, int flag) { void VertexBuffer::set_data(unsigned int size, const void *data, int flag) {
this->size = size; this->size = size;
glBindVertexArray(vertex_array);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, size, data, flag); glBufferData(GL_ARRAY_BUFFER, size, data, flag);
// TODO: Generalize
// This tells that the data consists of 2xfloat packets
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, false, 2 * sizeof(float), 0);
glBindVertexArray(0);
}
void VertexBuffer::bind() {
glBindVertexArray(vertex_array);
} }
void VertexBuffer::draw() { void VertexBuffer::draw() {
glBindVertexArray(vertex_array); bind();
glDrawArrays(GL_TRIANGLES, 0, size); glDrawArrays(GL_TRIANGLES, 0, size);
} }

View File

@ -12,6 +12,8 @@ class VertexBuffer {
void set_data(unsigned int size, const void *data, int flag); void set_data(unsigned int size, const void *data, int flag);
void bind();
void draw(); void draw();
private: private: