Further separate the render logic and the scene logic
With some cleanup
This commit is contained in:
parent
74ffe23551
commit
383d5d3f62
|
@ -32,7 +32,9 @@ void runProgram(GLFWwindow* window, CommandLineOptions options)
|
||||||
glClearColor(0.3f, 0.5f, 0.8f, 1.0f);
|
glClearColor(0.3f, 0.5f, 0.8f, 1.0f);
|
||||||
|
|
||||||
initRenderer(window, options);
|
initRenderer(window, options);
|
||||||
|
init_scene(options);
|
||||||
|
getTimeDeltaSeconds();
|
||||||
|
|
||||||
// Rendering Loop
|
// Rendering Loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
|
@ -41,7 +43,9 @@ void runProgram(GLFWwindow* window, CommandLineOptions options)
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
glfwGetWindowSize(window, &w, &h);
|
glfwGetWindowSize(window, &w, &h);
|
||||||
|
|
||||||
|
step_scene(getTimeDeltaSeconds());
|
||||||
|
|
||||||
updateFrame(window, w, h);
|
updateFrame(window, w, h);
|
||||||
renderFrame(window, w, h);
|
renderFrame(window, w, h);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <SFML/Audio/Sound.hpp>
|
#include <SFML/Audio/Sound.hpp>
|
||||||
#include <SFML/Audio/SoundBuffer.hpp>
|
#include <SFML/Audio/SoundBuffer.hpp>
|
||||||
#include <chrono>
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
@ -13,7 +12,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utilities/glfont.h>
|
#include <utilities/glfont.h>
|
||||||
#include <utilities/shader.hpp>
|
#include <utilities/shader.hpp>
|
||||||
#include <utilities/timeutils.h>
|
|
||||||
|
|
||||||
using glm::vec3;
|
using glm::vec3;
|
||||||
using glm::vec4;
|
using glm::vec4;
|
||||||
|
@ -51,11 +49,6 @@ void initRenderer(GLFWwindow* window, CommandLineOptions options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
|
|
||||||
init_scene(options);
|
|
||||||
|
|
||||||
// init
|
|
||||||
getTimeDeltaSeconds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// traverses and updates matricies
|
// traverses and updates matricies
|
||||||
|
@ -81,11 +74,7 @@ void updateNodeTransformations(SceneNode* node, mat4 transformationThusFar, mat4
|
||||||
|
|
||||||
// step
|
// step
|
||||||
void updateFrame(GLFWwindow* window, int windowWidth, int windowHeight) {
|
void updateFrame(GLFWwindow* window, int windowWidth, int windowHeight) {
|
||||||
double timeDelta = getTimeDeltaSeconds();
|
|
||||||
float aspect = float(windowWidth) / float(windowHeight);
|
float aspect = float(windowWidth) / float(windowHeight);
|
||||||
|
|
||||||
// main action:
|
|
||||||
step_scene(timeDelta);
|
|
||||||
|
|
||||||
// calculate camera
|
// calculate camera
|
||||||
mat4 projection = glm::perspective(
|
mat4 projection = glm::perspective(
|
||||||
|
@ -185,7 +174,9 @@ void renderNode(SceneNode* node, Gloom::Shader* parent_shader, vector<NodeDistSh
|
||||||
}
|
}
|
||||||
else if(node->vertexArrayObjectID != -1) {
|
else if(node->vertexArrayObjectID != -1) {
|
||||||
// load uniforms
|
// load uniforms
|
||||||
um4fv(MVP); um4fv(MV); um4fv(MVnormal);
|
um4fv(MVP);
|
||||||
|
um4fv(MV);
|
||||||
|
um4fv(MVnormal);
|
||||||
u2fv (uvOffset);
|
u2fv (uvOffset);
|
||||||
u3fv (diffuse_color);
|
u3fv (diffuse_color);
|
||||||
u3fv (emissive_color);
|
u3fv (emissive_color);
|
||||||
|
@ -263,7 +254,7 @@ void renderFrame(GLFWwindow* window, int windowWidth, int windowHeight) {
|
||||||
//glDisable(GL_DEPTH_TEST);
|
//glDisable(GL_DEPTH_TEST);
|
||||||
for (NodeDistShader a : transparent_nodes)
|
for (NodeDistShader a : transparent_nodes)
|
||||||
renderNode(a.node, a.s, nullptr, false);
|
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
|
glDepthMask(GL_TRUE); // read write
|
||||||
//glEnable(GL_DEPTH_TEST);
|
//glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
|
|
@ -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_diff = loadPNGFile("../res/textures/plain_diff.png");
|
||||||
PNGImage t_plain_normal = loadPNGFile("../res/textures/plain_normal.png", true);
|
PNGImage t_plain_normal = loadPNGFile("../res/textures/plain_normal.png", true);
|
||||||
PNGImage t_reflection = loadPNGFile("../res/textures/reflection_field.png");
|
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);
|
PNGImage t_perlin = makePerlinNoisePNG(256, 256, 0.05/16);
|
||||||
|
|
||||||
void init_scene(CommandLineOptions options) {
|
void init_scene(CommandLineOptions options) {
|
||||||
|
|
Loading…
Reference in New Issue