Here's the code if anyone wants to try it:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
int main() {
glfwSetErrorCallback([](int error, const char* description) {
std::cerr << "GLFW Error (" << error << "): " << description << std::endl;
});
// 1. Initialize GLFW
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW" << std::endl;
return -1;
}
// 2. Create a windowed mode window and its OpenGL context
GLFWwindow* window = glfwCreateWindow(640, 480, "Hello Triangle", NULL, NULL);
if (!window) {
std::cerr << "Failed to create window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// 3. Initialize GLEW (must be done after making context current)
if (glewInit() != GLEW_OK) {
std::cerr << "Failed to initialize GLEW" << std::endl;
return -1;
}
// 4. Loop until the user closes the window
while (!glfwWindowShouldClose(window)) {
// Render here
glClear(GL_COLOR_BUFFER_BIT);
// Draw a simple triangle using "Legacy" style for immediate testing
// Note: Modern OpenGL uses Shaders and Buffers (VBOs)
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(-0.5f, -0.5f);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(0.5f, -0.5f);
glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(0.0f, 0.5f);
glEnd();
// Swap front and back buffers
glfwSwapBuffers(window);
// Poll for and process events
glfwPollEvents();
}
glfwTerminate();
std::cout << "Progam terminated" << std::endl;
return 0;
}