I've just started learning openGL a couple of hours ago for my work and have been tasked with rendering a concave polygon using tessellation. I'm trying to compile the following code:
#ifndef CALLBACK
#define CALLBACK
#endif
#include "GL/gl.h"
#include "GL/glu.h"
void CALLBACK beginCallback(GLenum which);
void drawHook()
{
GLUtesselator* tes开发者_C百科sObj = gluNewTess();
gluTessCallback(tessObj, GLU_TESS_BEGIN, beginCallback);
}
void CALLBACK beginCallback(GLenum which)
{
glBegin(which);
}
which I've gotten from the OpenGL Programming Guide, Seventh Edition, with the relevant chapter also being available online. But the following error is being returned:
hook.cc:28: error: invalid conversion from ‘void (*)(GLenum)’ to ‘void (*)()’
hook.cc:28: error: initializing argument 3 of ‘void gluTessCallback(GLUtesselator*, GLenum, void (*)())’
This error leads me to believe that the third argument of gluTessCallback
should be a function that takes no arguments, yet the 'official' openGL reference states otherwise.
Am I missing something here or is the book incorrect?
The book is correct. You just have to cast the function pointer to void(*)()
. It's needed because the type is not (and cannot be) precise.
gluTessCallback(tessObj, GLU_TESS_BEGIN, (void(*)())&beginCallback);
The documentation you linked states that the third argument of gluTessCallback
is a parameterless function. (right after the heading Tessellation Callback Routines)
However, Example 11-1 casts the actual function pointer to a parameterless one:
gluTessCallback(tobj, GLU_TESS_ERROR, (GLvoid (*) ()) &errorCallback);
^^^^^^^^^^^^^^^
精彩评论