Anonymous's picture

Other toolkits except Windows.Forms

Suppose I want to render OpenGL scene to some windowed application not based on Windows.Forms (for example - Gtk#). Is it possible for me to do so? As far as I understand, the GLContext class is specifically written to wrap a SWF Control (p.s. - if so, why not to subclass Control?), but there is no simplified generic way to wrap a window handle.
I would like to be able to define a window handle as my render context since the low-level windowing systems (X11/Win32) both use integers as window handles, and most toolkits allow me to retrieve the low-level window handle of just about any element (Control in Winforms, Widget in Gtk#, etc...)
This will allow users the freedom to select the toolkit they want to use. It will be better if GLContext won't wrap a control, but a integer defining a window handle, and have a set of complementary assemblies, each defining an element in a different toolkit, that is an "opengl drawing canvas" for that toolkit.

Itai.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler.'s picture

I've wanted to do what you suggest right from the start (that's why GLContext does not inherit Windows.Forms.UserControl). The current design is little more than just a hack to get something working - there is a separate svn branch just for this feature, and it's slowly making progress (almost everything works on windows, x needs some work).

The problem is that GLContext interfaces differently with different platforms. For example, on X11 we need both a window handle and a connection to the x-server in order to create the visual (pixel format). This poses some interesting questions, like "will the windowing toolkit provide the x-connection (like Mono.Winforms do?)", and "if yes, what should the interface be like, in order to maintain cross-platform compatibility?", or "if not, should we start a new connection - or can we reuse an existing one?"

Do you have any experience with opengl contexts on X11? A more definite answer on these questions would really help things move forward!

Anonymous's picture

While I did have experience with OpenGL on X11, I don't remember much at this time (long time since I last actually wrote something). The OpenGL Green Book (OpenGL for the X Windows System) have good explanations of how to initialize OpenGL context on an X11 window, and code samples can be easily found over the internet (look for the glgears.c code for a good example. Related methods include glXMakeCurrent and glXSwapBuffers).
The GLContext object you defined seems like a good overall design, except for the Control property. I would abandon that property, and introduce a new interface - IGLDrawable, implemented specifically in a set of new assemblies, one for each toolkit, that will implement relevant widgets - one for winforms Control, another for gtk# widget, etc...
It must be an interface since specific implementations will inherit relevant toolkit base objects, such as Control and Widget, so you can't limit that by defining an abstract class. That interface should perhaps replace GLContext in its current usage scheme, and perhaps return a GLContext instance (the assumption is that a control or a widget have all the needed information internally - the handle, the display, the color-depth, etc., so it won't be a problem initiating an instance of GLContext. The tricky part is knowing which version of GLContext to create... perhaps GLContext should introduce a static method that makes the choice automatically).

Hope it helps a bit.
Itai.

the Fiddler.'s picture

The new implementation follows your suggestion almost exactly - there is an IGLContext interface with specific implementations for different toolkits, and the user will be able to define his own implementations. The current dependence on Control is a temporary hack - I just needed to get this to work fast, so I could test the rest of the library.

I hadn't heard of the the Green Book before, thanks for the pointer!

This all reminds me to allocate more time to work on OpenTK. Hopefully things will start moving faster soon!

JTalton's picture

I have a GTKGLWidgetSharp that I wrote which works on both Windows and Linux. I would love to see the code put to some good use. The Linux part is not 100% cooked, but my demo app runs fine on both Windows and Linux. Multiple controls are supported in the same app etc... Let me know if there is interest in it.

the Fiddler.'s picture

Sounds very nice! Please post a link(or send an email to stapostol -at- gmail.com, I'd love to integrate this in OpenTK if that's ok with you :)

GOoOGle's picture

Hello JTalton,

I'm currently really interested by our GTKGLWidgetSharp, and i would like to see it if you still propose it for the community.

This is exactly i would like to find, so if you could send it, i would really appreciate. (gooogle -at- free -dot- fr).

Thanks !