打开GLAD的在线服务,将语言(Language)设置为C/C++,在API选项中,选择3.3以上的OpenGL(gl)版本(我们的教程中将使用3.3版本,但更新的版本也能用)。之后将模式(Profile)设置为Core,并且保证选中了生成加载器(Generate a loader)选项。现在可以先(暂时)忽略扩展(Extensions)中的内容。都选择完之后,点击生成(Generate)按钮来生成库文件。
# define library paths in addition to /usr/lib # if I wanted to include libraries not in /usr/lib I'd specify # their path using -Lpath, something like: LFLAGS := -lglfw3 -lopengl32 -lgdi32
# define any directories containing header files other than /usr/include INCLUDES := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%))
# define the C libs LIBS := $(patsubst %,-L%, $(LIBDIRS:%/=%))
# define the C source files SOURCES := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS))) $(wildcard $(patsubst %,%/*.c, $(SOURCEDIRS)))
# define the C object files OBJECTS := $(patsubst %.cpp,%.o,$(patsubst %.c,%.o,$(SOURCES)))
# define the dependency output files DEPS := $(OBJECTS:.o=.d)
# # The following part of the makefile is generic; it can be used to # build any executable just by changing the definitions above and by # deleting dependencies appended to the file from 'make depend' #
# this is a suffix replacement rule for building .o's and .d's from .c's # it uses automatic variables $<: the name of the prerequisite of # the rule(a .c file) and $@: the name of the target of the rule (a .o file) # -MMD generates dependency output files same name as the .o file # (see the gnu make manual section about automatic variables) .cpp.o: $(CXX)$(CXXFLAGS)$(INCLUDES) -c -MMD $< -o $@ .c.o: $(CXX)$(INCLUDES) -c -MMD $< -o $@
// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly // --------------------------------------------------------------------------------------------------------- voidprocessInput(GLFWwindow *window) { if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); }
// glfw: whenever the window size changed (by OS or user resize) this callback function executes // --------------------------------------------------------------------------------------------- voidframebuffer_size_callback(GLFWwindow* window, int width, int height) { // make sure the viewport matches the new window dimensions; note that width and // height will be significantly larger than specified on retina displays. glViewport(0, 0, width, height); }