Further separate the render logic and the scene logic

With some cleanup
This commit is contained in:
Peder Bergebakken Sundt 2019-03-28 09:36:37 +01:00
parent 74ffe23551
commit 383d5d3f62
3 changed files with 10 additions and 16 deletions

View File

@ -32,6 +32,8 @@ void runProgram(GLFWwindow* window, CommandLineOptions options)
glClearColor(0.3f, 0.5f, 0.8f, 1.0f);
initRenderer(window, options);
init_scene(options);
getTimeDeltaSeconds();
// Rendering Loop
while (!glfwWindowShouldClose(window))
@ -42,6 +44,8 @@ void runProgram(GLFWwindow* window, CommandLineOptions options)
int w, h;
glfwGetWindowSize(window, &w, &h);
step_scene(getTimeDeltaSeconds());
updateFrame(window, w, h);
renderFrame(window, w, h);

View File

@ -3,7 +3,6 @@
#include <GLFW/glfw3.h>
#include <SFML/Audio/Sound.hpp>
#include <SFML/Audio/SoundBuffer.hpp>
#include <chrono>
#include <glad/glad.h>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
@ -13,7 +12,6 @@
#include <algorithm>
#include <utilities/glfont.h>
#include <utilities/shader.hpp>
#include <utilities/timeutils.h>
using glm::vec3;
using glm::vec4;
@ -51,11 +49,6 @@ void initRenderer(GLFWwindow* window, CommandLineOptions options) {
}
glfwSetCursorPosCallback(window, mouse_callback);
init_scene(options);
// init
getTimeDeltaSeconds();
}
// traverses and updates matricies
@ -81,12 +74,8 @@ void updateNodeTransformations(SceneNode* node, mat4 transformationThusFar, mat4
// step
void updateFrame(GLFWwindow* window, int windowWidth, int windowHeight) {
double timeDelta = getTimeDeltaSeconds();
float aspect = float(windowWidth) / float(windowHeight);
// main action:
step_scene(timeDelta);
// calculate camera
mat4 projection = glm::perspective(
glm::radians(45.0f), // fovy
@ -185,7 +174,9 @@ void renderNode(SceneNode* node, Gloom::Shader* parent_shader, vector<NodeDistSh
}
else if(node->vertexArrayObjectID != -1) {
// load uniforms
um4fv(MVP); um4fv(MV); um4fv(MVnormal);
um4fv(MVP);
um4fv(MV);
um4fv(MVnormal);
u2fv (uvOffset);
u3fv (diffuse_color);
u3fv (emissive_color);
@ -263,7 +254,7 @@ void renderFrame(GLFWwindow* window, int windowWidth, int windowHeight) {
//glDisable(GL_DEPTH_TEST);
for (NodeDistShader a : transparent_nodes)
renderNode(a.node, a.s, nullptr, false);
std::cout << transparent_nodes.size() << std::endl;
//std::cout << transparent_nodes.size() << std::endl;
glDepthMask(GL_TRUE); // read write
//glEnable(GL_DEPTH_TEST);

View File

@ -53,7 +53,6 @@ PNGImage t_cobble_normal = loadPNGFile("../res/textures/cobble_normal.png");
PNGImage t_plain_diff = loadPNGFile("../res/textures/plain_diff.png");
PNGImage t_plain_normal = loadPNGFile("../res/textures/plain_normal.png", true);
PNGImage t_reflection = loadPNGFile("../res/textures/reflection_field.png");
PNGImage t_reflection2 = loadPNGFile("../res/textures/reflection_blurry.png");
PNGImage t_perlin = makePerlinNoisePNG(256, 256, 0.05/16);
void init_scene(CommandLineOptions options) {