>>24665bro never watched a tutorial
```
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
// Callback function for error handling
void error_callback(int error, const char* description) {
std
cerr << "Error: " << description << stdendl;
}
// Function to display the scene
void display() {
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
glBegin(GL_TRIANGLES); // Draw a triangle
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex2f(0.0f, 1.0f); // Top vertex
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex2f(-1.0f, -1.0f); // Bottom left vertex
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex2f(1.0f, -1.0f); // Bottom right vertex
glEnd();
}
int main() {
glfwSetErrorCallback(error_callback); // Set error callback
if (!glfwInit()) return -1; // Initialize GLFW
GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL with GLFW", nullptr, nullptr); // Create window
if (!window) {
glfwTerminate(); // Terminate if window creation failed
return -1;
}
glfwMakeContextCurrent(window); // Make the window's context current
if (glewInit() != GLEW_OK) {
error_callback(0, "glewInit");
}
std
cout << glGetString(GL_VERSION) << stdendl;
float positions[] {
-0.5f, -0.5f,
0.0f, 0.5f,
0.5f, -0.5f,
};
unsigned int buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float), positions, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), 0);
while (!glfwWindowShouldClose(window)) {
// display(); // Render the scene
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3); // without index buffer
// glDrawElements(GL_TRIANGLES, 3, ) // with index buffer
glfwSwapBuffers(window); // Swap front and back buffers
glfwPollEvents(); // Poll for and process events
}
glfwDestroyWindow(window); // Destroy window
glfwTerminate(); // Terminate GLFW
return 0;
}
```