开发者

Any OCaml bindings for GtkGlExt? If not, how can I write them?

I currently have two separate programs: (1) a GTK GUI; (2) a Glut application with openGL 3D graphics. However, I'd like to have the openGL part as some widget embedded in the GUI I have.

I have noticed GtkGlExt is exactly what I need, but unfortunately there are no OCaml bindings mentioned on its web pages.

My questions are:

(1) Do you know if there are any such bindings lost somewhere in cyberspace? (I have found a similar discussion from 2008 so I would hope after 3 years something would have happened.)

(2) If there aren't any bindings, how difficult would it be to produce these bindings and where would it be a good place to start? How much of the original C libraries would I have to undestand? (I haven't done any C calls from OCaml so far.)

(3) Alternatively, do you know of any other out-of-the-box package I could use? (I have attempted t开发者_StackOverflow社区o install gtkglarea on OSX but I had errors which I couldn't solve and gave up. I've also tried to install lablgtk2-2.14.0+dfsg but got the errors described here.)


The standard solution is to use the LablGTK's OpenGL support. I know of no bindings to other solutions such as gtkglext. If you want to write your own bindings, in general it isn't overly difficult, does take some work and thought. You'll at least need to understand enough of the underlying C library to safely bridge with OCaml, which varies greatly with the library's interface. Since GtkGLExt is Glib-based, so you'll have the blessing and curse of being able to build on existing experience in the community with binding GLib/GTK libraries, and needing to understand enough of how Lablgtk2 works to make your bindings integrate with it. This is possible, but not exactly trivial and I don't recall seeing any good documentation on binding new GTK libraries to help you get started.

Your error in the other question looks like you're trying to hand-compile - have you tried building the GODI package for lablgtk with OpenGL enabled? It may have patches and/or build options to make it work. Alternatively, does MacPorts, which it looks like you're using from the /opt/local path, have OCaml and lablgtk packages?

Another option: There's another option I commonly use when I need access to facilities from an unbound library. Rather than writing bindings for the library, I'll write the logic needing that library in C and expose a minimal interface back to my OCaml code. In the GtkGLExt case, it's probably just a matter of creating initialization, teardown, and start/stop context calls that do the underlying work with the C API and return the OpenGL context or whatever is necessary. You'll still need to do some work to figure out how to get the right GTK object from the OCaml object, and how to pass back whatever is needed for LablGL to work, but it's typically easier than creating real bindings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜