|
@@ -5,49 +5,40 @@
|
|
|
#include "MarchingCubes.h"
|
|
|
#include "gaming-core/utils/Array.h"
|
|
|
#include "gaming-core/utils/List.h"
|
|
|
-#include "gaming-core/utils/Random.h"
|
|
|
#include "gaming-core/utils/Utils.h"
|
|
|
#include "gaming-core/wrapper/GL.h"
|
|
|
|
|
|
-static GLuint texture3d;
|
|
|
-static float tData[16][16][16];
|
|
|
-
|
|
|
-Game::Game(Shader& shader, Buttons& buttons, const Size& size)
|
|
|
- : shader(shader), buttons(buttons), size(size),
|
|
|
- frustum(60, 0.1f, 1000.0f, size), up(buttons.add(GLFW_KEY_SPACE, "Up")),
|
|
|
+Game::Game(Shader& shader, Shader& noiceShader, LayeredFramebuffer& buffer,
|
|
|
+ Buttons& buttons, const Size& size)
|
|
|
+ : shader(shader), noiceShader(noiceShader), noiceBuffer(buffer),
|
|
|
+ buttons(buttons), size(size), frustum(60, 0.1f, 1000.0f, size),
|
|
|
+ up(buttons.add(GLFW_KEY_SPACE, "Up")),
|
|
|
down(buttons.add(GLFW_KEY_LEFT_SHIFT, "Down")),
|
|
|
left(buttons.add(GLFW_KEY_A, "left")),
|
|
|
right(buttons.add(GLFW_KEY_D, "right")),
|
|
|
front(buttons.add(GLFW_KEY_W, "front")),
|
|
|
back(buttons.add(GLFW_KEY_S, "back")) {
|
|
|
- shader.use();
|
|
|
-
|
|
|
- Random r(0);
|
|
|
- for(int x = 0; x < 16; x++) {
|
|
|
- for(int y = 0; y < 16; y++) {
|
|
|
- for(int z = 0; z < 16; z++) {
|
|
|
- float sinX = sinf(M_PI * x / 8.0f);
|
|
|
- float cosY = cosf(M_PI * y / 8.0f);
|
|
|
- float cosZ = cosf(M_PI * z / 8.0f);
|
|
|
- tData[z][x][y] =
|
|
|
- (sinX * sinX + cosY * cosY + cosZ * cosZ) * (1.0f / 3.0f);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- glGenTextures(1, &texture3d);
|
|
|
- glBindTexture(GL_TEXTURE_3D, texture3d);
|
|
|
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
|
|
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
|
|
|
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
|
|
- glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, 16, 16, 16, 0, GL_RED, GL_FLOAT,
|
|
|
- tData);
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
+ rectangleBuffer.setAttributes(Attributes().addFloat(2));
|
|
|
+ float 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}};
|
|
|
+ rectangleBuffer.setStaticData(sizeof(data), data);
|
|
|
+ noiceBuffer.bindTextureTo(0);
|
|
|
}
|
|
|
|
|
|
void Game::render(float lag) {
|
|
|
+ GL::setViewport(64, 64);
|
|
|
+ noiceShader.use();
|
|
|
+ noiceBuffer.bindAndClear();
|
|
|
+ for(int i = 0; i < 64; i++) {
|
|
|
+ noiceShader.setFloat("layer", i * (1.0f / 63.0f));
|
|
|
+ noiceBuffer.bindLayer(i);
|
|
|
+ rectangleBuffer.draw(6);
|
|
|
+ }
|
|
|
+
|
|
|
+ GL::setViewport(size.width, size.height);
|
|
|
+ shader.use();
|
|
|
+ GL::bindMainFramebuffer();
|
|
|
+ GL::clearFramebuffer();
|
|
|
Vector3 interPos = Utils::interpolate(oldPosition, position, lag);
|
|
|
shader.setMatrix("proj", frustum.updateProjection().getValues());
|
|
|
|
|
@@ -58,28 +49,30 @@ void Game::render(float lag) {
|
|
|
|
|
|
shader.setMatrix("view", m.getValues());
|
|
|
|
|
|
- vertexBuffer.drawPoints(0);
|
|
|
- glDrawArrays(GL_POINTS, 0, 16 * 16 * 16);
|
|
|
+ noiceBuffer.bindTextureTo(0);
|
|
|
+ emptyBuffer.drawPoints(0);
|
|
|
+ glDrawArrays(GL_POINTS, 0, 64 * 64 * 64);
|
|
|
}
|
|
|
|
|
|
void Game::tick() {
|
|
|
oldPosition = position;
|
|
|
+ const float speed = 2.5f;
|
|
|
if(up.isDown()) {
|
|
|
- position -= Vector3(0.0f, 0.5f, 0.0f);
|
|
|
+ position -= Vector3(0.0f, speed, 0.0f);
|
|
|
}
|
|
|
if(down.isDown()) {
|
|
|
- position += Vector3(0.0f, 0.5f, 0.0f);
|
|
|
+ position += Vector3(0.0f, speed, 0.0f);
|
|
|
}
|
|
|
if(left.isDown()) {
|
|
|
- position += Vector3(0.5f, 0.0f, 0.0f);
|
|
|
+ position += Vector3(speed, 0.0f, 0.0f);
|
|
|
}
|
|
|
if(right.isDown()) {
|
|
|
- position -= Vector3(0.5f, 0.0f, 0.0f);
|
|
|
+ position -= Vector3(speed, 0.0f, 0.0f);
|
|
|
}
|
|
|
if(front.isDown()) {
|
|
|
- position += Vector3(0.0f, 0.0f, 0.5f);
|
|
|
+ position += Vector3(0.0f, 0.0f, speed);
|
|
|
}
|
|
|
if(back.isDown()) {
|
|
|
- position -= Vector3(0.0f, 0.0f, 0.5f);
|
|
|
+ position -= Vector3(0.0f, 0.0f, speed);
|
|
|
}
|
|
|
}
|