首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ubuntu12.04上的OpenGL 4教程

Ubuntu12.04上的OpenGL 4教程
EN

Stack Overflow用户
提问于 2014-09-03 13:27:41
回答 3查看 4.4K关注 0票数 2

我使用的是Ubuntu12.04,并且我已经安装了OpenGL4。

我还有一块支持CUDA的NVIDIA显卡。请注意,我一直在我的PC上使用CUDA进行并行计算,并且工作正常。

代码语言:javascript
复制
[eeuser@roadrunner sample_opengl]$ glxinfo | grep gl
server glx vendor string: NVIDIA Corporation
server glx version string: 1.4
server glx extensions:
client glx vendor string: NVIDIA Corporation
client glx version string: 1.4
client glx extensions:
    GL_ARB_texture_query_lod, GL_ARB_texture_rectangle, GL_ARB_texture_rg, 
    GL_NV_texture_multisample, GL_NV_texture_rectangle, GL_NV_texture_shader, 

我不能让一个简单的程序工作。有没有人能给出一个可以在我的电脑上运行的示例程序

下面是我使用的代码:

代码语言:javascript
复制
#include <GL/glew.h> // include GLEW and new version of GL on Windows
#include <GLFW/glfw3.h> // GLFW helper library
#include <stdio.h>

int main () {
  // start GL context and O/S window using the GLFW helper library
  if (!glfwInit ()) {
    fprintf (stderr, "ERROR: could not start GLFW3\n");
    return 1;
  } 

    // uncomment these lines if on Apple OS X
  /*glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 2);
  glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);*/

  GLFWwindow* window = glfwCreateWindow (640, 480, "Hello Triangle", NULL, NULL);
  if (!window) {
    fprintf (stderr, "ERROR: could not open window with GLFW3\n");
    glfwTerminate();
    return 1;
  }
  glfwMakeContextCurrent (window);

  // start GLEW extension handler
  glewExperimental = GL_TRUE;
  glewInit ();

  // get version info
  const GLubyte* renderer = glGetString (GL_RENDERER); // get renderer string
  const GLubyte* version = glGetString (GL_VERSION); // version as a string
  printf ("Renderer: %s\n", renderer);
  printf ("OpenGL version supported %s\n", version);

  // tell GL to only draw onto a pixel if the shape is closer to the viewer
  glEnable (GL_DEPTH_TEST); // enable depth-testing
  glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer"

  /* OTHER STUFF GOES HERE NEXT */

  // close GL context and any other GLFW resources
  glfwTerminate();
  return 0;
}

我试着用-

代码语言:javascript
复制
 g++ main2.cpp  -lglut -lGL -lGLEW -lGLU 

我得到一个错误:

代码语言:javascript
复制
main2.cpp:2:47: fatal error: GLFW/glfw3.h: No such file or directory
compilation terminated.

我现在想知道这是什么GLFW?更确切地说,我该如何安装它?在@eapert之后,我将libglfw安装为-

代码语言:javascript
复制
sudo apt-get install libglfw-dev

仍然会出现以下错误

代码语言:javascript
复制
main2.cpp: In function ‘int main()’:
main2.cpp:18:2: error: ‘GLFWwindow’ was not declared in this scope
main2.cpp:18:14: error: ‘window’ was not declared in this scope
main2.cpp:18:79: error: ‘glfwCreateWindow’ was not declared in this scope
main2.cpp:24:32: error: ‘glfwMakeContextCurrent’ was not declared in this scope
EN

回答 3

Stack Overflow用户

发布于 2014-09-03 13:41:35

安装GLFW:sudo apt-get install libglfw3-dev的"dev“包

警告:您从包管理器获得的版本可能已过期。

您可以按照herehere的说明操作。

票数 3
EN

Stack Overflow用户

发布于 2014-09-03 18:17:07

我试着用

编译-

g++ main2.cpp -lglut -lGL -lGLEW -lGLU

当你想使用GLFW时,为什么要链接GLUT呢?而且你的程序也不需要GLU。试试这个:

代码语言:javascript
复制
g++ main2.cpp -lGL -lGLEW -lglfw
票数 2
EN

Stack Overflow用户

发布于 2014-09-03 13:39:45

WARNING:这个问题在回答后发生了很大的变化

“我尝试了一些教程,但我不能让一个简单的程序工作”我假设,考虑到您前面所说的,您的CUDA程序可以在Windows上运行,只是不能在Ubuntu上运行?

1)首先尝试安装更新的Ubuntu版本(如果您在该PC上有选项)。12.04有点旧,如果你没有很好的理由使用它,你可能不应该使用它(例如,这是一台公司的PC,你会违反升级政策,类似的东西)

2)尝试为您的卡安装专有的NVIDIA驱动程序(这也应该为您提供NVIDIA OpenGL实现);您可能已经安装了mesa。我认为当前的mesa版本至少有一些GPGPU支持,但我不确定它们是否支持CUDA (如果你不是特别喜欢CUDA,你也可以尝试OpenCL,你可能有更好的机会使用它。尽管仍然有很好的机会需要专有的NVIDIA驱动程序)。

GLFW是一个助手库,用于创建窗口,在其中设置OpenGL,并提供对输入函数等的访问。在这方面,它类似于GLUT -你似乎很熟悉-但它是一个更现代的替代方案。当然,您需要安装它才能使用它。你应该可以像往常一样通过Ubuntus包管理器安装它,试试apt-cache search glfw,它会帮助你找到确切的包名称。如果有多个"lib“版本,请安装以-dev结尾的版本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25636831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档