I used the examples here to move my tessellation callbacks to a different class.
The code compiles, but the callback code never executes.
Callback Class:
template <class Class, typename ReturnType, typename Parameter>
class SingularCallBack
{
public:
typedef ReturnType (Class::*Method)(Parameter);
SingularCallBack(Class* class_instance, Method method)
: class_instance_(class_instance),
method_(method)
{}
ReturnType operator()(Parameter parameter)
{
return (class_instance_->*method_)(parameter);
}
ReturnType execute(Parameter parameter)
{
return operator()(parameter);
}
private:
Class* class_instance_;
Method method_;
};
Callbacks:
void MyClass::tessBegin(GLenum which)
{
glBegin(which);
cout << "BEGIN CALLBACK IS WORKING";
}
void MyClass::tessVertex(const GLvoid *data)
{
// cast back to double type
const GLdouble *ptr = (const GLdouble*)data;
glVertex3dv(ptr);
cout << "VERTEX CALLBACK IS WORKING";
}
Tessellation function where I'm registering them:
int MyClass::TessellatePolys()
{
GLUtesselator *tess = gluNewTess(); // create a tessellator
if(!tess) return 0; // failed to create tessellation object, return 0
// register callback functions
SingularCallBack<GLOrtho, void, GLenum>*BeginCallback;
BeginCallback = new SingularCallBack<GLOrtho, void, GLenum>(this,&GLOrtho::tessBegin);
gluTessCallback(tess, GLU_TESS_BEGIN, (void (CALLBACK *)())BeginCallback);
SingularCallBack<GLOrtho, void, const GLvoid*>*VertexCallback;
VertexCallback = new SingularCallBack<GLOrtho, void, const GLvoid*>(this,&GLOrtho::tessVertex);
gluTessCallback(tess, GLU_TESS_VERTEX, (void (CALLBACK *)())VertexCallback);
... (do tessellation) ...
return id;
}
What is wrong with the way the callbacks are being registered?
BeginCallback::class_instance_
, not dereferenceBeginCallback
and runoperator()
. – NebulosegluTessCallback
man page has a reasonable discussion of the callbacks and what you'll want to include in them (assuming you're familiar with immediate-mode-style OpenGL). – Connelley