generated from karl/cpp-template
Some fixes (still not functional)
This commit is contained in:
parent
835520edb8
commit
641d77d2db
@ -6,14 +6,20 @@ MCRenderer::MCRenderer()
|
||||
: 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)),
|
||||
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},
|
||||
{1.0f, 1.0f}, {-1.0, 1.0}, {1.0, -1.0}};
|
||||
float rectangle_data[12] = {-1.0f, -1.0f, //
|
||||
-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) {
|
||||
// Create the noise
|
||||
glViewport(0, 0, 64, 64);
|
||||
|
||||
noise_shader.use();
|
||||
noise.bind_and_clear();
|
||||
|
||||
@ -30,11 +36,17 @@ void MCRenderer::render(float delta) {
|
||||
|
||||
// Actual rendering
|
||||
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);
|
||||
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
|
||||
render_shader.setMat4("proj", camera.get_projection());
|
||||
@ -44,6 +56,7 @@ void MCRenderer::render(float delta) {
|
||||
noise.bind_to(0);
|
||||
|
||||
// Draw all layers as polygons
|
||||
mc_points.bind();
|
||||
glDrawArrays(GL_POINTS, 0, 64 * 64 * 64);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
@ -18,5 +18,7 @@ class MCRenderer {
|
||||
Framebuffer3D noise;
|
||||
VertexBuffer vertex_rectangle;
|
||||
|
||||
VertexBuffer mc_points;
|
||||
|
||||
Camera camera;
|
||||
};
|
||||
|
@ -8,11 +8,24 @@ VertexBuffer::VertexBuffer() {
|
||||
void VertexBuffer::set_data(unsigned int size, const void *data, int flag) {
|
||||
this->size = size;
|
||||
|
||||
glBindVertexArray(vertex_array);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
|
||||
|
||||
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() {
|
||||
glBindVertexArray(vertex_array);
|
||||
bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, size);
|
||||
}
|
@ -12,6 +12,8 @@ class VertexBuffer {
|
||||
|
||||
void set_data(unsigned int size, const void *data, int flag);
|
||||
|
||||
void bind();
|
||||
|
||||
void draw();
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user