手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Ubuntu 13.04使用Mesa

[日期:2013-07-19] 来源:Linux社区  作者:sheismylife [字体: ]

以前写过一些关于如何使用Mesa的文章,如今再试。Ubuntu 13.04下有些东西已经变了。

首先安装:

sudo apt-get install libgl1-mesa-dev
sudo apt-get install libglu1-mesa-dev
sudo apt-get install freeglut3-dev

现在不用NetBeans了,用CMake创建工程。

根目录下的CMakeLists.txt内容:

cmake_minimum_required(VERSION 2.8)
project (vender)
add_subdirectory(src bin)

src目录下的CMakeLists.txt文件内容如下:

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年前代码一样。

#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();
}

运行结果:

Ubuntu 13.04使用Mesa

我这次不想绘制什么图形,只是想知道我的显卡类型。因此代码删减如下:

#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;
}

运行结果:

www.linuxidc.com @linux:~/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

推荐阅读:

开源 3D 驱动集合 Mesa 发布 9.0 正式版本 http://www.linuxidc.com/Linux/2012-10/72003.htm

Mesa 越界内存破坏漏洞(CVE-2013-1872)  http://www.linuxidc.com/Linux/2013-06/85505.htm

更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款