Author Topic: User plugins in C/C++  (Read 428 times)

0 Members and 1 Guest are viewing this topic.

JeGX

  • Global Moderator
  • Hero Member

  • Offline
  • *****

  • 564
    • View Profile
    • Geeks3D.com
User plugins in C/C++
« on: June 23, 2014, 03:04:35 PM »
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:

Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
dlib = gh_utils.dylib_load(dylib_filename)
plugin_data = ""
gh_utils.dylib_start(dlib, winW, winH, plugin_data)



FRAME script :
Code: [Select]
plugin_data = ""
gh_utils.dylib_frame(dlib, elapsed_time, plugin_data)


SIZE script :
Code: [Select]
winW, winH = gh_window.getsize(0)
plugin_data = ""
gh_utils.dylib_resize(dlib, winW, winH, plugin_data)


TERMINATE script :
Code: [Select]
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: