GLSL Hacker 0.7.0+ brings the support of user plugins (or dynamic/shared libs: *.dll under Windows, *.so under Linux and *.dylib under OS X). These dynamic libraries must implement the following functions:
int gxl_dylib_start(void* render_window, int width, int height, const char* data, void* user_data);
int gxl_dylib_stop(const char* data, void* user_data);
int gxl_dylib_frame(float elapsed_time, const char* data, void* user_data);
int gxl_dylib_resize(int width, int height, const char* data, void* user_data);
int gxl_dylib_set_message(const char* message);
char* gxl_dylib_get_message();
render_window is a pointer on the following data structure:
struct RenderWindowData_v1
{
#if _WINDOWS
HDC _dc; // Device context.
HWND _hwnd; // Handle on the 3D window.
HGLRC _glrc; // OpenGL context.
#endif
#if _OSX
void* _glrc; // OpenGL context.
#endif
#if _LINUX
Display* _display; // not set, alwyas = 0
Window _window; // not set, alwyas = 0
void* _glrc; // OpenGL context.
#endif
};
Once your DLL is coded with these functions, you can load it and use it in GLSL Hacker:
INIT script:
dlib = gh_utils.dylib_load(dylib_filename)
plugin_data = ""
gh_utils.dylib_start(dlib, winW, winH, plugin_data)
FRAME script :
plugin_data = ""
gh_utils.dylib_frame(dlib, elapsed_time, plugin_data)
SIZE script :
winW, winH = gh_window.getsize(0)
plugin_data = ""
gh_utils.dylib_resize(dlib, winW, winH, plugin_data)
TERMINATE script :
plugin_data = ""
gh_utils.dylib_stop(dlib, plugin_data)
gh_utils.dylib_unload(dlib)
You can use the plugin_data variable to pass arbitrary string to the plugin.
A complete demo (including the DLL source code in C/C++ for Windows and OS X) is available in the host_api/User_Plugin/ folder of the
code sample pack.
This demo initializes and draws a simple triangle:
