SDRPlusPlus/src/main.cpp

119 lines
3.0 KiB
C++
Raw Normal View History

2020-06-10 04:13:56 +02:00
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <main_window.h>
#include <styles.h>
2020-07-19 15:59:44 +02:00
#include <icons.h>
2020-07-19 18:09:59 +02:00
#include <version.h>
2020-08-04 21:34:56 +02:00
#include <spdlog/spdlog.h>
#include <bandplan.h>
2020-08-07 14:29:06 +02:00
#include <module.h>
2020-06-22 16:45:57 +02:00
2020-06-10 04:13:56 +02:00
#ifdef _WIN32
#include <Windows.h>
#endif
static void glfw_error_callback(int error, const char* description) {
2020-08-04 21:34:56 +02:00
spdlog::error("Glfw Error {0}: {1}", error, description);
2020-06-10 04:13:56 +02:00
}
int main() {
#ifdef _WIN32
//FreeConsole();
#endif
2020-08-04 21:34:56 +02:00
spdlog::info("SDR++ v" VERSION_STR);
2020-06-10 04:13:56 +02:00
// Setup window
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit()) {
return 1;
}
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
// Create window with graphics context
2020-07-19 18:09:59 +02:00
GLFWwindow* window = glfwCreateWindow(1280, 720, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
2020-06-10 04:13:56 +02:00
if (window == NULL)
return 1;
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
if (glewInit() != GLEW_OK) {
2020-08-04 21:34:56 +02:00
spdlog::error("Failed to initialize OpenGL loader!");
2020-06-10 04:13:56 +02:00
return 1;
}
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.IniFilename = NULL;
// Setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 150");
setImguiStyle(io);
windowInit();
2020-08-04 21:34:56 +02:00
spdlog::info("Loading icons");
2020-07-19 15:59:44 +02:00
icons::load();
2020-08-05 11:23:13 +02:00
spdlog::info("Loading band plans");
2020-08-05 12:50:34 +02:00
bandplan::loadFromDir("bandplans");
2020-08-04 21:34:56 +02:00
2020-08-05 21:13:53 +02:00
spdlog::info("Loading band plans color table");
bandplan::loadColorTable("band_colors.json");
2020-08-04 21:34:56 +02:00
spdlog::info("Ready.");
2020-06-10 04:13:56 +02:00
// Main loop
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
int wwidth, wheight;
glfwGetWindowSize(window, &wwidth, &wheight);
ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(ImVec2(wwidth, wheight));
2020-06-15 15:53:45 +02:00
ImGui::Begin("Main", NULL, WINDOW_FLAGS);
2020-06-10 04:13:56 +02:00
drawWindow();
ImGui::End();
// Rendering
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0.0666f, 0.0666f, 0.0666f, 1.0f);
//glClearColor(0.90f, 0.90f, 0.90f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}