2024-01-21 01:36:21 +11:00
|
|
|
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
2024-01-21 12:58:37 +11:00
|
|
|
#include <glm/matrix.hpp>
|
2024-01-21 22:33:55 +11:00
|
|
|
#include <glm/ext/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale
|
|
|
|
#include <glm/ext/matrix_clip_space.hpp> // glm::perspective
|
2024-01-21 12:58:37 +11:00
|
|
|
|
2024-01-21 01:36:21 +11:00
|
|
|
#include <iostream>
|
|
|
|
|
2024-01-24 18:34:04 +11:00
|
|
|
#include "mesh/mesh.hpp"
|
|
|
|
#include "mesh/arrays.hpp"
|
|
|
|
#include "input/keyboard.hpp"
|
|
|
|
#include "input/mouse.hpp"
|
2024-02-14 18:00:39 +11:00
|
|
|
#include "input/focus.hpp"
|
2024-01-22 00:20:54 +11:00
|
|
|
#include "camera.hpp"
|
2024-01-21 01:36:21 +11:00
|
|
|
#include "resize.hpp"
|
|
|
|
#include "window.hpp"
|
|
|
|
#include "shader.hpp"
|
2024-01-24 18:34:04 +11:00
|
|
|
#include "mesh/font.hpp"
|
2024-01-28 00:02:54 +11:00
|
|
|
#include "locations.hpp"
|
|
|
|
#include "monitor/vessel.hpp"
|
|
|
|
#include "monitor/core.hpp"
|
2024-02-03 18:12:18 +11:00
|
|
|
#include "monitor/primary_loop.hpp"
|
2024-02-06 17:57:59 +11:00
|
|
|
#include "monitor/secondary_loop.hpp"
|
2024-02-14 18:00:39 +11:00
|
|
|
#include "monitor/turbine.hpp"
|
2024-01-28 00:02:54 +11:00
|
|
|
#include "mesh/texture.hpp"
|
2024-02-02 13:05:28 +11:00
|
|
|
#include "ui.hpp"
|
2024-01-21 01:36:21 +11:00
|
|
|
|
|
|
|
using namespace sim::graphics;
|
|
|
|
|
|
|
|
static GLFWwindow* win;
|
|
|
|
static bool win_should_close = false;
|
2024-01-26 00:30:14 +11:00
|
|
|
|
2024-02-16 16:51:25 +11:00
|
|
|
static GLMesh mesh_scene;
|
|
|
|
static monitor::Vessel monitor_vessel;
|
|
|
|
static monitor::Core monitor_core;
|
|
|
|
static monitor::PrimaryLoop monitor_primary_loop;
|
|
|
|
static monitor::SecondaryLoop monitor_secondary_loop;
|
|
|
|
static monitor::Turbine monitor_turbine;
|
2024-01-21 01:36:21 +11:00
|
|
|
|
2024-02-03 02:27:08 +11:00
|
|
|
glm::mat4 window::projection_matrix;
|
|
|
|
|
2024-01-21 01:36:21 +11:00
|
|
|
void GLAPIENTRY cb_debug_message(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
|
|
|
|
{
|
2024-01-25 00:52:02 +11:00
|
|
|
if(severity != GL_DEBUG_SEVERITY_NOTIFICATION)
|
|
|
|
{
|
|
|
|
std::cout << "GL CALLBACK: " << message << "\n";
|
|
|
|
}
|
2024-01-21 01:36:21 +11:00
|
|
|
}
|
|
|
|
|
2024-01-31 00:23:44 +11:00
|
|
|
void window::create()
|
2024-01-21 01:36:21 +11:00
|
|
|
{
|
|
|
|
glfwInit();
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
|
2024-01-28 00:02:54 +11:00
|
|
|
glfwWindowHint(GLFW_VISIBLE, false);
|
|
|
|
|
2024-01-23 17:46:33 +11:00
|
|
|
#ifdef __APPLE__
|
|
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
|
|
|
|
#endif
|
2024-01-28 00:02:54 +11:00
|
|
|
|
2024-01-21 01:36:21 +11:00
|
|
|
win = glfwCreateWindow(800, 600, "FastNuclearSim", nullptr, nullptr);
|
|
|
|
|
|
|
|
glfwMakeContextCurrent(win);
|
2024-01-24 18:34:04 +11:00
|
|
|
glfwSwapInterval(1);
|
2024-01-28 00:02:54 +11:00
|
|
|
|
2024-01-21 01:36:21 +11:00
|
|
|
GLenum err = glewInit();
|
2024-01-28 00:02:54 +11:00
|
|
|
|
2024-01-21 01:36:21 +11:00
|
|
|
if(err != GLEW_OK)
|
|
|
|
{
|
2024-01-27 12:01:52 +11:00
|
|
|
std::cerr << "GLEW Init Failed: " << glewGetErrorString(err) << "\n";
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!glGetTextureHandleARB || !glMakeTextureHandleResidentARB)
|
|
|
|
{
|
|
|
|
std::cerr << "Fatal: Bindless textures not supported\n";
|
|
|
|
|
|
|
|
if(!glGetTextureHandleARB)
|
|
|
|
std::cerr << " Missing: glGetTextureHandleARB\n";
|
|
|
|
if(!glMakeTextureHandleResidentARB)
|
|
|
|
std::cerr << " Missing: glMakeTextureHandleResidentARB\n";
|
|
|
|
|
2024-01-21 01:36:21 +11:00
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
glEnable(GL_DEBUG_OUTPUT);
|
|
|
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
2024-01-21 12:58:37 +11:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
2024-02-02 13:05:28 +11:00
|
|
|
glEnable(GL_CULL_FACE);
|
2024-01-21 12:58:37 +11:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2024-01-21 01:36:21 +11:00
|
|
|
glDebugMessageCallback(cb_debug_message, nullptr);
|
|
|
|
|
|
|
|
keyboard::init();
|
2024-01-22 00:20:54 +11:00
|
|
|
mouse::init();
|
2024-01-21 01:36:21 +11:00
|
|
|
resize::init();
|
2024-01-28 00:02:54 +11:00
|
|
|
texture::init();
|
2024-02-14 12:19:19 +11:00
|
|
|
camera::init();
|
2024-01-21 01:36:21 +11:00
|
|
|
font::init();
|
2024-02-02 13:05:28 +11:00
|
|
|
ui::init();
|
2024-01-22 00:20:54 +11:00
|
|
|
|
2024-01-21 01:36:21 +11:00
|
|
|
shader::init_program();
|
2024-01-21 22:33:55 +11:00
|
|
|
|
2024-02-16 16:51:25 +11:00
|
|
|
sim::System& sys = sim::System::active;
|
|
|
|
Mesh m, m2;
|
2024-01-31 00:23:44 +11:00
|
|
|
|
2024-02-02 13:05:28 +11:00
|
|
|
m.load_model("../assets", "scene-baked.glb");
|
2024-02-16 15:07:33 +11:00
|
|
|
m2.load_model("../assets/model", "monitor_graphics.stl");
|
|
|
|
m.add(m2, glm::mat4(1));
|
|
|
|
|
2024-02-14 12:19:19 +11:00
|
|
|
mesh_scene.bind();
|
|
|
|
mesh_scene.set(m, GL_STATIC_DRAW);
|
2024-01-30 19:39:19 +11:00
|
|
|
|
2024-02-14 12:19:19 +11:00
|
|
|
monitor_core.init();
|
|
|
|
monitor_vessel.init();
|
|
|
|
monitor_primary_loop.init();
|
|
|
|
monitor_secondary_loop.init();
|
2024-02-14 18:00:39 +11:00
|
|
|
monitor_turbine.init();
|
2024-01-26 00:30:14 +11:00
|
|
|
|
2024-01-28 00:02:54 +11:00
|
|
|
glfwShowWindow(win);
|
2024-01-21 01:36:21 +11:00
|
|
|
glViewport(0, 0, 800, 600);
|
|
|
|
}
|
|
|
|
|
2024-02-02 13:05:28 +11:00
|
|
|
void window::update(double dt)
|
2024-01-21 01:36:21 +11:00
|
|
|
{
|
2024-01-30 19:39:19 +11:00
|
|
|
glfwPollEvents();
|
|
|
|
|
2024-02-14 12:19:19 +11:00
|
|
|
monitor_core.update(dt);
|
|
|
|
monitor_vessel.update(dt);
|
|
|
|
monitor_primary_loop.update(dt);
|
|
|
|
monitor_secondary_loop.update(dt);
|
2024-02-14 18:00:39 +11:00
|
|
|
monitor_turbine.update(dt);
|
2024-01-26 00:30:14 +11:00
|
|
|
|
2024-02-02 13:05:28 +11:00
|
|
|
ui::update(dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void window::render()
|
|
|
|
{
|
|
|
|
glm::mat4 mat_camera = camera::get_matrix();
|
|
|
|
glm::mat4 mat_projection = glm::perspective(glm::radians(90.0f), resize::get_aspect(), 0.01f, 20.f);
|
2024-01-21 22:33:55 +11:00
|
|
|
glUniformMatrix4fv(shader::gl_projection, 1, false, &mat_projection[0][0]);
|
2024-02-02 13:05:28 +11:00
|
|
|
glUniformMatrix4fv(shader::gl_camera, 1, false, &mat_camera[0][0]);
|
2024-02-03 02:27:08 +11:00
|
|
|
projection_matrix = mat_projection;
|
2024-01-24 22:01:33 +11:00
|
|
|
|
|
|
|
glClearColor(0, 0, 0, 1.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2024-01-21 12:58:37 +11:00
|
|
|
|
2024-02-14 12:19:19 +11:00
|
|
|
mesh_scene.bind();
|
|
|
|
mesh_scene.uniform();
|
|
|
|
mesh_scene.render();
|
|
|
|
|
|
|
|
monitor_core.render();
|
|
|
|
monitor_vessel.render();
|
|
|
|
monitor_primary_loop.render();
|
|
|
|
monitor_secondary_loop.render();
|
2024-02-14 18:00:39 +11:00
|
|
|
monitor_turbine.render();
|
2024-01-21 01:36:21 +11:00
|
|
|
|
2024-02-14 18:00:39 +11:00
|
|
|
focus::render();
|
2024-02-02 13:05:28 +11:00
|
|
|
ui::render();
|
2024-02-14 18:00:39 +11:00
|
|
|
focus::render_ui();
|
2024-02-02 13:05:28 +11:00
|
|
|
|
2024-01-21 01:36:21 +11:00
|
|
|
glfwSwapBuffers(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool window::should_close()
|
|
|
|
{
|
|
|
|
return win_should_close || glfwWindowShouldClose(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
void window::close()
|
|
|
|
{
|
|
|
|
win_should_close = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void window::destroy()
|
|
|
|
{
|
2024-01-28 00:02:54 +11:00
|
|
|
glfwDestroyWindow(win);
|
2024-01-21 01:36:21 +11:00
|
|
|
glfwTerminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
GLFWwindow* window::get_window()
|
|
|
|
{
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|