OpenGL环境搭建Windows+Mac+Linux
OpenGL环境搭建Windows+Mac+Linux
Mac平台下
下载的GLFW解压缩

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

1.browse source, 选择GLFW的源码根目录
2.browse build, 选择要生成的工程目录,最好是空文件夹
3.点击Configure

选择Xcode, 然后点击Done
然后会出来这个画面

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

双击GLFW.xcodeproj, XCode就会打开了
然后继续下面操作

选择Simple吧,然后运行就可以看到一个窗口了
我们可以在上面画一个三角形
#include <GLFW/glfw3.h> int main(void)
{
GLFWwindow* window; /* Initialize the library */
if (!glfwInit())
return -; /* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(, , "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -;
} /* Make the window's context current */
glfwMakeContextCurrent(window); /* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */ glClearColor(, , , );
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); static GLfloat vertexs[] = {
-, -, ,
, -, ,
, ,
};
static GLubyte colors[] = {
,,,,
,,,,
,,,,
}; glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(, GL_FLOAT, , vertexs);
glColorPointer(, GL_UNSIGNED_BYTE, , colors); glDrawArrays(GL_TRIANGLES, , ); /* Swap front and back buffers */
glfwSwapBuffers(window); /* Poll for and process events */
glfwPollEvents();
} glfwTerminate();
return ;
}

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, 以后每个工程都要加这两句代码
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glfw3.lib")
下面我们绘制一个三角形吧!!
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glfw3.lib")
#include <gl/glfw3.h>
#include <gl/GL.h> int main(void)
{
GLFWwindow* window; /* Initialize the library */
if (!glfwInit())
return -; /* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(, , "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -;
} /* Make the window's context current */
glfwMakeContextCurrent(window); /* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClearColor(,,,);
glClear(GL_COLOR_BUFFER_BIT); static GLfloat pvertexs[] = {
-, -, ,
, -, ,
, ,
};
static GLfloat color[] = {
,,,,
,,,,
,,,
};
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(, GL_FLOAT, , pvertexs);
glColorPointer(, GL_FLOAT, , color); glDrawArrays(GL_TRIANGLES, , ); /* Swap front and back buffers */
glfwSwapBuffers(window); /* Poll for and process events */
glfwPollEvents();
} glfwTerminate();
return ;
}
效果图:

Linux平台
在Linux上安装也比较简单,首先还是安装cmake,这里安装的命令行的cmake(到了linux下不用命令行不显逼格)
然后安装 xorg-dev, libglu1-mesa-dev,基于debian的linux(ubuntu,mint...)可以使用如下命令安装
sudo apt-get install xorg-dev
sudo apt-get install libglu1-mesa-dev
安装后将glfw解压缩到一个文件夹glfw中,然后选择一个你要生成文件的位置(空白文件夹)test中
1.打开命令行,cd 到你的test文件夹中
cd '/home/luwei/Downloads/test'
2.使用cmake命令指向glfw文件夹生成文件
cmake '/home/luwei/Downloads/glfw'
3.输入编译命令,编译源码
make
现在生成的可执行文件都在test文件夹中了,生成位置对应glfw的文件目录结构,输入命令运行程序
./examples/simple
我们自己写个自己的OpenGL的程序吧
找到glfw/examples/simple.c,使用你习惯的编辑器打开,然后写自己的OpenGL程序
这里我还是使用上面的那段程序啦(注意引入的头文件路径不同了)
写完之后,要重新make命令编译,在test文件夹下使用make命令编译,然后运行。
总结
哎!!!总算都出来了,OpenGL编程记住一大堆函数和它该用啥参数是让我很苦恼的事情,尤其是Linux下我用编辑器写的程序根本没有代码提示,没办法记性不好呀
OpenGL环境搭建Windows+Mac+Linux的更多相关文章
- android 环境搭建 windows, linux
android环境也搭建了很多次了,linux下window下.在这里记录下,以后再搭建设置变量啥的就直接看自己的博客就好了.电子挡笔记有时候也不方便 1.下载材料 概述:用的是比较简单的方式搭建环境 ...
- [.net 面向对象程序设计深入](5)MVC 6 —— 构建跨平台.NET开发环境(Windows/Mac OS X/Linux)
[.net 面向对象程序设计深入](5)MVC 6 —— 构建跨平台.NET开发环境(Windows/Mac OS X/Linux) 1.关于跨平台 上篇中介绍了MVC的发展历程,说到ASP.NET ...
- 在eclipse里配置Android ndk环境 适用于windows mac 和linux(转)
在eclipse里配置Android ndk环境 适用于windows mac 和linux(转) 2012-02-27 13:02:16| 分类: android | 标签:java prog ...
- 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 北京海淀区 ...
- MAC OpenGL 环境搭建
MAC OpenGL 环境搭建 基础库介绍 先要安装两个库一个是GLEW(OpenGL Extension Wrangler Library),另外一个是GLFW(Graphics Library F ...
- 【Lua学习笔记之:Lua环境搭建 Windows 不用 visual studio】
Lua 环境搭建 Windows 不用 visual studio 系统环境:Win7 64bit 联系方式:yexiaopeng1992@126.com 前言: 最近需要学习Unity3d游戏中的热 ...
- 【mongodb 学习一】环境搭建之 mac 下连接 mongodb 的UI 客户端
记录下 mongodb 的学习 懒得自己达 mongodb 的服务器了 虽然一句命令就能搞定了 brew install mongodb 可是考虑到以后的应用还是放在网上的,就直接用现成的服务吧 下载 ...
- Python环境搭建(windows)
Python环境搭建(windows) Python简介 Python(英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/),是一种面向对象.直译式计算机编程语言,具有近二十年的发展历史,成 ...
- Laravel 开发环境搭建 - Windows
Laravel 开发环境搭建 - Windows : https://laravel-china.org/docs/laravel-development-environment/5.5/dev ...
随机推荐
- 如何在Win10下设置图片的浏览方式为windows照片查看器
小编前些天刚装好了win10,一阵心奋啊,今天刚打开一个图片,却发现图片的默认打开方式是window应用商店的app, 这让我觉得特别不舒服,没有之前windows自带的照片查看器好用,后来我本想进入 ...
- 查看Android应用签名信息
本文档介绍在Android下如何查看自己的应用签名及三方APK或系统APK签名信息,包含其中的MD5.SHA1.SHA256值和签名算法等信息. 1.查看自己的应用签名 可以通过两种方式查看 (1) ...
- gmail邮箱怎么批量删除邮件
转载:http://jingyan.baidu.com/article/9f7e7ec056cbcd6f2815543c.html 首先打开gmail邮箱,随便打开一封邮件,找到发件人邮件地址,复制, ...
- sqlserver2008r2 127.0.0.1 用户sa登录失败 错误18456
按照网上的所有方法都试过了,还是不行. 最后,将sa密码重新设置一下,解决问题.
- JS 学习笔记--4---运算符
1.JS 中包含的运算符有:一元运算符.二元运算符.三元运算符.算术运算符.关系运算符.逻辑运算符.位运算符.赋值运算符.其他的运算符等. 2.表达式:简单来讲就是一句代码(分号隔开),解释器会把它翻 ...
- flex Chrome flash调试时 出现Shockwave flash has crashed的解决办法
在Chrome中输入:chrome://plugins/ PPAPI的Flash Player停用. 使用NPAPI的Flash player. 这里好像没有显示是Debug版本. 但是我在调 ...
- python开发中常用的框架
以下是15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python Web应用开发框架 Django 应该是最出名的 ...
- mybatis中:returned more than one row, where no more than one was expected.异常
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorEx ...
- 同一网站不同和二级域名和不同子目录的cookie
1.cookie二级域名的实现: 用户其中一个站点登录,而且可以各个子频道间切换,保持登录状态设置Cookie时,使用如下代码即可:setcookie(name,value,expire,path,& ...
- 【mysql5.6】连接vs2010
参考这篇博客:http://www.tuicool.com/articles/mUZNne 配置:vs2010项目属性里面配置包含目录和库目录. 包含目录:C:\Program Files\MySQL ...
