Ubuntu12.04 64位
一、建立基本编译环境
1.首先不可或缺的,就是编译器与基本的函数库,如果系统没有安装的话,请依照下面的方式安装:
sudo apt-get install build-essential
sudo apt-get install libgl1-mesa-dev
3.安装OpenGL UtilitiesOpenGL Utilities 是一组建构于 OpenGL Library 之上的工具组,提供许多很方便的函数,使 OpenGL 更强大且更容易使用。 接下来我们安装OpenGL Utilities
sudo apt-get install libglu1-mesa-dev
sudo apt-get install libglut-dev(网上都说是这个貌似已经不可用了)
或
sudo apt-get install freeglut3-dev
================================= COMPILATION AND INSTALLATION =================================
List of packages needed for compilation on Ubuntu:
build-essential g++ cmake libx11-dev freeglut3-dev libglu1-mesa-dev libxcb1-dev libxext-dev libxxf86vm-dev libxi-dev libxmu-dev glew-utils libglew1.5-dev
To compile and install GLTools:
cd buildcmake ..makesudo make installsudo ldconfig
By default, headers will be in /usr/local/include and libraries will be in /usr/local/lib
二、编译
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include <GL/glut.h> void init(); void display(); int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(0, 0); glutInitWindowSize(300, 300); glutCreateWindow("OpenGL 3D View"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; } void init() { glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glOrtho(-5, 5, -5, 5, 5, 15); glMatrixMode(GL_MODELVIEW); gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0); } void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0, 0); glutWireTeapot(3); glFlush(); |
将 GLTools.h、GLShaderManager、GLBatch.h等文件中的
// Linux
#ifdef linux
#define GLEW_STATIC
#include <glew.h> //改为 #include <GL/glew.h>
#endif