pabloiw's picture

WFP with several GraphicsContext

Hey, I want to write a WPF application which has several (two or three etc..) instances of GLControl.
I was searching for some good example for very long time, but I can't find anything. I'm now using the example from http://steveharoz.com/blog/?p=116, I created a UserControl with the glControl in WindowsFormsHost, and when I make two or more instances of this, they are overlaping each other. Please help me to resolve it.
I can send someone my project to debug.

Inline Images
They should be in different controls.

Comments

Comment viewing options

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

Your going to have to be more descriptive about what you mean by overlapping.

The issue most people have is not calling glControl1.MakeCurrent(); on the control before calling any openGL functions in any function called from the eventloop Render being the obvious one, but you might have to do it in your Resize code if you reset the viewport there.

pabloiw's picture

I don't have glControl.MakeCurrent() in Resize but in the UserControl Loaded event
Above I've added the screenshot. When I add gl.MakeCurrent into Render function, everythink work fine, but I'am afraid about performence, i use DispatcherTimer to render like in example, bacause of WPF, and I want to know, it is possible to use the MakeCurrent just one time per user control / not one per window, and of course when i resize window.

ERP's picture

MakeCurrent ought to be extremely cheap, it's literall just setting a global variable.

OpenGL is a state machine, if you don't tell it which context to render to when you start it will use the last one the application was using.
You've got multiple contexts so you have to set the one you want to render to before rendering, there is nothing magical in windows or OpenGL that is going to do that for you.

pabloiw's picture

Thank you very much, now it's all working fine when i've putted glControl.MakeCurrent() before rendering.