tags:

views:

86

answers:

3

I'm trying to make a multi instance engine in C++ with a wrapper for C#.
In made the engine in such way that there is a function like CreateEngine that takes as a parameter the handle to the window or control on which I want the engine to be initialized.
In C# I made a custom control that initializes opengl for drawing and has a render event.
If I make just one instance of the control everything works fine but then when I create another one placed in another window, the second one flickers to black(alternates the clear screen color with black although there is no reference to black in my code). Neither of them doesn't draw anything. Instead they just clear the color of the screen. The first control clears the space to blue and the second to red (theoretically). Since there is nothing to draw I don't think I have to share the wgl lists or something(I did it anyway but commenting that part of code won't solve anything).

Some more thinks to note: I'm not quite an OpenGL n00b but this really puzzles me. I also checked about everything I know I this area. The problem only appears when the are more instances of the control. In C# I overwrote the OnPaint event clearing the viewport and I invalidate it every 33 milliseconds. I also overwrote OnPaintBackground since this seems to generate flickering issues.

+1  A: 

Interfacing between the Winforms and OpenGL models of states and events can be very tricky get right. My advice is to follow the structure of some other code that does this successfully. A good choice would be the implementation of SimpleOpenGLControl in the Tao Framework.

http://taoframework.svn.sourceforge.net/viewvc/taoframework/trunk/src/Tao.Platform.Windows/SimpleOpenGlControl.cs?revision=158&view=markup

Another option would be to just make use of this class rather than implementing your own OpenGL control. Either way, the following may be useful - it highlights some of the issues when there are multiple controls:

http://slizerboy.wordpress.com/2010/04/14/multiopenglcontrol/

RD1
A: 

OpenTK also has good examples on how to use c# and OpenGL.

Jose
+1  A: 

You may want to explore double buffering - if your machine has a lot of excess horsepower then you might not notice the screen clear and redraw with a single control, but as soon as there's two controls and all the setup/teardown overhead in the render pipe

Basically, double buffering means you are always rendering to an off screen surface and then flipping that to be the onscreen surface and the current onscreen surface becomes the offscreen surface

heres a tutorial (search for OpenGL double buffering on google and you'll find lots more) http://www.swiftless.com/tutorials/opengl/smooth_rotation.html

Mark Mullin