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.
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