
OpenTK and WPF interoperation
Posted Wednesday, 9 September, 2009 - 15:28 by the Fiddler| Project: | The Open Toolkit library |
| Version: | 0.9.9-2b |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | in progress (review) |
Right now, it is possible to create an OpenTK.GLControl and host it in a WPF using a WindowsFormsHost.
The question is: can we create an OpenGL context directly on a WPF window and do away with the host control?
The attached solution creates a WPF solution, obtains its handle and creates a GraphicsContext. This works without errors, however OpenGL rendering results in artifacts. The msdn entry for the OnRender method, notes that:
The rendering instructions for this element are not used directly when this method is invoked, and are instead preserved for later asynchronous use by layout and drawing.
This explains why the rendering artifacts appear: OpenGL tries to render to the window directly and does not participate into WPF composition.
One *could* use offscreen OpenGL rendering, perform a readback and present the results into the WPF window, but this is inefficient. It would be nice to find a better solution or confirm that it cannot be done.
Any ideas?
| Attachment | Size |
|---|---|
| OpenTKWPF.zip | 1.81 MB |


Comments
#31
WPF support :
But for glReadPixel, which format should I use ?
I can't find a match between theses 2 technologies !!!!
#32
Argb in WPF or GDI+ equals Bgra in OpenGL.
Try Format32bppRgb in WPF and Bgra in ReadPixels.
#33
Thanks,
It is strange that GL_BGRA correspond to PixelFormat.Format32bppRgb, where have you see this information ?
It sounds to be the inverse :-P ... even there is a Format32bppArgb more too !
Anyway, it change nothing ... maybe the problem is in the configuration of the RenderBuffer or the FrameBuffer :
Here is my code that play with colors modes :
#34
Thanks,
It is strange that GL_BGRA correspond to PixelFormat.Format32bppRgb, where have you see this information ?
It sounds to be the inverse :-P ... even there is a Format32bppArgb more too !
Anyway, it change nothing ... maybe the problem is in the configuration of the RenderBuffer or the FrameBuffer :
Here is my code that play with colors modes :
#35
Wow,
Finally I have solve every problems and the control sounds to working correctly now.
Thanks for all your help.
Regards
#36
i am glad that you solve the problems. i met a function in the specs that i did not know of: "BlitFrameBuffer", which blits contents of readbuffer to drawbuffer. i did not try this but the spec suggests that if source height is negative than the image would be reversed. i missed the point where you solved the inverse image problem. so in case i wrote this message.
#37
Is that working control available for use?
#38
Not really,
I have worked at lot to try to get a good control... I have got several versions of the control, based on differents approach but none work with acceptable performance.
The best is to use a WindowsFormsHost... if performance is important for you