Skip to content

Instantly share code, notes, and snippets.

@gcatlin
Last active February 19, 2022 03:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcatlin/00173738eb879db0f246803c05b917bb to your computer and use it in GitHub Desktop.
Save gcatlin/00173738eb879db0f246803c05b917bb to your computer and use it in GitHub Desktop.
Minimal C GLFW OpenGL example
//
// 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