setup: switched from glut to glfw as windowing backend

This commit is contained in:
2025-08-21 22:21:21 +02:00
parent bc1940fb66
commit 255c7da8e5
2 changed files with 46 additions and 9 deletions

3
build.sh Executable file
View File

@@ -0,0 +1,3 @@
#! /bin/bash
g++ main.cpp -lGL -lglfw -lGLEW

View File

@@ -1,5 +1,5 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <GL/freeglut.h> #include <GLFW/glfw3.h>
#include <cstdio> #include <cstdio>
void display() { void display() {
@@ -20,20 +20,54 @@ void display() {
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
}*/ }*/
void processInput(GLFWwindow *window)
{
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
}
int main(int argc, char** argv) { int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); GLFWwindow* window;
glutInitWindowSize(800, 600);
glutCreateWindow("OpenGL Example"); if (!glfwInit())
return -1;
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
GLenum err = glewInit(); GLenum err = glewInit();
if (GLEW_OK != err) { if (GLEW_OK != err) {
fprintf(stderr, "GLEW error: %s\n", glewGetErrorString(err)); fprintf(stderr, "GLEW error: %s\n", glewGetErrorString(err));
return 1; return 1;
} }
glViewport(0, 0, 800, 600); glViewport(0, 0, 800, 600);
//glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glutDisplayFunc(display); while (!glfwWindowShouldClose(window))
glutMainLoop(); {
return 0; processInput(window);
/* Render here */
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
/* Poll for and process events */
glfwPollEvents();
glfwSwapBuffers(window);
} }
glfwTerminate();
}