feat(main.cpp): rework main file

This commit is contained in:
2026-01-04 21:16:38 +01:00
parent b09b2a27a8
commit 773c0b559c

View File

@@ -1,68 +1,81 @@
#include <cstddef>
#include <cstdlib>
#include <iostream>
#include "glad/glad.h" #include "glad/glad.h"
#include "GLFW/glfw3.h" #include "GLFW/glfw3.h"
// #include "imgui.h"
#include <cstdio> // #include "backends/imgui_impl_glfw.h"
// #include <cstdlib> // #include "backends/imgui_impl_opengl3.h"
#include <iostream>
#include <ostream>
#include "camera.hpp" #include "camera.hpp"
#include "cube.hpp" #include "cube.hpp"
#include "glm/ext/vector_float3.hpp"
static void glfwErrorCallback(int error, const char *description) constexpr const char *WINDOW_NAME = "window";
int width = 800;
int height = 600;
int main(void)
{ {
std::cerr << "GLFW Error " << error << ": " << description << std::endl; // define error callback
} glfwSetErrorCallback(
[](int error, const char *desc)
int main() { std::cerr << "GLFW ERROR (" << error << "): " << desc << std::endl; });
{
const char *title = "window";
int width = 800, height = 600;
glfwSetErrorCallback(glfwErrorCallback);
if (glfwInit() == GLFW_FALSE) if (glfwInit() == GLFW_FALSE)
{ {
std::cerr << "ERROR(GLFW): initialisation error" << std::endl; std::cerr << "GLFW ERROR: Failed to initialize glfw." << std::endl;
exit(EXIT_FAILURE); return EXIT_FAILURE;
} }
// OpenGL 3.3 // OpenGL CORE 4.1
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_DEPTH_BITS, 24); // window properties
glfwWindowHint(GLFW_STENCIL_BITS, 8); glfwWindowHint(GLFW_DEPTH_BITS, 24); // set depth buffer to 3 bytes (24 bits)
glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_STENCIL_BITS, 8); // set stencil buffer to 1 byte (8 bits)
#ifdef __APPLE__ glfwWindowHint(GLFW_SAMPLES, 4); // activate MSAA (4 samples per pixels)
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #ifdef __APPLE__
#endif glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,
GL_TRUE); // disable deprecated functionalities
#endif
GLFWwindow *window = glfwCreateWindow(width, height, title, nullptr, GLFWwindow *window =
nullptr); if (window == nullptr) glfwCreateWindow(width, height, WINDOW_NAME, nullptr, nullptr);
if (window == NULL)
{ {
std::cerr std::cerr << "GLFW ERROR: Failed to create GLFW window." << std::endl;
<< "ERROR: Failed to create GLFW window with requested GL version."
<< std::endl;
glfwTerminate(); glfwTerminate();
exit(EXIT_FAILURE); return EXIT_FAILURE;
} }
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{ {
std::cerr << "ERROR: Failed to initialize GLAD" << std::endl; std::cerr << "GLAD ERROR: Failed to initialize GLAD" << std::endl;
glfwDestroyWindow(window); glfwDestroyWindow(window);
glfwTerminate(); glfwTerminate();
exit(EXIT_FAILURE); return EXIT_FAILURE;
} }
glfwSwapInterval(1); glfwSwapInterval(1);
// IMGUI_CHECKVERSION();
// ImGui::CreateContext();
// ImGuiIO &io = ImGui::GetIO();
// (void)io;
// ImGui::StyleColorsDark();
// ImGui_ImplGlfw_InitForOpenGL(window, true);
// ImGui_ImplOpenGL3_Init("#version 410");
Camera camera(width, height, window, 0.1f); Camera camera(width, height, window, 0.1f);
Cube cube{camera, glm::vec3 {0.f, 0.f, 0.f}, "stone.png"}; Cube cube{camera, glm::vec3{0.f, 0.f, 0.f}, "stone.png"};
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_MULTISAMPLE); glEnable(GL_MULTISAMPLE);
@@ -97,5 +110,5 @@ int main()
glfwDestroyWindow(window); glfwDestroyWindow(window);
glfwTerminate(); glfwTerminate();
return 0; return EXIT_SUCCESS;
} }