opengl -- glBeginQuery 未声明
我想使用命令:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查询函数在
glext.h
中声明。请注意,包含此文件不会神奇地初始化函数指针,也不会检查功能可用性(尽管 1.5 功能几乎无处不在,但编写良好的程序不能简单地假设它可以工作)。您至少必须正确初始化指针,否则您的程序将崩溃并烧毁。如果您不知道我现在在说什么,或者您有任何不确定性,请下载 GLEW。这将为您省去很多痛苦。
编辑:对其工作原理的更详细解释是:超越核心 1.2(或我相信在 Linux 中为 1.3)的功能仅通过函数指针机制实现。为此,像
glBeginQuery
这样的函数将具有一个名为PFNGLBEGINQUERYPROC
的函数指针 typedef,您可以使用它来初始化名为glBeginQuery
的静态全局变量。当然,您也可以自由地执行其他操作(您可以将所有函数指针放入一个结构中,或者给它们起一些愚蠢的名称),但这是最常见的做法。您还必须检查是否支持正确的版本和/或扩展,否则您不知道您想要的功能是否已实现。
GLEW 为您完成所有这些工作,因此只要您这样做,它就可以工作:
旁注:您可以通过定义
让
,但这并不是很有用,因为它会导致链接器抱怨缺少符号(事实上,我一直想知道为什么它存在)。glext.h
生成原型GL_GLEXT_PROTOTYPESThe 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 namedPFNGLBEGINQUERYPROC
which you use to initialize a static global variable calledglBeginQuery
. 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:
Sidenote: You can have
glext.h
generate prototypes by definingGL_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).