Skip to content

Instantly share code, notes, and snippets.

@ancientstraits
Created June 2, 2021 04:29
Show Gist options
  • Save ancientstraits/fd388214cb7d4d7adbc0f9ed2c60cb0a to your computer and use it in GitHub Desktop.
Save ancientstraits/fd388214cb7d4d7adbc0f9ed2c60cb0a to your computer and use it in GitHub Desktop.
Quick OpenGL tutorial
// For video https://youtu.be/7_0ZqdPqQ1I
// Put in "src" directory
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
if (!glfwInit()) {
fprintf(stderr, "Failed to initialize GLFW\n");
return 1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(1024, 768, "Game", NULL, NULL);
if (!window) {
fprintf(stderr, "Failed to create window\n");
return 1;
}
glfwMakeContextCurrent(window);
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLFW\n");
return 1;
}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GLFW_TRUE);
while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&
!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
# For video https://youtu.be/7_0ZqdPqQ1I
OBJS = $(patsubst src/%.c, obj/%.o, $(wildcard src/*.c))
CFLAGS = -Iinclude -g -ggdb `pkg-config --cflags glfw3 glew`
LIBS = `pkg-config --libs glfw3 glew` -lm
DEPS = $(wildcard include/*.h)
EXEC = main
obj/%.o: src/%.c $(DEPS)
$(CC) -o $@ -c $< $(CFLAGS)
$(EXEC): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment