市面上很多库 glfw glew freeglut 等等 这些都可以在官网下载。
编译这些很简单 下个Cmake软件就可以自己编译
配置我看网上很多说的比较复杂这里理清一下。
加载库
1、首先看你需要什么版本32还是64位。
2、引用lib库文件
3、引用库头文件
至于vs工程怎么配置很简单,网上有的是在项目管理配置里面添加的:
对应的添加默认库glfw3.lib和glew32.lib
这种直接引用头文件和库文件目录
项目里面代码只需要以下就行了
(附加库依赖和VC++库目录一样)
#include <glfw3.h>
还有种方法不设置项目属性直接在项目中引用 这种就需要把路径写下
//#include "./lib/glfw32/GLFW/glfw3.h" //#pragma comment (lib, "lib/glfw32/glfw3.lib") //#pragma comment (lib, "lib/glew32/glew32d.lib")
结构如下
很明显:项目配置无非就是把库路径加到系统内部去了 ,就像放入VS的VC库一样。
测试代码:
//#include "./lib/glfw32/GLFW/glfw3.h" //#pragma comment (lib, "lib/glfw32/glfw3.lib") //#pragma comment (lib, "lib/glew32/glew32d.lib") #include <glfw3.h> //#pragma comment (lib, "glfw3.lib") //#pragma comment (lib, "glew32d.lib") int main(void) { GLFWwindow* window; /* Initialize the library */ if (!glfwInit()) return -1; /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(480, 320, "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)) { /* Draw a triangle */ glBegin(GL_TRIANGLES); glColor3f(1.0, 0.0, 0.0); // Red glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 1.0, 0.0); // Green glVertex3f(-1.0, -1.0, 0.0); glColor3f(0.0, 0.0, 1.0); // Blue glVertex3f(1.0, -1.0, 0.0); glEnd(); /* Swap front and back buffers */ glfwSwapBuffers(window); /* Poll for and process events */ glfwPollEvents(); } glfwTerminate(); return 0; }