opengl -- glBeginQuery 未声明

发布于 2024-11-05 17:43:35 字数 433 浏览 0 评论 0原文

我想使用命令:

glBeginQuery

glEndQuery

glGetQueryObjectiv

glGenQueries

,但编译器给我“..未声明”

我使用linux并且我有这些头文件(到目前为止工作正常)

          #include <GL/gl.h>
          #include <GL/glu.h>
          #include <GL/glut.h>
          #include <GL/glx.h>

          #include <X11/X.h>    
          #include <X11/keysym.h>

有解决方案吗?

i want to use the commands :

glBeginQuery

glEndQuery

glGetQueryObjectiv

glGenQueries

but the compiler gives me "..was not declared"

I use linux and i have these header files (which work fine until now)

          #include <GL/gl.h>
          #include <GL/glu.h>
          #include <GL/glut.h>
          #include <GL/glx.h>

          #include <X11/X.h>    
          #include <X11/keysym.h>

Is there a solution for this?

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

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

发布评论

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

评论(1

不寐倦长更 2024-11-12 17:43:35

查询函数在glext.h中声明。请注意,包含此文件不会神奇地初始化函数指针,也不会检查功能可用性(尽管 1.5 功能几乎无处不在,但编写良好的程序不能简单地假设它可以工作)。您至少必须正确初始化指针,否则您的程序将崩溃并烧毁。

如果您不知道我现在在说什么,或者您有任何不确定性,请下载 GLEW。这将为您省去很多痛苦。

编辑:对其工作原理的更详细解释是:超越核心 1.2(或我相信在 Linux 中为 1.3)的功能仅通过函数指针机制实现。为此,像 glBeginQuery 这样的函数将具有一个名为 PFNGLBEGINQUERYPROC 的函数指针 typedef,您可以使用它来初始化名为 glBeginQuery 的静态全局变量。当然,您也可以自由地执行其他操作(您可以将所有函数指针放入一个结构中,或者给它们起一些愚蠢的名称),但这是最常见的做法。

您还必须检查是否支持正确的版本和/或扩展,否则您不知道您想要的功能是否已实现。

GLEW 为您完成所有这些工作,因此只要您这样做,它就可以工作

#include <GL/glew.h>
  ...
if (glewInit() != GLEW_OK)
    fail_with_error();

旁注:您可以通过定义 glext.h 生成原型GL_GLEXT_PROTOTYPES,但这并不是很有用,因为它会导致链接器抱怨缺少符号(事实上,我一直想知道为什么它存在)。

The query functions are declared in glext.h. Note that including this file will not magically initialize function pointers nor check for feature availability (although 1.5 functionality is pretty much omnipresent, a well-written program cannot simply assume that it works). You must at the very least initialize pointers properly or your program will crash and burn.

If you have no idea what I'm talking about now or if you are unsure in any way, download GLEW. That will save you a lot of pain.

EDIT: A more elaborate explanation of how it works is this: The functionality that goes beyond core 1.2 (or 1.3 in the case of Linux, I believe) is only implemented via a function pointer mechanism. For that, a function like glBeginQuery would have a function pointer typedef named PFNGLBEGINQUERYPROC which you use to initialize a static global variable called glBeginQuery. You are of course free to do anything else too (you can put all your function pointers into a struct, or give them silly names), but this is what is most commonly done.

You also have to check that the proper version and/or extensions are supported, otherwise you don't know whether the functionality that you want is implemented at all.

GLEW does all that for you so it just works if you do:

#include <GL/glew.h>
  ...
if (glewInit() != GLEW_OK)
    fail_with_error();

Sidenote: You can have glext.h generate prototypes by defining GL_GLEXT_PROTOTYPES, but this is not very useful, because it will cause the linker to complain about a missing symbol (in fact, I've always been wondering why this exists at all).

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