开发者

opengl -- glBeginQuery not declared

开发者 https://www.devze.com 2023-03-04 02:44 出处:网络
i want to use the commands : glBeginQuery glEndQuery glGetQueryObjectiv glGenQueries but the compiler gives me \"..was not declared\"

i want to use the commands :

glBeginQuery

glEndQuery

glGetQueryObjectiv

glGenQueries

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

I use linux an开发者_如何学God 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?


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消