commit c616c3d7deb7b976ab893b8b7455fd034fea0d93
parent c14d337b94f0592b16988060b8f09a0e1db832f9
Author: amin <dev@aminmesbah.com>
Date: Tue, 15 May 2018 06:18:32 +0000
Use glfw and glad
FossilOrigin-Name: 286979a1cd68324c134704050d2aad3288eb77a5d77af9bcaf7aa2e45e6a09bf
Diffstat:
3 files changed, 71 insertions(+), 17 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,7 +1,6 @@
*.out
*.swp
-debug/*
-release/*
+build/*
tags
diff --git a/Makefile b/Makefile
@@ -1,42 +1,45 @@
CC = clang
-CFLAGS = -std=c99 -Wall -Wextra -Wshadow -Wswitch-enum -Wno-unused-parameter -Wno-missing-braces
-LDFLAGS = -lglfw -lGL -lGLEW -lGLU -lm -lX11 -lpthread -lXrandr -lXi
+CFLAGS = -std=c99 -Ilib -Wall -Wextra -Wshadow -Wswitch-enum -Wno-unused-parameter -Wno-missing-braces
+LDFLAGS = -ldl -lglfw -lGL -lGLEW -lGLU -lm -lpthread -lX11 -lXi -lXrandr
-SRC_FILES = main.c
+SRC_FILES = glad.c main.c
SRC = $(addprefix src/, $(SRC_FILES))
EXE_FILE = a_game
-DBGDIR = debug
+DBGDIR = build/debug
DBGEXE = $(DBGDIR)/$(EXE_FILE)
DBGCFLAGS = -g -Og -Werror
-RELDIR = release
+RELDIR = build/release
RELEXE = $(RELDIR)/$(EXE_FILE)
RELCFLAGS = -O2 -Os
-.PHONY: all clean compile_debug compile_release debug lib_debug lib_release memcheck prep run todo
+.PHONY: all clean debug debug_dir gdb memcheck memcheck release release_dir run todo
-all: compile_debug compile_release
+all: debug release
clean:
rm -f $(RELDIR)/* $(DBGDIR)/*
-compile_debug: prep lib_debug
+debug: debug_dir
$(CC) $(CFLAGS) $(DBGCFLAGS) $(SRC) -o $(DBGEXE) $(LDFLAGS)
-compile_release: prep lib_release
- $(CC) $(CFLAGS) $(RELCFLAGS) $(SRC) -o $(RELEXE) $(LDFLAGS)
+debug_dir:
+ @mkdir -p $(DBGDIR)
-debug: compile_debug
+gdb: debug
gdb $(DBGEXE)
-memcheck: compile_debug
+memcheck: debug
valgrind --track-origins=yes ./$(DBGEXE)
-prep:
- @mkdir -p $(DBGDIR) $(RELDIR)
+release: release_dir
+ $(CC) $(CFLAGS) $(RELCFLAGS) $(SRC) -o $(RELEXE) $(LDFLAGS)
+
+release_dir:
+ @mkdir -p $(RELDIR)
-run: compile_release
+run: release
./$(RELEXE)
todo:
diff --git a/src/main.c b/src/main.c
@@ -1,6 +1,58 @@
#include <stdio.h>
+#include <glad/glad.h>
+#include <GLFW/glfw3.h>
+
+#ifdef GLAD_DEBUG
+void pre_gl_callback(const char *func_name, void *func_ptr, int len_args, ...)
+{
+ printf("Calling: %s (%d arguments)\n", func_name, len_args);
+}
+#endif
+
+void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
+#define SCR_WIDTH 800
+#define SCR_HEIGHT 600
+
int main(void)
{
+ glfwSetErrorCallback(error_callback);
+
+ if (!glfwInit())
+ {
+ fprintf(stderr, "GLFW initialization failed");
+ return -1;
+ }
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+
+ GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "A Game", NULL, NULL);
+ if (!window)
+ {
+ fprintf(stderr, "GLFW window creation failed");
+ glfwTerminate();
+ return -1;
+ }
+
+ glfwMakeContextCurrent(window);
+ if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress))
+ {
+ fprintf(stderr, "glad initialization failed");
+ return -1;
+ }
+
printf("Hello, world");
+
+ while (!glfwWindowShouldClose(window))
+ {
+ }
+
+ glfwDestroyWindow(window);
+ glfwTerminate();
+ return 0;
}