如何判断电脑是否支持OpenGL 2.0? (我想写着色器)

发布于 2024-11-02 12:23:51 字数 2914 浏览 1 评论 0原文

我对编写 OpenGL 着色器很感兴趣,但不确定我的显卡是否足以支持此功能,或者我的系统是否配置正确以使用替代软件 (Mesa)。如何判断我的计算机是否支持 OpenGL 着色器? (我使用 Ubuntu 10.04)到目前为止,我已经尝试了三个测试,每个测试都得到了相互矛盾的答案:

1)我从OpenGL A Primer 3rd 中的示例代码下载、编译并成功运行了 OpenGL 着色器程序版本位于此处 。但是,同一章中实现其他 OpenGL 着色器的其他一些代码示例无法运行。其中一些甚至导致我的计算机崩溃或输出窗口做出有趣的事情并闪烁颜色,非常奇怪。

2)我运行了以下命令并得到:

$ glxinfo | grep "OpenGL version"
OpenGL version string: 1.5 Mesa 7.7.1

这似乎表明我正在运行 OpenGL 1.5,但是 Mesa 版本(据我所知,它是 OpenGL 2.0 的软件实现。速度不那么快,但功能与真正的硬件)似乎足以运行 OpenGL 2.0。我如何知道我的代码使用的是哪个驱动器,OpenGL 1.5 还是 Mesa 7.7.1?

3) 我编写了一些代码来输出计算机上的 OpenGL 版本,并得到以下输出:

$ ./version
OpenGL Version major=1, minor=5
GLSL Version major=0, minor=0

这并没有说明任何有关 Mesa 的信息,并且会让我相信我正在运行 OpenGL 1.5。请帮助我了解我正在运行的版本,以便我知道是否需要跑到商店购买新的显卡,然后才能确信着色器将运行。谢谢你!

PS这是代码:

#include <GL/glut.h>
#include <stdio.h>
#include <string.h>

void getGlVersion(int *major, int *minor)
{
  const char *verstr = (const char *) glGetString(GL_VERSION);
  if ((verstr == NULL) || (sscanf(verstr,"%d.%d", major, minor) != 2))
    {
      *major = *minor = 0;
      fprintf(stderr, "Invalid GL_VERSION format!!!\n");
    }
}

void getGlslVersion(int *major, int *minor)
{
  int gl_major, gl_minor;
  getGlVersion(&gl_major, &gl_minor);
  *major = *minor = 0;
  if(gl_major == 1)
    {
      /* GL v1.x can provide GLSL v1.00 only as an extension */
      const char *extstr = (const char *) glGetString(GL_EXTENSIONS);
      if ((extstr != NULL) &&
      (strstr(extstr, "GL_ARB_shading_language_100") != NULL))
    {
      *major = 1;
      *minor = 0;
    }
    }
  else if (gl_major >= 2)
    {
      /* GL v2.0 and greater must parse the version string */
      const char *verstr =
    (const char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
      if((verstr == NULL) ||
     (sscanf(verstr, "%d.%d", major, minor) != 2))
    {
      *major = *minor = 0;
      fprintf(stderr,
          "Invalid GL_SHADING_LANGUAGE_VERSION format!!!\n");
    }
    }
}

void display(void)
{
  glClear(GL_COLOR_BUFFER_BIT);

  glBegin(GL_POLYGON);
  glVertex2f(-0.5, -0.5);
  glVertex2f(-0.5, 0.5);
  glVertex2f(0.5, 0.5);
  glVertex2f(0.5, -0.5);
  glEnd();

  glFlush();

  int major, minor;
  getGlVersion(&major, &minor);
  fprintf(stderr, "OpenGL Version major=%i, minor=%i\n", major, minor);

  getGlslVersion(&major, &minor);
  fprintf(stderr, "GLSL Version major=%i, minor=%i\n", major, minor);
}

void init() {}

int main(int argc, char** argv)
{
  glutInit(&argc,argv);
  glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(500,500);
  glutInitWindowPosition(0,0);
  glutCreateWindow("simple");
  glutDisplayFunc(display);
  init();
  glutMainLoop();
}

I'm interested in writing OpenGL shaders, but am not sure if my graphics card is good enough to support this or if my system is configured correctly to use the software alternative (Mesa). How do I tell if my computer will support OpenGL shaders? (I use Ubuntu 10.04) I've tried three tests so far, and I'm getting contradictory answers for each:

1) I downloaded, compiled and successfully ran an OpenGL shader program from the sample code in OpenGL A Primer 3rd Edition located here. However, some of the other code samples from that same chapter which implement other OpenGL shaders don't run. Some of them even cause my computer to crash or the output window to do funny things with flashing colors, very strange.

2) I ran the following command and got:

$ glxinfo | grep "OpenGL version"
OpenGL version string: 1.5 Mesa 7.7.1

This would seem to indicate that I'm running OpenGL 1.5, but the Mesa version (which as I understand it is a software implementation of OpenGL 2.0. Not as fast, but same functionally as the real deal in hardware) seems to be good enough to run OpenGL 2.0. How can I tell which drive my code is using, OpenGL 1.5 or Mesa 7.7.1?

3) I wrote some code to output the version of OpenGL on the computer and got the following output:

$ ./version
OpenGL Version major=1, minor=5
GLSL Version major=0, minor=0

This doesn't say anything about Mesa, and would lead me to believe I'm running OpenGL 1.5. Please help me understand what version I'm running, so I can know if I need to run out to the store and buy a new graphics card before I can be confident shaders will run. Thank you!

P.S. Here's the code:

#include <GL/glut.h>
#include <stdio.h>
#include <string.h>

void getGlVersion(int *major, int *minor)
{
  const char *verstr = (const char *) glGetString(GL_VERSION);
  if ((verstr == NULL) || (sscanf(verstr,"%d.%d", major, minor) != 2))
    {
      *major = *minor = 0;
      fprintf(stderr, "Invalid GL_VERSION format!!!\n");
    }
}

void getGlslVersion(int *major, int *minor)
{
  int gl_major, gl_minor;
  getGlVersion(&gl_major, &gl_minor);
  *major = *minor = 0;
  if(gl_major == 1)
    {
      /* GL v1.x can provide GLSL v1.00 only as an extension */
      const char *extstr = (const char *) glGetString(GL_EXTENSIONS);
      if ((extstr != NULL) &&
      (strstr(extstr, "GL_ARB_shading_language_100") != NULL))
    {
      *major = 1;
      *minor = 0;
    }
    }
  else if (gl_major >= 2)
    {
      /* GL v2.0 and greater must parse the version string */
      const char *verstr =
    (const char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
      if((verstr == NULL) ||
     (sscanf(verstr, "%d.%d", major, minor) != 2))
    {
      *major = *minor = 0;
      fprintf(stderr,
          "Invalid GL_SHADING_LANGUAGE_VERSION format!!!\n");
    }
    }
}

void display(void)
{
  glClear(GL_COLOR_BUFFER_BIT);

  glBegin(GL_POLYGON);
  glVertex2f(-0.5, -0.5);
  glVertex2f(-0.5, 0.5);
  glVertex2f(0.5, 0.5);
  glVertex2f(0.5, -0.5);
  glEnd();

  glFlush();

  int major, minor;
  getGlVersion(&major, &minor);
  fprintf(stderr, "OpenGL Version major=%i, minor=%i\n", major, minor);

  getGlslVersion(&major, &minor);
  fprintf(stderr, "GLSL Version major=%i, minor=%i\n", major, minor);
}

void init() {}

int main(int argc, char** argv)
{
  glutInit(&argc,argv);
  glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(500,500);
  glutInitWindowPosition(0,0);
  glutCreateWindow("simple");
  glutDisplayFunc(display);
  init();
  glutMainLoop();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光礼记 2024-11-09 12:23:51

获取 GL 版本的唯一“GL 批准”方法是使用 glGetString(GL_VERSION),这会报告驱动程序支持的 GL 版本。

Mesa 可以实现任何版本的 OpenGL,即使它是在软件或硬件中实现的,在您的情况下,您拥有由 MESA 7.7.1 实现的 OpenGL 1.5,这是 OpenGL 实现。

了解某个硬件支持某个 GL 版本的唯一可靠方法是检查制造商规格,因为驱动程序可能已过时并支持较旧的 GL 版本。一个例子是 GeForce 8 卡,它们最初支持 OpenGL 2.1,当 OpenGL 3.x 出现时,它们也支持它,但仅使用更新的驱动程序。

The only "GL Approved" way of getting the GL version is using glGetString(GL_VERSION), and this reports the GL version supported by the driver.

Mesa can implement any version of OpenGL, even if it's implemented in software or hardware, in your case you have OpenGL 1.5 IMPLEMENTED by MESA 7.7.1, which is the OpenGL implementation.

The only sure way of knowing whatever a certain HW supports a certain GL version is to check the manufacturer specifications, since drivers can be outdated and support a older GL version. A example is GeForce 8 cards, they originally supported up to OpenGL 2.1, and when OpenGL 3.x appeared, they supported it also, but only using updated drivers.

计㈡愣 2024-11-09 12:23:51

glxinfo 会告诉您是否确实有硬件加速。使用 Ubuntu,您通常需要通过 Synaptic 显式安装适当的(ATI 或 NVIDIA)驱动程序才能获得硬件加速。

glxinfo will tell you if you actually have hardware acceleration or not. With Ubuntu, you usually need to explicitly install the appropriate (ATI or NVIDIA) drivers via Synaptic to get hardware acceleration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文