I have a strange "flickering" problem with Tao' SimpleOpenGlControl
control. I have 3 tab pages of a System.Windows.Forms.TabControl
. The first and the second pages are filled with a SimpleOpenGlControl
while on the third page there is a MonthCalendar
(or a Button
or something else). Consider this code:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
simpleOpenGlControl1.InitializeContexts();
Gl.glClearColor(0, 0, 0, 1);
simpleOpenGlControl2.InitializeContexts();
Gl.glClearColor(0, 0, 0, 1);
}
private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e) {
// This delay makes the problem evident.
Thread.Sleep(2000);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
}
private void simpleOpenGlControl2_Paint(object sender, PaintEventArgs e) {
Thread.Sleep(2000);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
}
}
If I switch from the first page to the second, the third, the second and to the first again I see the calendar as a sort of background before the first control is painted.
I saw from the source code that the OnPaintBackground
method is overridden and that the base class UserControl.OnPaintBackground
method is not called. Could it be the problem?
Edit:
I tried to override the OnPaintBackground
method in a subclass but it is not called. Actually the control' styles are initialized in this way:
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, false);
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.UserPaint, true);
I suspect that the tab control buffering is conflicting with that of the SimpleOpenGlControl
in some way.
The AutoMakeCurrent
and AutoSwapBuffers
properties are set to true. I tried to call SwapBuffers()
before the TabPage
change and the result is better but not perfect: going back and forward through the tabs cause the MonthCalendar
to flash sometime.
Edit2:
I've the same problem using the OpenTK.GLControl
. No problem using dotNet controls as PictureBox
.
Edit3:
I tried also overriding WndProc
has described in Why do my WinForm controls flicker before the paint event? but the result is the same.
Also this answer on the OpenTk forums doesn't help.
It seems impossible that there is no solution to this problem!