53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
#include <glad/glad.h> // Include GLAD before GLFW
|
|
#include <GLFW/glfw3.h>
|
|
#include <iostream>
|
|
|
|
// Callback to resize the viewport when the window is resized
|
|
void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
|
|
(void)window; // Unused parameter
|
|
glViewport(0, 0, width, height);
|
|
}
|
|
|
|
int main() {
|
|
// 1. Initialize GLFW
|
|
glfwInit();
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
// 2. Create the Window
|
|
GLFWwindow *window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
|
if (window == NULL) {
|
|
std::cout << "Failed to create GLFW window" << std::endl;
|
|
glfwTerminate();
|
|
return -1;
|
|
}
|
|
glfwMakeContextCurrent(window);
|
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
|
|
|
// 3. Initialize GLAD (Load function pointers)
|
|
if (!gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress))){
|
|
std::cout << "Failed to initialize GLAD" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// 4. The Render Loop
|
|
while (!glfwWindowShouldClose(window)) {
|
|
// Input
|
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
|
glfwSetWindowShouldClose(window, true);
|
|
|
|
// Rendering commands here
|
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f); // Set clear color (Teal)
|
|
glClear(GL_COLOR_BUFFER_BIT); // Clear the screen
|
|
|
|
// Swap buffers and poll IO events
|
|
glfwSwapBuffers(window);
|
|
glfwPollEvents();
|
|
}
|
|
|
|
// 5. Clean up
|
|
glfwTerminate();
|
|
return 0;
|
|
}
|