diff options
author | rtk0c <[email protected]> | 2022-04-17 20:08:57 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-04-17 20:08:57 -0700 |
commit | 5424a1d5434e3ddd911a504719918c2df027e2fd (patch) | |
tree | 6275aab13140d81dcc46c8290e73ac9a8bbb5605 /source/main.cpp | |
parent | afcac59c7d04f4337d6b04ebed8cac7e871ccc50 (diff) |
Changeset: 8 Initial work on sprites and texture system
Diffstat (limited to 'source/main.cpp')
-rw-r--r-- | source/main.cpp | 121 |
1 files changed, 99 insertions, 22 deletions
diff --git a/source/main.cpp b/source/main.cpp index 8f16403..3d02f8d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -2,14 +2,16 @@ #include "AppConfig.hpp" #include "EditorNotification.hpp" +#include "Ires.hpp" #include "Material.hpp" +#include "Mesh.hpp" #include "Shader.hpp" -#include "Texture.hpp" #define GLFW_INCLUDE_NONE #include <GLFW/glfw3.h> #include <backends/imgui_impl_glfw.h> +#include <backends/imgui_impl_opengl2.h> #include <backends/imgui_impl_opengl3.h> #include <glad/glad.h> #include <imgui.h> @@ -55,18 +57,35 @@ static void GlfwKeyCallback(GLFWwindow* window, int key, int scancode, int actio } int main(int argc, char* argv[]) { + using namespace Tags; + + constexpr auto kImGuiBackend = "imgui-backend"; constexpr auto kGameDataDir = "game-data-directory"; constexpr auto kGameAssetDir = "game-asset-directory"; cxxopts::Options options(std::string(AppConfig::kAppName), ""); // clang-format off options.add_options() + (kImGuiBackend, "ImGui backend. Options: opengl2, opengl3. Leave empty to default.", cxxopts::value<std::string>()) (kGameAssetDir, "Directory in which assets are looked up from. Can be relative paths to the executable.", cxxopts::value<std::string>()->default_value(".")) (kGameDataDir, "Directory in which game data (such as saves and options) are saved to. Leave empty to use the default directory on each platform.", cxxopts::value<std::string>()) - ; + ; // clang-format on auto args = options.parse(argc, argv); + bool imguiUseOpenGL3; + { + auto imguiBackend = args[kImGuiBackend].as<std::string>(); + if (imguiBackend == "opengl2") { + imguiUseOpenGL3 = false; + } else if (imguiBackend == "opengl3") { + imguiUseOpenGL3 = true; + } else { + // TODO support more backends? + imguiUseOpenGL3 = false; + } + } + { auto assetDir = args[kGameAssetDir].as<std::string>(); @@ -103,20 +122,20 @@ int main(int argc, char* argv[]) { // Decide GL+GLSL versions #if defined(IMGUI_IMPL_OPENGL_ES2) // GL ES 2.0 + GLSL 100 - const char* glsl_version = "#version 100"; + const char* imguiGlslVersion = "#version 100"; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); #elif defined(__APPLE__) // GL 3.2 + GLSL 150 - const char* glsl_version = "#version 150"; + const char* imguiGlslVersion = "#version 150"; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac #else // GL 3.0 + GLSL 130 - const char* glsl_version = "#version 130"; + const char* imguiGlslVersion = "#version 130"; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); #endif @@ -146,41 +165,99 @@ int main(int argc, char* argv[]) { ImGui::CreateContext(); ImGui_ImplGlfw_InitForOpenGL(window, true); - ImGui_ImplOpenGL3_Init(glsl_version); + if (imguiUseOpenGL3) { + ImGui_ImplOpenGL3_Init(imguiGlslVersion); + } else { + ImGui_ImplOpenGL2_Init(); + } ShaderManager::instance = new ShaderManager(); - TextureManager::instance = new TextureManager(); MaterialManager::instance = new MaterialManager(); + IresManager::instance = new IresManager(); ShaderManager::instance->DiscoverShaders(); - TextureManager::instance->DiscoverTextures(); MaterialManager::instance->DiscoverMaterials(); + IresManager::instance->DiscoverFilesDesignatedLocation(); + + gVformatStandard.Attach(new VertexFormat()); + gVformatStandard->AddElement(VertexElementFormat{ + .bindingIndex = 0, + .type = VET_Float3, + .semantic = VES_Position, + }); + gVformatStandard->AddElement(VertexElementFormat{ + .bindingIndex = 1, + .type = VET_Float2, + .semantic = VES_TexCoords1, + }); + gVformatStandard->AddElement(VertexElementFormat{ + .bindingIndex = 1, + .type = VET_Ubyte4Norm, + .semantic = VES_Color1, + }); + + gVformatStandardPacked.Attach(new VertexFormat()); + gVformatStandardPacked->AddElement(VertexElementFormat{ + .bindingIndex = 0, + .type = VET_Float3, + .semantic = VES_Position, + }); + gVformatStandardPacked->AddElement(VertexElementFormat{ + .bindingIndex = 0, + .type = VET_Float2, + .semantic = VES_TexCoords1, + }); + gVformatStandardPacked->AddElement(VertexElementFormat{ + .bindingIndex = 0, + .type = VET_Ubyte4Norm, + .semantic = VES_Color1, + }); app.Init(); while (!glfwWindowShouldClose(window)) { glfwPollEvents(); - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + int fbWidth, fbHeight; + glfwGetFramebufferSize(window, &fbWidth, &fbHeight); + glViewport(0, 0, fbWidth, fbHeight); + auto clearColor = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + glClearColor(clearColor.x * clearColor.w, clearColor.y * clearColor.w, clearColor.z * clearColor.w, clearColor.w); + glClear(GL_COLOR_BUFFER_BIT); + + { // Regular draw + app.Update(); + app.Draw(); + } - app.Show(); - ImGui::ShowNotifications(); + { // ImGui stuff + if (imguiUseOpenGL3) { + ImGui_ImplOpenGL3_NewFrame(); + } else { + ImGui_ImplOpenGL2_NewFrame(); + } + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); - ImGui::Render(); - int display_w, display_h; - glfwGetFramebufferSize(window, &display_w, &display_h); - glViewport(0, 0, display_w, display_h); - auto clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); - glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); - glClear(GL_COLOR_BUFFER_BIT); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + app.Show(); + ImGui::ShowNotifications(); + + ImGui::Render(); + if (imguiUseOpenGL3) { + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + } else { + ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); + } + } glfwSwapBuffers(window); } app.Shutdown(); - ImGui_ImplOpenGL3_Shutdown(); + if (imguiUseOpenGL3) { + ImGui_ImplOpenGL3_Shutdown(); + } else { + ImGui_ImplOpenGL2_Shutdown(); + } ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); |