我使用此处的示例将我的镶嵌回调移动到不同的类。
代码编译,但回调代码永远不会执行。
回调类:
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_;
};
回调:
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";
}
我正在注册它们的镶嵌功能:
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;
}
注册回调的方式有什么问题?