Basic GUI
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
build/
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
|
||||
@@ -16,11 +16,13 @@ find_package(assimp CONFIG REQUIRED)
|
||||
find_package(glfw3 CONFIG REQUIRED)
|
||||
find_package(glm CONFIG REQUIRED)
|
||||
find_package(Ktx CONFIG REQUIRED)
|
||||
find_package(imgui CONFIG REQUIRED)
|
||||
|
||||
add_executable(RayTracer "")
|
||||
target_include_directories(RayTracer PUBLIC src/)
|
||||
target_link_libraries(RayTracer PUBLIC assimp::assimp)
|
||||
target_link_libraries(RayTracer PUBLIC glfw)
|
||||
target_link_libraries(RayTracer PUBLIC imgui::imgui)
|
||||
if(APPLE)
|
||||
target_link_libraries(RayTracer PUBLIC GLEW::GLEW)
|
||||
else()
|
||||
|
||||
+3
-4
@@ -5,7 +5,7 @@
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Debug",
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
||||
"buildRoot": "${projectDir}\\bin\\${name}",
|
||||
"buildRoot": "${projectDir}\\build",
|
||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "",
|
||||
@@ -16,14 +16,13 @@
|
||||
"name": "Release",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "RelWithDebInfo",
|
||||
"buildRoot": "${projectDir}\\bin\\${name}",
|
||||
"buildRoot": "${projectDir}\\build",
|
||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||
"cmakeExecutable": "C:/Program Files/CMake/bin/cmake.exe",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "",
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
||||
"variables": []
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "scene/Scene.h"
|
||||
#include "util/ModelLoader.h"
|
||||
#include "window/Window.h"
|
||||
#include <iostream>
|
||||
#include <imgui.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -19,6 +21,11 @@ int main()
|
||||
});
|
||||
while (true)
|
||||
{
|
||||
window.beginFrame();
|
||||
if (ImGui::Button("Test"))
|
||||
{
|
||||
std::cout << "Test" << std::endl;
|
||||
}
|
||||
window.update(scene.getImage());
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
void BVH::addModel(PModel model, glm::mat4 transform)
|
||||
{
|
||||
model->boundingBox.transform(transform);
|
||||
for (auto& point : model->positions)
|
||||
{
|
||||
point = glm::vec3(transform * glm::vec4(point, 1));
|
||||
}
|
||||
models.push_back(std::move(model));
|
||||
}
|
||||
|
||||
@@ -13,6 +17,10 @@ void BVH::addModels(std::vector<PModel> _models, glm::mat4 transform)
|
||||
for (int i = 0; i < _models.size(); ++i)
|
||||
{
|
||||
_models[i]->boundingBox.transform(transform);
|
||||
for (auto& point : _models[i]->positions)
|
||||
{
|
||||
point = glm::vec3(transform * glm::vec4(point, 1));
|
||||
}
|
||||
models.push_back(std::move(_models[i]));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ void Scene::render(Camera cam, RenderParameter params)
|
||||
image.resize(params.width * params.height);
|
||||
accumulator.resize(params.width * params.height);
|
||||
worker = std::thread(
|
||||
[&]()
|
||||
[&, cam, params]()
|
||||
{
|
||||
for (int samp = 0; samp < params.numSamples; ++samp)
|
||||
{
|
||||
|
||||
+28
-2
@@ -1,5 +1,8 @@
|
||||
#include "Window.h"
|
||||
#include <iostream>
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_glfw.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
|
||||
#define GLSL(...) "#version 400\n" #__VA_ARGS__
|
||||
|
||||
@@ -12,13 +15,27 @@ Window::Window(int width, int height) : width(width), height(height)
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL
|
||||
window = glfwCreateWindow(width, height, "RayTracer", nullptr, nullptr);
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(window,
|
||||
true); // Second param install_callback=true will install GLFW callbacks and chain to existing ones.
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
|
||||
glewInit();
|
||||
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
program = glCreateProgram();
|
||||
vertShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
@@ -75,13 +92,22 @@ Window::Window(int width, int height) : width(width), height(height)
|
||||
|
||||
Window::~Window() {}
|
||||
|
||||
void Window::update(const std::vector<glm::vec3>& textureData)
|
||||
void Window::beginFrame()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glfwPollEvents();
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
void Window::update(const std::vector<glm::vec3>& textureData)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_FLOAT, textureData.data());
|
||||
glUseProgram(program);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ class Window
|
||||
public:
|
||||
Window(int width, int height);
|
||||
~Window();
|
||||
void beginFrame();
|
||||
void update(const std::vector<glm::vec3>& textureData);
|
||||
|
||||
private:
|
||||
|
||||
+13
-1
@@ -1,3 +1,15 @@
|
||||
{
|
||||
"dependencies": ["assimp", "ktx", "glfw3", "glew", "glm", "stb", "fmt"]
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "imgui",
|
||||
"features": [ "glfw-binding", "opengl3-binding" ]
|
||||
},
|
||||
"assimp",
|
||||
"ktx",
|
||||
"glfw3",
|
||||
"glew",
|
||||
"glm",
|
||||
"stb",
|
||||
"fmt"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user