2 行 OpenGL 程序中的 EXEC_BAD_ACCESS

发布于 2024-10-07 17:20:03 字数 307 浏览 2 评论 0原文

下面的简单程序在运行时会产生 EXEC_BAD_ACCESS (分段错误),我不明白为什么:

#include <OpenGL/gl.h>

int main(void) {
  const GLubyte * strVersion;
  // The next line gives an 'EXEC_BAD_ACCESS'
  strVersion = glGetString (GL_VERSION);
}

我在 OS X 10.6.5 的 Xcode 中运行,并且链接到 OpenGL 框架。任何想法将不胜感激。

The following simple program produces an EXEC_BAD_ACCESS (segmentation fault) when run, and I don't understand why:

#include <OpenGL/gl.h>

int main(void) {
  const GLubyte * strVersion;
  // The next line gives an 'EXEC_BAD_ACCESS'
  strVersion = glGetString (GL_VERSION);
}

I'm running in Xcode in OS X 10.6.5, and I'm linking against the OpenGL framework. Any ideas would be appreciated.

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

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

发布评论

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

评论(2

禾厶谷欠 2024-10-14 17:20:03

在调用 gl* 函数之前,您必须创建一个 OpenGL 上下文。有多种方法可以做到这一点,例如使用 GLUT 或 SDL。

You have to create an OpenGL context before you can call gl* functions. There are several ways to do that, for example using GLUT or SDL.

为你鎻心 2024-10-14 17:20:03

对于 C 规范来创建变量 GLubyte,您可以调用它,

 const GLubyte* glGetString(GL_VERSION );

然后您应该能够获取版本。以下

 const char *GLVersionString = glGetString(GL_VERSION);
 //Or better yet, use the GL3 way to get the version number
 int OpenGLVersion[2];
 glGetIntegerv(GL_MAJOR_VERSION, &OpenGLVersion[0])
 glGetIntegerv(GL_MINOR_VERSION, &OpenGLVersion[1])

是有关 glGetString 的更多基本信息:

 glGetString returns a pointer to a static string describing some aspect of the current GL connection. name can be one of the following:
 GL_VENDOR
     Returns the company responsible for this GL implementation.
     This name does not change from release to release.             
 GL_RENDERER
     Returns the name of the renderer.
     This name is typically specific to a particular configuration of a hardware platform.
     It does not change from release to release.              
 GL_VERSION
     Returns a version or release number.
 GL_SHADING_LANGUAGE_VERSION
     Returns a version or release number for the shading language.           
 GL_EXTENSIONS
     Returns a space-separated list of supported extensions to GL.

For C Specification to create the variable GLubyte you call it by

 const GLubyte* glGetString(GL_VERSION );

then you should be able to get the version. by the following

 const char *GLVersionString = glGetString(GL_VERSION);
 //Or better yet, use the GL3 way to get the version number
 int OpenGLVersion[2];
 glGetIntegerv(GL_MAJOR_VERSION, &OpenGLVersion[0])
 glGetIntegerv(GL_MINOR_VERSION, &OpenGLVersion[1])

here is more basic information on glGetString:

 glGetString returns a pointer to a static string describing some aspect of the current GL connection. name can be one of the following:
 GL_VENDOR
     Returns the company responsible for this GL implementation.
     This name does not change from release to release.             
 GL_RENDERER
     Returns the name of the renderer.
     This name is typically specific to a particular configuration of a hardware platform.
     It does not change from release to release.              
 GL_VERSION
     Returns a version or release number.
 GL_SHADING_LANGUAGE_VERSION
     Returns a version or release number for the shading language.           
 GL_EXTENSIONS
     Returns a space-separated list of supported extensions to GL.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文