Ho utilizzato gli esempi here per spostare i miei callback di tessellation in una classe diversa.OpenGL Tessellation Callback Not Executing
Il codice viene compilato, ma il codice di richiamata non viene mai eseguito.
richiamata Classe:
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_;
};
le richiamate: la funzione
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 dove li sto registrando:
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;
}
Cosa c'è di sbagliato con il modo in cui i callback sono stati registrati ?
Non vedo come si possa eseguire il cast di un puntatore a un puntatore a funzione. Il modo in cui sto leggendo è che il tesselator proverà ad eseguire i dati in 'BeginCallback :: class_instance_', non dereference' BeginCallback' ed esegui 'operator()'. – genpfault
Vedo cosa stai dicendo. Quella parte è stata il mio tentativo di integrare questa soluzione (http://www.partow.net/programming/templatecallback/) nel codice della tessellazione. Sto arrivando all'intera cosa in modo errato? – BrickFrog
Tipo di. Il tessellator GLU è un codice piuttosto vecchio e non gestisce gli oggetti C++ nel modo in cui stai provando. Rendere le tue callback semplicemente semplici funzioni C-sytle semplificherà molte cose. La [man page ['gluTessCallback'] (http://www.opengl.org/sdk/docs/man2/xhtml/gluTessCallback.xml) ha una discussione ragionevole sui callback e su cosa vorresti includere in essi (supponendo che hai familiarità con OpenGL in stile immediato. – radical7