OpenGL环境搭建Windows+Mac+Linux

Mac平台下


下载列表:
GLFW
cmake

下载的GLFW解压缩

然后安装cmake, 安装好cmake之后打开

1.browse source, 选择GLFW的源码根目录

2.browse build, 选择要生成的工程目录,最好是空文件夹

3.点击Configure

选择Xcode, 然后点击Done

然后会出来这个画面

不要惊慌,再点击一次Configure应该就没有那么红了(主要是上面那么框中没有红得就可以了,下面那个一直存在红色)

4.然后点击Generate, 就生成工程了

双击GLFW.xcodeproj, XCode就会打开了

然后继续下面操作

选择Simple吧,然后运行就可以看到一个窗口了

我们可以在上面画一个三角形

  1. #include <GLFW/glfw3.h>
  2.  
  3. int main(void)
  4. {
  5. GLFWwindow* window;
  6.  
  7. /* Initialize the library */
  8. if (!glfwInit())
  9. return -;
  10.  
  11. /* Create a windowed mode window and its OpenGL context */
  12. window = glfwCreateWindow(, , "Hello World", NULL, NULL);
  13. if (!window)
  14. {
  15. glfwTerminate();
  16. return -;
  17. }
  18.  
  19. /* Make the window's context current */
  20. glfwMakeContextCurrent(window);
  21.  
  22. /* Loop until the user closes the window */
  23. while (!glfwWindowShouldClose(window))
  24. {
  25. /* Render here */
  26.  
  27. glClearColor(, , , );
  28. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  29.  
  30. static GLfloat vertexs[] = {
  31. -, -, ,
  32. , -, ,
  33. , ,
  34. };
  35. static GLubyte colors[] = {
  36. ,,,,
  37. ,,,,
  38. ,,,,
  39. };
  40.  
  41. glEnableClientState(GL_VERTEX_ARRAY);
  42. glEnableClientState(GL_COLOR_ARRAY);
  43.  
  44. glVertexPointer(, GL_FLOAT, , vertexs);
  45. glColorPointer(, GL_UNSIGNED_BYTE, , colors);
  46.  
  47. glDrawArrays(GL_TRIANGLES, , );
  48.  
  49. /* Swap front and back buffers */
  50. glfwSwapBuffers(window);
  51.  
  52. /* Poll for and process events */
  53. glfwPollEvents();
  54. }
  55.  
  56. glfwTerminate();
  57. return ;
  58. }

windows平台


直接在GLFW网站上下载 [Windows pre-compiled binaries], 下载32位版比较保险
下载后解压看到如下文件:

将include\GLFW里.h文件加入C:\Program Files (x86)\Windows Kits\8.0\Include\um\gl

如果你用的是vs2012
将lib-msvc110里的glfw3.lib,glfw3dll.lib放到C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x86
将lib-msvc110里的glfw3.dll放到C:\windows\System32

好了环境配置完毕!下面实战吧 打开vs2012创建一个win32 console的工程
然后创建一个main.cpp, 以后每个工程都要加这两句代码

  1. #pragma comment(lib,"opengl32.lib")
  2. #pragma comment(lib,"glfw3.lib")

下面我们绘制一个三角形吧!!

  1. #pragma comment(lib,"opengl32.lib")
  2. #pragma comment(lib,"glfw3.lib")
  3. #include <gl/glfw3.h>
  4. #include <gl/GL.h>
  5.  
  6. int main(void)
  7. {
  8. GLFWwindow* window;
  9.  
  10. /* Initialize the library */
  11. if (!glfwInit())
  12. return -;
  13.  
  14. /* Create a windowed mode window and its OpenGL context */
  15. window = glfwCreateWindow(, , "Hello World", NULL, NULL);
  16. if (!window)
  17. {
  18. glfwTerminate();
  19. return -;
  20. }
  21.  
  22. /* Make the window's context current */
  23. glfwMakeContextCurrent(window);
  24.  
  25. /* Loop until the user closes the window */
  26. while (!glfwWindowShouldClose(window))
  27. {
  28. /* Render here */
  29. glClearColor(,,,);
  30. glClear(GL_COLOR_BUFFER_BIT);
  31.  
  32. static GLfloat pvertexs[] = {
  33. -, -, ,
  34. , -, ,
  35. , ,
  36. };
  37. static GLfloat color[] = {
  38. ,,,,
  39. ,,,,
  40. ,,,
  41. };
  42. glEnableClientState(GL_COLOR_ARRAY);
  43. glEnableClientState(GL_VERTEX_ARRAY);
  44.  
  45. glVertexPointer(, GL_FLOAT, , pvertexs);
  46. glColorPointer(, GL_FLOAT, , color);
  47.  
  48. glDrawArrays(GL_TRIANGLES, , );
  49.  
  50. /* Swap front and back buffers */
  51. glfwSwapBuffers(window);
  52.  
  53. /* Poll for and process events */
  54. glfwPollEvents();
  55. }
  56.  
  57. glfwTerminate();
  58. return ;
  59. } 

效果图:

Linux平台


在Linux上安装也比较简单,首先还是安装cmake,这里安装的命令行的cmake(到了linux下不用命令行不显逼格)

然后安装 xorg-devlibglu1-mesa-dev,基于debian的linux(ubuntu,mint...)可以使用如下命令安装

  1. sudo apt-get install xorg-dev
  2. sudo apt-get install libglu1-mesa-dev

安装后将glfw解压缩到一个文件夹glfw中,然后选择一个你要生成文件的位置(空白文件夹)test

1.打开命令行,cd 到你的test文件夹中

  1. cd '/home/luwei/Downloads/test'

2.使用cmake命令指向glfw文件夹生成文件

  1. cmake '/home/luwei/Downloads/glfw'

3.输入编译命令,编译源码

  1. make

现在生成的可执行文件都在test文件夹中了,生成位置对应glfw的文件目录结构,输入命令运行程序

  1. ./examples/simple

我们自己写个自己的OpenGL的程序吧

找到glfw/examples/simple.c,使用你习惯的编辑器打开,然后写自己的OpenGL程序

这里我还是使用上面的那段程序啦(注意引入的头文件路径不同了)

写完之后,要重新make命令编译,在test文件夹下使用make命令编译,然后运行。

总结


哎!!!总算都出来了,OpenGL编程记住一大堆函数和它该用啥参数是让我很苦恼的事情,尤其是Linux下我用编辑器写的程序根本没有代码提示,没办法记性不好呀

OpenGL环境搭建Windows+Mac+Linux的更多相关文章

  1. android 环境搭建 windows, linux

    android环境也搭建了很多次了,linux下window下.在这里记录下,以后再搭建设置变量啥的就直接看自己的博客就好了.电子挡笔记有时候也不方便 1.下载材料 概述:用的是比较简单的方式搭建环境 ...

  2. [.net 面向对象程序设计深入](5)MVC 6 —— 构建跨平台.NET开发环境(Windows/Mac OS X/Linux)

    [.net 面向对象程序设计深入](5)MVC 6 —— 构建跨平台.NET开发环境(Windows/Mac OS X/Linux) 1.关于跨平台 上篇中介绍了MVC的发展历程,说到ASP.NET ...

  3. 在eclipse里配置Android ndk环境 适用于windows mac 和linux(转)

    在eclipse里配置Android ndk环境 适用于windows mac 和linux(转) 2012-02-27 13:02:16|  分类: android |  标签:java  prog ...

  4. Setting up a EDK II build environment on Windows and Linux:搭建Windows和Linux开发环境[2.2]

    Setting up a EDK II build environment on Windows and Linux:搭建Windows和Linux开发环境[2.2] 2015-07   北京海淀区  ...

  5. MAC OpenGL 环境搭建

    MAC OpenGL 环境搭建 基础库介绍 先要安装两个库一个是GLEW(OpenGL Extension Wrangler Library),另外一个是GLFW(Graphics Library F ...

  6. 【Lua学习笔记之:Lua环境搭建 Windows 不用 visual studio】

    Lua 环境搭建 Windows 不用 visual studio 系统环境:Win7 64bit 联系方式:yexiaopeng1992@126.com 前言: 最近需要学习Unity3d游戏中的热 ...

  7. 【mongodb 学习一】环境搭建之 mac 下连接 mongodb 的UI 客户端

    记录下 mongodb 的学习 懒得自己达 mongodb 的服务器了 虽然一句命令就能搞定了 brew install mongodb 可是考虑到以后的应用还是放在网上的,就直接用现成的服务吧 下载 ...

  8. Python环境搭建(windows)

    Python环境搭建(windows) Python简介 Python(英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/),是一种面向对象.直译式计算机编程语言,具有近二十年的发展历史,成 ...

  9. Laravel 开发环境搭建 - Windows

    Laravel 开发环境搭建 - Windows  :   https://laravel-china.org/docs/laravel-development-environment/5.5/dev ...

随机推荐

  1. 关于js with语句的一些理解

    关于js with语句的一些理解   今天看到js的with语句部分,书中写到,with语句接收的对象会添加到作用域链的前端并在代码执行完之后移除.看到这里,我有两点疑问,添加到作用域链前端是不是指对 ...

  2. nodejs笔记二--文件I/O;

    一.写入文件: fs.writeFile(filename, data, callback),数据参数可以是string或者是Buffer,编码格式参数可选,默认为"utf8",回 ...

  3. EasyUI 在aspx页面显示高度不正常解决办法

    <body class="easyui-layout"> <form id="form1" runat="server"& ...

  4. bzoj 1041 圆上的整点 分类: Brush Mode 2014-11-11 20:15 80人阅读 评论(0) 收藏

    这里先只考虑x,y都大于0的情况 如果x^2+y^2=r^2,则(r-x)(r+x)=y*y 令d=gcd(r-x,r+x),r-x=d*u^2,r+x=d*v^2,显然有gcd(u,v)=1且u&l ...

  5. 项目分析(PLUG)

    plug过程 .INIT_PLUG #define INIT_PLUG Plug::InitPlug g_InitPlug(true); //共享内存数据结构 struct PlugShareMemo ...

  6. shiro添加注解@RequiresPermissions不起作用

    这是因为没有开启spring拦截器,在spring-mvc.xml中加入以下代码就可以了(一定要写在最先加载的xml中,写在后面加载的xml中也不起作用) <bean class="o ...

  7. javascript高级函数

    高级函数 安全的类型检测 js内置的类型检测并非完全可靠,typeof操作符难以判断某个值是否为函数 instanceof在多个frame的情况下,会出现问题. 例如:var isArray = va ...

  8. Oracle 时间处理(加减)

    一. 类似SQL SERVER中DateAdd select sysdate,add_months(sysdate,12) from dual;        --加1年 select sysdate ...

  9. PE文件结构学习

    PE:Portable Executable File Format(可移植的执行体).Windows平台主流可执行文件格式..exe与.dll文件都是PE格式.32位的叫做PE32,64位的叫做PE ...

  10. spring 两个 properties

    A模块和B模块都分别拥有自己的Spring XML配置,并分别拥有自己的配置文件: A模块 A模块的Spring配置文件如下: <?xml version="1.0" enc ...