I’m currently developing a game in the LeadWerks 2 engine and I’ve decided to use Qt4 as the GUI and window manager. What I want to do is create a Qt QGLWidget window and have the LeadWerks engine run inside of that.
There is some information of building a basic QGLWidget application here.
I’m really struggling to understand how to do this exactly. I can create a custom GL buffer within the LeadWerks engine and I believe what I need to do is give that buffer the GL context Qt created.
As for the LeadWerks side of things, the main thing I need to do is call a method called CreateCustomBuffer and pass it a few things:
virtual void Buffer::CreateCustom( byte* getsize, byte* makecurrent)
Creates and returns a new custom buffer. GetSize (defined as void _stdcall GetSize(int* width, int* height)) and MakeCurrent (defined as void _stdcall MakeCurrent(void)) are callback functions for the buffer. GetSize should return (by changing the value provided with a pointer) the size of the custum OpenGL buffer/context used. MakeCurrent should set the custom buffer as the current OpenGL context.
If I understand it correct, this callback will be called whenever LeadWerks wants the context to become active (it doesn’t manage it itself then), similar the getsize callback is to obtain the size of the available window. So normally you’d use this to activate the context from another interface you’ve access for.
Unfortunately those callbacks don’t allow for passing a pointer, which means, you can’t pass the QGLWidget class instance pointer, so that you could delegate the call to a class member function. Not being able to pass user data to callbacks is a sign of bad API design, because it makes things hard, which would be easy otherwise.
There is a library called ffcall which provides a mechanism to get around this http://www.gnu.org/s/libffcall/callback.html
So you’d write a delegator function
create callback wrappers (as in your QGLWidget derives class’ constructor) as class member variables:
And those you can pass to LeadEngine: