Add Parallax Demo + some bugfixes
The initialization order in the Application was wrong, so some code has been moved from run to the constructor.
This commit is contained in:
parent
3dacb0c095
commit
482116018f
@ -10,6 +10,10 @@ def add_strict_compile_flags(env):
|
||||
env.Append(CCFLAGS=["-Wall", "-Wextra", "-pedantic", "-std=c++17"])
|
||||
|
||||
|
||||
def add_debug_compile_flags(env):
|
||||
env.Append(CCFLAGS=["-g"])
|
||||
|
||||
|
||||
# Create the environment and create a Compilation Database for use in VSCodium
|
||||
env = Environment(tools=['default', 'compilation_db'])
|
||||
env.CompilationDatabase()
|
||||
@ -45,9 +49,11 @@ testEnv.Append(LINKFLAGS=[
|
||||
|
||||
add_third_party_includes(testEnv)
|
||||
add_strict_compile_flags(testEnv)
|
||||
add_debug_compile_flags(testEnv)
|
||||
|
||||
# Build the test programs
|
||||
catch_cpp = "test/catch_amalgamated.cpp"
|
||||
testEnv.Program('test/bin/vector-test.out', [catch_cpp, 'test/vector/vector-test.cpp'])
|
||||
|
||||
testEnv.Program('test/bin/test-app.out', Glob('test/test-app/*.cpp'))
|
||||
testEnv.Program('test/bin/parallax-demo.out', Glob('test/parallax-demo/*.cpp'))
|
||||
|
@ -6,12 +6,16 @@
|
||||
|
||||
namespace Gedeng {
|
||||
|
||||
void Application::run() {
|
||||
Application::Application(unsigned long ms_per_update, unsigned int window_size_x, unsigned int window_size_y,
|
||||
String window_name)
|
||||
: MS_PER_UPDATE(ms_per_update), WINDOW_SIZE_X(window_size_x), WINDOW_SIZE_Y(window_size_y),
|
||||
WINDOW_NAME(window_name) {
|
||||
// Setup Rendering
|
||||
// FIXME: Make these parameters variable, maybe move this to a different function
|
||||
RenderBackend::initialize_window(WINDOW_SIZE_X, WINDOW_SIZE_Y, WINDOW_NAME);
|
||||
Input::initialize(RenderBackend::get_window());
|
||||
}
|
||||
|
||||
void Application::run() {
|
||||
unsigned long previous_time_ms = Time::get_time_ms();
|
||||
unsigned long time_until_fixed_update_ms = 0.0;
|
||||
|
||||
@ -31,6 +35,8 @@ void Application::run() {
|
||||
}
|
||||
|
||||
dynamic_update(static_cast<double>(elapsed_time_ms) / 1000.0);
|
||||
|
||||
RenderBackend::render();
|
||||
}
|
||||
}
|
||||
|
||||
|
1411
cpp/vendor/glad.c
vendored
1411
cpp/vendor/glad.c
vendored
File diff suppressed because it is too large
Load Diff
@ -6,10 +6,8 @@ namespace Gedeng {
|
||||
|
||||
class Application {
|
||||
public:
|
||||
Application(unsigned long ms_per_update, unsigned int window_size_x, unsigned int window_size_y, String window_name)
|
||||
: MS_PER_UPDATE(ms_per_update), WINDOW_SIZE_X(window_size_x), WINDOW_SIZE_Y(window_size_y),
|
||||
WINDOW_NAME(window_name) {
|
||||
}
|
||||
Application(unsigned long ms_per_update, unsigned int window_size_x, unsigned int window_size_y,
|
||||
String window_name);
|
||||
|
||||
// Virtual since this class will be inherited by user-created applications
|
||||
virtual ~Application() = default;
|
||||
|
@ -2,7 +2,11 @@
|
||||
|
||||
// Adapted from LearnOpenGL
|
||||
|
||||
// Must be the first include
|
||||
#include <glad/glad.h>
|
||||
|
||||
// Other includes
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <fstream>
|
||||
@ -152,21 +156,17 @@ class Shader {
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(shader, 1024, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n"
|
||||
<< infoLog
|
||||
<< "\n -- --------------------------------------------------- -- "
|
||||
<< std::endl;
|
||||
<< infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
|
||||
}
|
||||
} else {
|
||||
glGetProgramiv(shader, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(shader, 1024, NULL, infoLog);
|
||||
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n"
|
||||
<< infoLog
|
||||
<< "\n -- --------------------------------------------------- -- "
|
||||
<< std::endl;
|
||||
<< infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Gedeng
|
94
test/parallax-demo/main.cpp
Normal file
94
test/parallax-demo/main.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
#include "Gedeng/Logger.h"
|
||||
#define GEDENG_MAIN
|
||||
#include <Gedeng.h>
|
||||
|
||||
class ParallaxApp : public Gedeng::Application {
|
||||
public:
|
||||
ParallaxApp(unsigned long ms_per_update, unsigned int window_size_x, unsigned int window_size_y,
|
||||
Gedeng::String window_name)
|
||||
: Application(ms_per_update, window_size_x, window_size_y, window_name), number_of_steps(10.0),
|
||||
number_of_refinement_steps(10.0), bump_depth(0.1),
|
||||
render_shader(Gedeng::Shader("Shader/bump.vs", "Shader/bump.fs")),
|
||||
camera(Gedeng::Camera(90, 1920, 1080, 0.1, 1000.0)),
|
||||
albedo("Resources/Textures/PavingStones/PavingStones070_2K_Color.jpg", Gedeng::Texture::Settings()),
|
||||
bump("Resources/Textures/PavingStones/PavingStones070_2K_Displacement.jpg", Gedeng::Texture::Settings()),
|
||||
normal("Resources/Textures/PavingStones/PavingStones070_2K_Normal.jpg", Gedeng::Texture::Settings()) {
|
||||
// Move and rotate the camera so we see the quad well
|
||||
camera.translate(glm::vec3(0.0, -1.0, 1.0));
|
||||
camera.rotate(30, glm::vec3(1.0, 0.0, 0.0));
|
||||
}
|
||||
|
||||
~ParallaxApp() = default;
|
||||
|
||||
void fixed_update(double delta) override {
|
||||
// Settings for bump mapping
|
||||
if (Gedeng::Input::is_key_down(GLFW_KEY_Q)) {
|
||||
number_of_steps += delta * 5.0;
|
||||
}
|
||||
if (Gedeng::Input::is_key_down(GLFW_KEY_W)) {
|
||||
number_of_steps -= delta * 5.0;
|
||||
}
|
||||
if (Gedeng::Input::is_key_down(GLFW_KEY_A)) {
|
||||
number_of_refinement_steps += delta * 5.0;
|
||||
}
|
||||
if (Gedeng::Input::is_key_down(GLFW_KEY_S)) {
|
||||
number_of_refinement_steps -= delta * 5.0;
|
||||
}
|
||||
if (Gedeng::Input::is_key_down(GLFW_KEY_Z)) {
|
||||
bump_depth += delta * 0.1;
|
||||
}
|
||||
if (Gedeng::Input::is_key_down(GLFW_KEY_X)) {
|
||||
bump_depth -= delta * 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
void dynamic_update(double delta) override {
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
render_shader.use();
|
||||
|
||||
// Camera
|
||||
render_shader.setMat4("projection", camera.get_projection());
|
||||
render_shader.setMat4("view", camera.get_view());
|
||||
render_shader.setVec3("viewPos", camera.get_translation());
|
||||
|
||||
// Lighting
|
||||
render_shader.setVec3("lightPos", glm::vec3(0.0, 1.0, 5.0));
|
||||
|
||||
render_shader.setFloat("number_of_steps", glm::max(0.0f, number_of_steps));
|
||||
render_shader.setFloat("number_of_refinement_steps", glm::max(0.0f, number_of_refinement_steps));
|
||||
render_shader.setFloat("bump_depth", glm::max(0.0f, bump_depth));
|
||||
|
||||
// Textures
|
||||
albedo.bind_to(0);
|
||||
normal.bind_to(1);
|
||||
bump.bind_to(2);
|
||||
|
||||
// Quad which is rendered onto
|
||||
quad_mesh.rotate(delta * 25.0f, glm::normalize(glm::vec3(0.0, 0.0, 1.0)));
|
||||
quad_mesh.render(render_shader);
|
||||
}
|
||||
|
||||
private:
|
||||
float number_of_steps;
|
||||
float number_of_refinement_steps;
|
||||
float bump_depth;
|
||||
|
||||
Gedeng::Shader render_shader;
|
||||
|
||||
Gedeng::VertexBuffer vertex_rectangle;
|
||||
|
||||
Gedeng::Camera camera;
|
||||
|
||||
Gedeng::Texture albedo;
|
||||
Gedeng::Texture bump;
|
||||
Gedeng::Texture normal;
|
||||
|
||||
Gedeng::QuadMesh quad_mesh;
|
||||
};
|
||||
|
||||
Gedeng::Application *Gedeng::create_application() {
|
||||
GG_CLIENT_INFO("Creating Application");
|
||||
return new ParallaxApp(20, 900, 600, String("Parallax Demo"));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user