
[solved] OpenTK with WPF
Posted Friday, 12 November, 2010 - 15:18 by Virdues inHi all,
First of all, would like to say a big thumbs with with OpenTK. Past two months I have been working on a uni project, happily working away using OTK with windows forms and now our group has decided that they want it displayed using WPF.
Been looking around the forums and google about how to do this but nothing really is clearly explained. I know it's best to use windows forms host, which I did use (using VS2010). I simply dragged it across but GLControl is grayed out so I cannot drag it across onto the windows forms host. I've tried adding it via xaml (which I hate) with no success and I can't seems to add it conventionally as code.
So I am at a total loss on how to get an OTK GLControl on the WPF form with or without a windows forms host.
Many thanks for your time.


Comments
Re: OpenTK with WPF
Hello!
What I _just_ did.
Add a "Windows Forms" Control, MyGlControl to your wpf project.
Attach the OpenTK glcontrol to that control. Follow the steps http://www.opentk.com/doc/chapter/2/glcontrol here
In your XAML file. Name your WindowsFormsHost so you can access it from CodeBehind.
In the codebehind, set the child of the windowsformshost to be an instance of MyGlControl.
Hope this helps.
Re: OpenTK with WPF
Like I mentioned before the GLControl item in the toolbox is grayed out with either the WPF form highlighted or the WindowsFormsHost control in the WPF form highlighted.
Re: OpenTK with WPF
You need to make an ordinary windows forms control, MyOrdinaryWindowsFormsControl, put the glcontrol onto that, no wpf or xaml involved so far.
Then put MyOrdinaryWindowsFormsControl into your WindowsFormsHost in your xaml file?
If you don't get it I can put together a sample.
Re: OpenTK with WPF
Hey everyone! Right now working on an effects tool for an iphone game I am working on and I am developing this in WPF and wanted to use the OpenTK to render the viewport.
Now I followed the instructions at the link above and I am able to get the viewport to clear to the color specified, but I can't get the yellow triangle to render. Any ideas on why this is the case? Anyone else seen anything similar? It does step into my Render method and through the begin/end block. Any ideas or direction would be great! thanks all!
Re: OpenTK with WPF
Provide the code that is meant to be doing the drawing so we can have a better understand of what is going on. The only things I can think of why it wouldn't be drawing is not including the GL.End(); but you said you have included it, the other thing is do you have .Invalidate(); in there?
Re: OpenTK with WPF
Thanks Virdues! I was going to include just the rendering but I figured since thee wasn't much here I would just include it all. I pretty much followed the tutorial and then figured once I had that I would start implementing my particles. I also tried the invalidate call at the end since I did not have that but unfortunately it didnt work. Let me know if you need anything else. Thanks for lookin at this. I've been playin with this all morn and still not any luck :p
One other thing, when I remove the swapbuffer call out, the clearcolor of the background doesnt change so it does seem to be swapping also.
Re: OpenTK with WPF
Lol...disregard :) I decided to shrink up my GLControl on the Windows User Control object and the triangle appeared. I was putting the window in a docking window and it seems that the area where the triangle was drawing, was getting hidden behind one of my other dock panels. :p