2025-04-01 01:25:39 +00:00
|
|
|
#include "Engine.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
GLFWwindow* Engine::window = nullptr;
|
|
|
|
|
|
|
|
bool Engine::Init() {
|
|
|
|
if (!glfwInit()) {
|
2025-04-01 16:02:52 +00:00
|
|
|
std::cout << "Failed to initialize GLFW\n";
|
2025-04-01 01:25:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Specify the OpenGL version (e.g., 3.3 Core Profile)
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
|
|
|
|
// Create the GLFW window
|
|
|
|
window = glfwCreateWindow(1280, 800, "Engine Window", nullptr, nullptr);
|
|
|
|
if (!window) {
|
2025-04-01 16:02:52 +00:00
|
|
|
std::cout << "Failed to create GLFW window\n";
|
2025-04-01 01:25:39 +00:00
|
|
|
glfwTerminate();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make the OpenGL context current
|
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
|
|
|
|
|
|
|
|
// Set the viewport size to match the framebuffer dimensions
|
|
|
|
int width, height;
|
|
|
|
glfwGetFramebufferSize(window, &width, &height);
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Engine::BeginFrame() {
|
|
|
|
// Clear the screen with a chosen color
|
|
|
|
glClearColor(0.0f, 0.2f, 0.4f, 1.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Engine::EndFrame() {
|
|
|
|
// Swap the front and back buffers and process events
|
|
|
|
glfwSwapBuffers(window);
|
|
|
|
glfwPollEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
GLFWwindow* Engine::GetWindow() {
|
|
|
|
return window;
|
|
|
|
}
|