Windows7+VS2012下OpenGL 4的环境配置

系统环境

        Windows 7 Ultimate x64,Visual Studio Ultimate 2012 Update 4,和一块支持OpenGL 4.x的显卡。


准备工作

        首先用GPU Caps Viewer检查机器最高支持的OpenGL及GLSL版本。比如我的机器可以支持OpenGL 4.5和GLSL 4.5:

gpu-caps-viewer

        下载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”:

cmake-1       

在弹出的窗口中选择“Visual Studio 11 2012”,点击“Finish”:

               cmake-2       

保持默认配置即可。如果想用头文件+.dll的方式调用GLFW,可以勾选“BUILD_SHARED_LINKS”;不勾选则是默认的头文件+.lib方式调用。为“CMAKE_INSTALL_PREFIX”选择一个新的位置,用来存放用VS2012编译输出的结果。然后点击“Generate”,VS2012项目文件就生成完毕了。

cmake-3

        打开刚刚指定的Build目录,用Visual Studio 2012打开GLFW.sln文件。为保险起见,先用Debug方式编译ZERO_CHECK,如果没有报错,则用Release方式编译ALL_BUILD,再编译INSTALL。

vs2012-glfw 

      如果编译成功,在之前指定的GLFW文件夹内会多出两个文件夹include和lib,这里面就包含着我们会用到的头文件和链接库文件:

glfw-directory       

 把include中的GLFW文件夹拷贝到一个你觉得方便的位置,比如“E:\dev-lib\opengl4\include”:

glfw-include       

把lib中的glfw3.lib文件拷贝到新的位置,比如“E:\dev-lib\opengl4\lib”:

glfw-lib


编译GLEW

        用Visual Studio 2012打开GLEW目录下build\vc10\glew.sln文件,第一次打开时会提示是否把VS2010项目转换成VS2012项目,选择是即可。选择Release方式,点击BUILD -> Build Solution:

vs2012-glew     

如果编译成功,会发现在bin\Release\Win32目录下有3个新文件。把glew32.dll文件拷贝到C:\Windows\SysWOW64目录下。

glew-bin       

 glewinfo.exe和visualinfo.exe可以用来查看系统对OpenGL各个特性的支持情况,比如:

glewinfo       

把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”:

vs2012-new-project       

右击项目名称,点击Properties。在Configuration Properties -> VC++ Directories中,为Include Directories添加“E:\dev-lib\opengl4\include;”;为Library Directories添加“E:\dev-lib\opengl4\lib;”。注意为Debug和Release都要添加:

project-properties       

在Configuration Properties -> Linker -> Input中,为Additional Dependencies添加“glew32.lib;glfw3.lib;opengl32.lib;”。注意为Debug和Release都要添加:

linker-input

        把以下代码拷贝到0gl4-test.cpp文件中。代码来自Anton's OpenGL 4 Tutorials

#include "stdafx.h"
#include <GL/glew.h>
//#define GLFW_DLL
#include <GLFW/glfw3.h>int 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 "closer"float 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\n""in vec3 vp;""void main () {""  gl_Position = vec4 (vp, 1.0);""}";const char* fragment_shader ="#version 400\n""out 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 we've been drawing onto the display
        glfwSwapBuffers (window);}// close GL context and any other GLFW resources
    glfwTerminate();return 0;
}

点击“Local Windows Debugger”,就可以看见如下效果:

triangle

 


另一枚例子

        这是一个用合成的Gerstner波绘制水面的例子,根据《水面的简单渲染 – Gerstner波》修改而来。完整代码下载地址:http://pan.baidu.com/s/1gdzoe4b,所需的配置文件下载地址:http://pan.baidu.com/s/1pJ81kyZ。项目托管地址:https://github.com/johnhany/OpenGLProjects/tree/master/GerstnerWave。

        效果如下:

gerstner-waves

原文链接:Windows7+VS2012下OpenGL 4的环境配置

转载于:https://www.cnblogs.com/rainbow70626/p/5557636.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/418428.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

前端学习(1965)vue之电商管理系统电商系统之渲染添加参数的按钮

目录结构 router.js import Vue from vue import Router from vue-router import Login from ./components/Login.vue import Home from ./components/Home.vue import Welcome from ./components/Welcome.vue import Users from ./components/user/Users.vue import Right fr…

构建之法08

需求问题 然后就是用户场景分析&#xff0c;在没有听课或者看这本书之前呢这些我是完全想不到的&#xff0c;那时候脑子里只有一个简单的想法——把功能实现了不就得了&#xff0c;哪有那摸多的麻烦事啊&#xff01;真的是和书上说的一样的那种人&#xff0c;但是看完书后发现是…

前端学习(1966)vue之电商管理系统电商系统之获取参数列表

目录结构 router.js import Vue from vue import Router from vue-router import Login from ./components/Login.vue import Home from ./components/Home.vue import Welcome from ./components/Welcome.vue import Users from ./components/user/Users.vue import Right fr…

【教训】rm -fr ./* 教训

昨晚犯了一个重大错误&#xff0c;运行了 rm -rf ./*本来是要删除一个不重要的目录的&#xff0c;结果在它的父目录下运行了上面命令&#xff0c;结果。。。都没了。。。 幸好数据库文件没有被删掉&#xff0c;数据还在&#xff0c;网站程序被删掉了&#xff0c;不久前有备份过…

在linux上安装与启动Elasticsearch

https://www.jianshu.com/p/975326e65f65

[修正] Berlin 10.1 支持 iPhone 4 (iOS v7.x)

原本在 Seattle 版本时&#xff0c;还能支持 iPhone 3GS (iOS v6.x), iPhone 4 (iOS v7.x)&#xff0c;到了 Berlin 已不支持了&#xff0c;在用户的抱怨下&#xff0c;只好自己尝试去修正它&#xff0c;经过一番努力&#xff0c;终于找到原来是 TNSLayoutConstraint 在搞鬼&am…

前端学习(1967)vue之电商管理系统电商系统之切换面板获取

目录结构 router.js import Vue from vue import Router from vue-router import Login from ./components/Login.vue import Home from ./components/Home.vue import Welcome from ./components/Welcome.vue import Users from ./components/user/Users.vue import Right fr…

Linux 退出vi编辑模式

https://www.cnblogs.com/cheneyboon/p/11454547.html

Python学习笔记——基础篇【第七周】———FTP作业(面向对象编程进阶 Socket编程基础)...

FTP作业 本节内容&#xff1a; 面向对象高级语法部分Socket开发基础作业&#xff1a;开发一个支持多用户在线的FTP程序面向对象高级语法部分 参考&#xff1a;http://www.cnblogs.com/wupeiqi/p/4766801.html metaclass 详解文章&#xff1a;http://stackoverflow.com/questio…

spring boot集成oss

https://my.oschina.net/u/3677987/blog/4309412

前端学习(1968)vue之电商管理系统电商系统之将不同的参数挂载到数据源上

目录结构 router.js import Vue from vue import Router from vue-router import Login from ./components/Login.vue import Home from ./components/Home.vue import Welcome from ./components/Welcome.vue import Users from ./components/user/Users.vue import Right fr…

在云服务器搭建WordPress博客(六)发布和管理文章

<(&#xffe3;︶&#xffe3;)↗[GO!] 发布文章是一个网站后台最重要的功能之一&#xff0c;WordPress的文章发布功能是比较强大的&#xff0c;系统简单地介绍一下。 访问后台 – 文章 – 写文章 &#xff0c;就可以看到如下图所示的界面&#xff1a; 一、编辑区 1.标题 –…

前端学习(1969)vue之电商管理系统电商系统之渲染动态参数和静态参数的表格

目录结构 router.js import Vue from vue import Router from vue-router import Login from ./components/Login.vue import Home from ./components/Home.vue import Welcome from ./components/Welcome.vue import Users from ./components/user/Users.vue import Right fr…

cron 在线生成

https://cron.qqe2.com/

数据库5 索引 动态哈希(Dynamic Hashing)

索引文件 聚集索引和非聚集索引 其实&#xff0c;我们的汉语字典的正文本身就是一个聚集索引。比如&#xff0c;我们要查“安”字&#xff0c;就会很自然地翻开字典的前几页&#xff0c;因为“安”的拼音是“an”&#xff0c;而按照拼音排序汉字的字典是以英文字母“a”开头并以…

前端学习(1970)vue之电商管理系统电商系统之渲染添加参数的对话框

目录结构 router.js import Vue from vue import Router from vue-router import Login from ./components/Login.vue import Home from ./components/Home.vue import Welcome from ./components/Welcome.vue import Users from ./components/user/Users.vue import Right fr…

java删除list元素的几种方式

方式一&#xff1a;使用Iterator的remove()方法 public class Test {public static void main(String[] args) {List<String> list new ArrayList<>();list.add("aa");list.add("bb");list.add("cc");Iterator<String> it …

php考试总结

Php基础知识测试题 姓名&#xff1a; 那 班级&#xff1a; 0410 成绩&#xff1a; 本试题共40道选择题&#xff0c;10道判断题&#xff0c;考试时间1个半小时 一&#xff1a;选择题&#xff08;单项选择&#xff0c;每题2分&#xff09;&#xff1a; 1&#xff0e; LAMP具体结构…

解决Mysql5.7以上版本, 使用group by抛出Expression #1 of SELECT list is not in GROUP BY clause and contains no异常

出现原因&#xff1a; MySQL 5.7.5和up实现了对功能依赖的检测。如果启用了only_full_group_by SQL模式(在默认情况下是这样)&#xff0c;那么MySQL就会拒绝选择列表、条件或顺序列表引用的查询&#xff0c;这些查询将引用组中未命名的非聚合列&#xff0c;而不是在功能上依赖于…