glfw3是glut之后的比较流行的opengl的渲染框架,同样他支持双缓冲等,具体看glfw3的doc
1.编写makefile
CC = g++
# -O2 : optimization option
# -s : build small binary
# -mwindows : use this option to remove the popping cmd window
CCFLAGS = -O2 -Wall
BIN = Demo.exe
WINDRES = windres
COMMONC =
RES =
OBJ =
# MinGWLib路径
MGBPATH = 'D:\ProgramFiles\MinGW\lib'
# 项目Lib路径
CUBPATH = lib
# 项目头文件路径
CUCPATH = include
# 连接库文件
LIBS =-L$(CUBPATH) -lglfw3 -lgdi32
INCLU =-I$(CUCPATH)
RM = -del
# 编译源码
$(BIN): Demo.cpp
$(CC) $(CCFLAGS) -o $(BIN) -c $^ $(INCLU) $(LIBS)
# 清理,PHONY避免无依赖时被看成最终目标
.PHONY:clean
clean:
$(RM) $(BIN) $(OBJ)
# 直接运行生成的文件
# .PHONY:run
run:$(BIN)
$(BIN)
记住这里我们使用mingw中的g++是4.0+的,而官方的提供glfw3的mingw版式3.+的版本的,所以需要-c指定源文件,否则会__chkstk_ms的失败
2.官方的例子
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
3.接着在cmd下set你的minwg的bin路径(个人不喜欢把bin加入系统path,只是临时使用,因为当你的开发工具太多时经常出现版本冲突问题等)
F:\work\opengl\_draw_triangle>make
g++ -O2 -Wall -o Demo.exe -c Demo.cpp -Iinclude -Llib -lglfw3 -lgdi32
F:\work\opengl\_draw_triangle>
4.
