Index

zydeco / master

Experiment in graphics programming, C++, OpenGL, simulation techniques.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1008 Dec 2023 15:215a717feFractal renderer update for articleJosh Stockin115G

Blob @ zydeco / src / main.cpp

text/plain3263 bytesdownload raw
1#include <iostream>
2
3#include "ZydecoCommon.hpp"
4#include "CommonSDL2.hpp"
5#include "EventHandlerSDL2.hpp"
6#include "WindowSDL2.hpp"
7#include "TimerSDL2.hpp"
8#include "Renderer.hpp"
9#include "Engine.hpp"
10
11
12static Logger LOGGER("main");
13
14static const char *ZYDECO_TERMOUT[] = {
15 "Zydeco v0.1.0 Copyright (c) Joshua Stockin 2023",
16 "<https://joshstock.in> <josh@joshstock.in>",
17};
18
19
20void on_terminate(void)
21{
22 ZydecoFault("PROGRAM TERMINATED UNEXPECTEDLY.");
23}
24
25int main(int argc, char *argv[])
26{
27 // Print boilerplate copyright output
28 for (const char *line : ZYDECO_TERMOUT)
29 {
30 std::cout << line << std::endl;
31 }
32
33 // Runtime environment setup
34 std::set_terminate(static_cast<std::terminate_handler>(on_terminate));
35
36 // Initialize logging
37 Logger::InitializeLogging(Logger::VERBOSE, &std::cout);
38 LOGGER.Log(Logger::INFO, "main(): Logging initialized");
39
40 // Initialize SDL environment
41 LOGGER.Log(Logger::INFO, "main(): Initializing SDL...");
42 SDL_CallErrorReturningFunction(SDL_Init, SDL_INIT_VIDEO | SDL_INIT_EVENTS);
43 LOGGER.Log(Logger::INFO, "main(): SDL initialized");
44
45 // Load ImGui
46 LOGGER.Log(Logger::INFO, "main(): Loading ImGui...");
47 IMGUI_CHECKVERSION();
48 ImGui::CreateContext();
49 ImGuiIO& imgui_io = ImGui::GetIO();
50 imgui_io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
51 //imgui_io.ConfigDockingWithShift = false;
52
53 // Create subsystems
54 LOGGER.Log(Logger::INFO, "main(): Creating subsystems...");
55 EventHandlerSDL2 sdl_event_handler {};
56 WindowSDL2 sdl_window {"Zydeco", SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE};
57 TimerSDL2 sdl_core_timer {};
58
59 // Load OpenGL
60 LOGGER.Log(Logger::INFO, "main(): Loading OpenGL with GL3W...");
61
62 sdl_window.MakeContextCurrent();
63 int gl3wRes = gl3wInit();
64 if (gl3wRes != 0)
65 {
66 ZydecoFault("gl3wInit failed ({})", gl3wRes);
67 }
68
69 if (!gl3wIsSupported(GL_VERSION_MAJOR, GL_VERSION_MINOR))
70 {
71 ZydecoFault("OpenGL/GL3W {}.{} not supported", GL_VERSION_MAJOR, GL_VERSION_MINOR);
72 }
73
74 LOGGER.Log(Logger::DEBUG, "main(): OpenGL {}, GLSL {}", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
75 LOGGER.Log(Logger::DEBUG, "main(): Renderer: {}", glGetString(GL_RENDERER));
76 LOGGER.Log(Logger::INFO, "main(): OpenGL loaded with GL3W");
77
78 TimerSDL2 sdl_renderer_timer {};
79 Renderer gl_renderer {sdl_event_handler, sdl_window, sdl_renderer_timer};
80
81 LOGGER.Log(Logger::INFO, "main(): Subsystems created");
82
83 // Create engine
84 LOGGER.Log(Logger::INFO, "main(): Creating engine...");
85 Engine engine {sdl_event_handler, sdl_window, sdl_core_timer, gl_renderer};
86 LOGGER.Log(Logger::INFO, "main(): Engine created");
87
88 // Enter loop
89 LOGGER.Log(Logger::INFO, "main(): Entering engine loop");
90 engine.Execute();
91
92 // Engine exited
93 LOGGER.Log(Logger::INFO, "main(): Engine exited");
94
95 // Quit ImGui
96 LOGGER.Log(Logger::INFO, "main(): Quitting ImGui");
97 ImGui_ImplOpenGL3_Shutdown();
98 ImGui_ImplSDL2_Shutdown();
99 ImGui::DestroyContext();
100
101 // Quit SDL
102 LOGGER.Log(Logger::INFO, "main(): Quitting SDL");
103 SDL_Quit();
104
105 // Exiting program
106 LOGGER.Log(Logger::INFO, "main(): Exiting");
107 return 0;
108}
109