来源:自学PHP网 时间:2015-04-14 11:12 作者: 阅读:次
[导读] Ubuntu13.04使用Mesa首先安装:[cpp]sudo apt-get install libgl1-mesa-dev sudo apt-get install libglu1-mesa-dev sudo apt-get install freeglut3-dev 现在不用NetBeans了,用CMake创建工程。根目......
Ubuntu13.04使用Mesa
首先安装:
[cpp]
sudo apt-get install libgl1-mesa-dev
sudo apt-get install libglu1-mesa-dev
sudo apt-get install freeglut3-dev
现在不用NetBeans了,用CMake创建工程。
根目录下的CMakeLists.txt内容:
[cpp]
cmake_minimum_required(VERSION 2.8)
project (vender)
add_subdirectory(src bin)
src目录下的CMakeLists.txt文件内容如下:
[cpp]
cmake_minimum_required(VERSION 2.8)
set(CMAKE_BUILD_TYPE Debug)
set(PROJECT_INCLUDE_DIR ../include)
include_directories(${PROJECT_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src CPP_LIST1)
add_executable(vender ${CPP_LIST1})
target_link_libraries(vender GL GLU glut)
add_definitions(-Wall)
然后看一下src/main.cc文件内容,和3年前代码一样。
[cpp]
#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();
}
运行结果:
我这次不想绘制什么图形,只是想知道我的显卡类型。因此代码删减如下:
[cpp]
#include <GL/glut.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(0, 0);
glutInitWindowSize(300, 300);
glutCreateWindow("OpenGL 3D View");
GLubyte const* vender = glGetString(GL_VENDOR);
cout << "GL_VENDOR: " << vender << endl;
GLubyte const* renderer = glGetString(GL_RENDERER);
cout << "GL_RENDERER: " << renderer << endl;
GLubyte const* version = glGetString(GL_VERSION);
cout << "GL_VERSION: " << version << endl;
return 0;
}
运行结果:
[cpp]
dean@dean-GA-MA790XT-UD4P:~/work/opengl/vendor/build/bin$ ./vender
GL_VENDOR: X.Org
GL_RENDERER: Gallium 0.4 on AMD JUNIPER
GL_VERSION: 3.0 Mesa 9.1.4
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com