generated from karl/cpp-template
Compare commits
No commits in common. "7a3e5364e09d56599f0cf5d7971dbee6ba7af192" and "fc4d263a2196f35fa8dc4ef5c9bd22da98391fa2" have entirely different histories.
7a3e5364e0
...
fc4d263a21
15
Input.h
15
Input.h
@ -1,15 +0,0 @@
|
|||||||
#include <map>
|
|
||||||
|
|
||||||
class Input {
|
|
||||||
|
|
||||||
public:
|
|
||||||
inline static std::map<int, bool> keys_down;
|
|
||||||
|
|
||||||
static void set_key_down(int key, bool down) {
|
|
||||||
keys_down[key] = down;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool is_key_down(int key) {
|
|
||||||
return keys_down[key];
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,6 +1,5 @@
|
|||||||
#include "MCRenderer.h"
|
#include "MCRenderer.h"
|
||||||
#include "Framebuffer3D.h"
|
#include "Framebuffer3D.h"
|
||||||
#include "Input.h"
|
|
||||||
#include "VertexBuffer.h"
|
#include "VertexBuffer.h"
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
|
|
||||||
@ -26,26 +25,7 @@ void MCRenderer::render(float delta) {
|
|||||||
noise_shader.use();
|
noise_shader.use();
|
||||||
noise.bind_and_clear();
|
noise.bind_and_clear();
|
||||||
|
|
||||||
if (Input::is_key_down(GLFW_KEY_E)) {
|
noise_shader.setFloat("height", 0);
|
||||||
height += delta;
|
|
||||||
}
|
|
||||||
if (Input::is_key_down(GLFW_KEY_Q)) {
|
|
||||||
height -= delta;
|
|
||||||
}
|
|
||||||
if (Input::is_key_down(GLFW_KEY_W)) {
|
|
||||||
camera.translate(glm::vec3(0.0, 0.0, -delta * 20.0));
|
|
||||||
}
|
|
||||||
if (Input::is_key_down(GLFW_KEY_S)) {
|
|
||||||
camera.translate(glm::vec3(0.0, 0.0, delta * 20.0));
|
|
||||||
}
|
|
||||||
if (Input::is_key_down(GLFW_KEY_D)) {
|
|
||||||
camera.rotate(-delta * 90.0, glm::vec3(0.0, 1.0, 0.0));
|
|
||||||
}
|
|
||||||
if (Input::is_key_down(GLFW_KEY_A)) {
|
|
||||||
camera.rotate(delta * 90.0, glm::vec3(0.0, 1.0, 0.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
noise_shader.setFloat("height", height);
|
|
||||||
|
|
||||||
for (int i = 0; i < size_z; i++) {
|
for (int i = 0; i < size_z; i++) {
|
||||||
// Create one layer
|
// Create one layer
|
||||||
@ -67,6 +47,9 @@ void MCRenderer::render(float delta) {
|
|||||||
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);
|
||||||
|
|
||||||
|
// Set the camera position
|
||||||
|
camera.rotate(delta, glm::vec3(0.0, 1.0, 0.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());
|
||||||
render_shader.setMat4("view", camera.get_view());
|
render_shader.setMat4("view", camera.get_view());
|
||||||
@ -84,5 +67,5 @@ void MCRenderer::render(float delta) {
|
|||||||
|
|
||||||
// Draw all layers as polygons
|
// Draw all layers as polygons
|
||||||
glDrawArrays(GL_POINTS, 0, size_x * size_y * size_z);
|
glDrawArrays(GL_POINTS, 0, size_x * size_y * size_z);
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, Input::is_key_down(GLFW_KEY_X) ? GL_LINE : GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
}
|
}
|
@ -16,8 +16,6 @@ class MCRenderer {
|
|||||||
int size_y;
|
int size_y;
|
||||||
int size_z;
|
int size_z;
|
||||||
|
|
||||||
float height = 0.0;
|
|
||||||
|
|
||||||
Shader render_shader;
|
Shader render_shader;
|
||||||
Shader noise_shader;
|
Shader noise_shader;
|
||||||
|
|
||||||
|
@ -5,16 +5,10 @@ in vec3 varPosition;
|
|||||||
out float noise;
|
out float noise;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
// Base: Distance to a helix
|
// Just to random stuff to the numbers until it looks nice
|
||||||
vec3 helix_pos = vec3(sin(varPosition.y * 5.0) * 0.2 + 0.5, varPosition.y, cos(varPosition.y * 5.0) * 0.2 + 0.5);
|
float f1 = sin((varPosition.x + varPosition.z) * 10.0);
|
||||||
float dist = distance(helix_pos, varPosition);
|
float f2 = cos((varPosition.y + varPosition.x) * 7.0);
|
||||||
|
|
||||||
noise = 0.6 - dist;
|
|
||||||
|
|
||||||
// Create some blobby shapes on the helix
|
|
||||||
float f1 = sin((varPosition.x + varPosition.z) * 7.0);
|
|
||||||
float f2 = cos((varPosition.y + varPosition.x) * 3.0);
|
|
||||||
float f3 = cos((varPosition.z + varPosition.y) * 8.0);
|
float f3 = cos((varPosition.z + varPosition.y) * 8.0);
|
||||||
|
|
||||||
noise += abs(f1 + f2 + f3) * 0.1;
|
noise = (f1 * f1 + f2 * f2 + f3 * f3) * (1.0 / 3.0);
|
||||||
}
|
}
|
||||||
|
22
main.cpp
22
main.cpp
@ -6,18 +6,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "Framebuffer3D.h"
|
#include "Framebuffer3D.h"
|
||||||
#include "Input.h"
|
|
||||||
#include "MCRenderer.h"
|
#include "MCRenderer.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
|
||||||
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
|
||||||
|
|
||||||
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) {
|
|
||||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GLFW_TRUE);
|
|
||||||
|
|
||||||
Input::set_key_down(key, action == GLFW_RELEASE ? false : true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
const unsigned int SCR_WIDTH = 1920;
|
const unsigned int SCR_WIDTH = 1920;
|
||||||
const unsigned int SCR_HEIGHT = 1080;
|
const unsigned int SCR_HEIGHT = 1080;
|
||||||
@ -51,9 +44,6 @@ int main() {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keyboard input processing function
|
|
||||||
glfwSetKeyCallback(window, key_callback);
|
|
||||||
|
|
||||||
// configure global opengl state
|
// configure global opengl state
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
@ -62,22 +52,16 @@ int main() {
|
|||||||
MCRenderer renderer = MCRenderer(128, 128, 128);
|
MCRenderer renderer = MCRenderer(128, 128, 128);
|
||||||
|
|
||||||
// render loop
|
// render loop
|
||||||
double timeInLastFrame = glfwGetTime();
|
// -----------
|
||||||
double elapsed_time = 0.0;
|
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
// Delta time handling
|
renderer.render(0.1); // TODO: Proper delta
|
||||||
double delta = glfwGetTime() - timeInLastFrame;
|
|
||||||
timeInLastFrame = glfwGetTime();
|
|
||||||
elapsed_time += delta;
|
|
||||||
|
|
||||||
renderer.render(delta);
|
|
||||||
|
|
||||||
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user