Last active
December 21, 2024 23:57
-
-
Save gcatlin/00173738eb879db0f246803c05b917bb to your computer and use it in GitHub Desktop.
Minimal C GLFW OpenGL example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// cc glfw-opengl-example.c glad.c -lglfw | |
// | |
#include "glad.h" // https://glad.dav1d.de/ | |
#include <GLFW/glfw3.h> | |
static void quit(GLFWwindow *window, int key, int scancode, int action, int mods) | |
{ | |
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { | |
glfwSetWindowShouldClose(window, GLFW_TRUE); | |
} | |
} | |
int main() | |
{ | |
glfwInit(); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); | |
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | |
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); | |
GLFWwindow *window = glfwCreateWindow(1280, 720, "GLFW OpenGL", NULL, NULL); | |
glfwMakeContextCurrent(window); | |
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); | |
glfwSetKeyCallback(window, quit); | |
while (!glfwWindowShouldClose(window)) { | |
glfwPollEvents(); | |
glClearColor(0.3, 0.3, 0.3, 1.0); | |
glClear(GL_COLOR_BUFFER_BIT); | |
glfwSwapBuffers(window); | |
} | |
glfwDestroyWindow(window); | |
glfwTerminate(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment