做网站有必要要源码吗,百度做网站联系电话,学做网站视频,找设计师系统环境 Windows 7 Ultimate x64#xff0c;Visual Studio Ultimate 2012 Update 4#xff0c;和一块支持OpenGL 4.x的显卡。 准备工作 首先用GPU Caps Viewer检查机器最高支持的OpenGL及GLSL版本。比如我的机器可以支持OpenGL 4.5和GLSL 4.5#xff1a; 下载GLEW和GLFW的源… 系统环境 Windows 7 Ultimate x64Visual Studio Ultimate 2012 Update 4和一块支持OpenGL 4.x的显卡。 准备工作 首先用GPU Caps Viewer检查机器最高支持的OpenGL及GLSL版本。比如我的机器可以支持OpenGL 4.5和GLSL 4.5 下载GLEW和GLFW的源码。其中GLEW用来管理和载入OpenGL的各种扩展库GLFW用来创建窗口和控制鼠标及键盘的交互。我使用的版本分别是glew-1.12.0和glfw-3.1.1。下载地址分别为 https://sourceforge.net/projects/glew/files/glew/1.12.0/glew-1.12.0.zip/download http://sourceforge.net/projects/glfw/files/glfw/3.1.1/glfw-3.1.1.zip/download 下载并安装CMAKE。用来辅助编译GLFW。我使用的版本为cmake-3.2.1。下载地址为 http://www.cmake.org/files/v3.2/cmake-3.2.1-win32-x86.exe 编译GLFW 打开CMAKE。点击“Browsw source…”选择GLFW的根目录点击“Browse build…”任意选取一个新建的文件夹作为输出目录。点击“Configure” 在弹出的窗口中选择“Visual Studio 11 2012”点击“Finish” 保持默认配置即可。如果想用头文件.dll的方式调用GLFW可以勾选“BUILD_SHARED_LINKS”不勾选则是默认的头文件.lib方式调用。为“CMAKE_INSTALL_PREFIX”选择一个新的位置用来存放用VS2012编译输出的结果。然后点击“Generate”VS2012项目文件就生成完毕了。 打开刚刚指定的Build目录用Visual Studio 2012打开GLFW.sln文件。为保险起见先用Debug方式编译ZERO_CHECK如果没有报错则用Release方式编译ALL_BUILD再编译INSTALL。 如果编译成功在之前指定的GLFW文件夹内会多出两个文件夹include和lib这里面就包含着我们会用到的头文件和链接库文件 把include中的GLFW文件夹拷贝到一个你觉得方便的位置比如“E:\dev-lib\opengl4\include” 把lib中的glfw3.lib文件拷贝到新的位置比如“E:\dev-lib\opengl4\lib” 编译GLEW 用Visual Studio 2012打开GLEW目录下build\vc10\glew.sln文件第一次打开时会提示是否把VS2010项目转换成VS2012项目选择是即可。选择Release方式点击BUILD - Build Solution 如果编译成功会发现在bin\Release\Win32目录下有3个新文件。把glew32.dll文件拷贝到C:\Windows\SysWOW64目录下。 glewinfo.exe和visualinfo.exe可以用来查看系统对OpenGL各个特性的支持情况比如 把lib\Release\Win32目录下的glew32.lib拷贝到之前的“E:\dev-lib\opengl4\lib”中。把include目录中的GL文件夹拷贝到之前的“E:\dev-lib\opengl4\include”中。 新建项目 打开Visual Studio 2012点击FILE - New - Project…选择Visual C - Win32 Console Application。比如命名为“ogl4-test” 右击项目名称点击Properties。在Configuration Properties - VC Directories中为Include Directories添加“E:\dev-lib\opengl4\include;”为Library Directories添加“E:\dev-lib\opengl4\lib;”。注意为Debug和Release都要添加 在Configuration Properties - Linker - Input中为Additional Dependencies添加“glew32.lib;glfw3.lib;opengl32.lib;”。注意为Debug和Release都要添加 把以下代码拷贝到0gl4-test.cpp文件中。代码来自Antons OpenGL 4 Tutorials #include stdafx.h
#include GL/glew.h
//#define GLFW_DLL
#include GLFW/glfw3.hint main(int argc, _TCHAR* argv[])
{// start GL context and O/S window using the GLFW helper libraryif (!glfwInit ()) {fprintf (stderr, ERROR: could not start GLFW3\n);return 1;} GLFWwindow* window glfwCreateWindow (800, 600, Hello Triangle, NULL, NULL);if (!window) {fprintf (stderr, ERROR: could not open window with GLFW3\n);glfwTerminate();return 1;}glfwMakeContextCurrent (window);// start GLEW extension handlerglewExperimental GL_TRUE;glewInit ();// get version infoconst GLubyte* renderer glGetString (GL_RENDERER); // get renderer stringconst GLubyte* version glGetString (GL_VERSION); // version as a stringprintf (Renderer: %s\n, renderer);printf (OpenGL version supported %s\n, version);// tell GL to only draw onto a pixel if the shape is closer to the viewerglEnable (GL_DEPTH_TEST); // enable depth-testingglDepthFunc (GL_LESS); // depth-testing interprets a smaller value as closerfloat points[] {0.0f, 0.5f, 0.0f,0.5f, -0.5f, 0.0f,-0.5f, -0.5f, 0.0f};GLuint vbo 0;glGenBuffers (1, vbo);glBindBuffer (GL_ARRAY_BUFFER, vbo);glBufferData (GL_ARRAY_BUFFER, 9 * sizeof (float), points, GL_STATIC_DRAW);GLuint vao 0;glGenVertexArrays (1, vao);glBindVertexArray (vao);glEnableVertexAttribArray (0);glBindBuffer (GL_ARRAY_BUFFER, vbo);glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL);const char* vertex_shader #version 400\nin vec3 vp;void main () { gl_Position vec4 (vp, 1.0);};const char* fragment_shader #version 400\nout vec4 frag_colour;void main () { frag_colour vec4 (0.5, 0.0, 0.5, 1.0);};GLuint vs glCreateShader (GL_VERTEX_SHADER);glShaderSource (vs, 1, vertex_shader, NULL);glCompileShader (vs);GLuint fs glCreateShader (GL_FRAGMENT_SHADER);glShaderSource (fs, 1, fragment_shader, NULL);glCompileShader (fs);GLuint shader_programme glCreateProgram ();glAttachShader (shader_programme, fs);glAttachShader (shader_programme, vs);glLinkProgram (shader_programme);// Loop until the user closes the windowwhile (!glfwWindowShouldClose(window)){// wipe the drawing surface clearglClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glUseProgram (shader_programme);glBindVertexArray (vao);// draw points 0-3 from the currently bound VAO with current in-use shaderglDrawArrays (GL_TRIANGLES, 0, 3);// update other events like input handling glfwPollEvents ();// put the stuff weve been drawing onto the displayglfwSwapBuffers (window);}// close GL context and any other GLFW resourcesglfwTerminate();return 0;
} 点击“Local Windows Debugger”就可以看见如下效果 另一枚例子 这是一个用合成的Gerstner波绘制水面的例子根据《水面的简单渲染 – Gerstner波》修改而来。完整代码下载地址http://pan.baidu.com/s/1gdzoe4b所需的配置文件下载地址http://pan.baidu.com/s/1pJ81kyZ。项目托管地址https://github.com/johnhany/OpenGLProjects/tree/master/GerstnerWave。 效果如下 原文链接Windows7VS2012下OpenGL 4的环境配置 转载于:https://www.cnblogs.com/rainbow70626/p/5557636.html