DamienDe's picture

Bad flickering/artifacts while scrolling in form on Windows 7


I have a flicker problem with OpenTK in my C# Winforms application under Windows 7.
When I put a GLControl somewhere on a Form and enable autoscroll on the Form and arrange everything so I got some scrollbars and then finally scroll the form, the GLControl will be filled with garbage until I refresh it manually or by resizing the form.
The same problem occurs on a panel.
In Windows XP everything is fine, so I suspect that this is a problem with the Aero mode from Windows 7. I disabled Aero by switching to the basic mode and the flicker is gone.

So what are my options? Is there any way at all to get a garbage free GLControl under Windows 7 while scrolling.
I could not find anything about this problem, but I can´t be the only person using OpenTk in Windows 7.

The graphics card is an ATI 4600 with the newest 10.7 drivers.

Well everything else is fine, as I made the control draggable, resizable etc. it always looks perfect, just not when using a scrollbar.

Thanks for listening :)


Comment viewing options

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

If the GLControl is partially or totally obscured, then this behavior is normal and expected (the contents of the OpenGL framebuffer are not guaranteed on obscured pixels). Does this also happen while the GLControl is 100% visible?

DamienDe's picture

Yes it happes for GLControls which are in the middle of the form.
I created a test project with a panel on a form. The panel is anchored top/left and much bigger than the form, to enable the scrollbars from the form. On the panel a GLControl is placed so it appears in the middle of the form at application start.
When I now use the scrollbars, the content of the GLControl disappears.

I am not really sure, that it is the same behaviour as in my real application, but anyway in both cases the GLControl displays garbage or nothing at all, while scrolling with the scrollbars.

I attachted a zip file with the test project.

Edit: When I disable Aero the test project works fine.

ogl.zip11.32 KB
the Fiddler's picture

I can confirm this on my Nvidia card (Win7 64bit). Happens with Aero, works fine without.

A partial workaround is to handle the Form1.Scroll event and call glControl1.Invalidate() from there. The contents show correctly in this case, but some flicker remains.

I don't know why this happens, I'll let you know if I manage to find anything.

Edit: this seems to be a widespread issue (it's not just OpenTK).

DamienDe's picture

Thanks for investigating so far.
I already tried updating my OpenGL stuff in the scroll event, well its better, but still very bad.
I hope there is a way around this, if not I have to find another solution, like DirectX and WPF. But I would really hate that, as I already build quite some GUI content for the application with Winforms and I dislike WPF and its forced XML code.

the Fiddler's picture

I checked the GLControl implementation and everything is set up as recommended. I tested all available ControlStyles but nothing seemed to help. The only thing I have not tried is setting the PFD_SWAP_COPY and PFD_SUPPORT_COMPOSITION flags explicitly - unlikely to help but you never know.

What's worse, this seems to be a pretty common complaint on the internet but noone seems to know how to make it work. This wouldn't be the first time I've encountered issues with OpenGL on Aero so I'm pretty sure this can be fixed somehow - but I don't know how exactly, yet.

DamienDe's picture

Is this a problem with all programs using Toolkits which are not "accelerated" like WPF and use 3D controls on their forms ?
This would essentially somehow break every 3D application, which does not run fullscreen. This is just crazy, what was Microsoft thinking?!

DamienDe's picture

Okay, I played around with SlimDX now and have a Direct3d9 control which does not has the garbage/flicker problem.
So I assume it must be a OpenGL vs Aero problem and not a global Hardware Rendering vs 2D GDI thing.

But I hate to have to switch to direct3d as I never coded anything with it and I finally loose compatibility across other operating systems.

DamienDe's picture

I loaded the test project into monodevelop and tried it with mono 2.6.7 and the flicker was gone. Mono uses normal GDI+ rendering on Windows doesn´t it ?
So why doesn´t the glcontrol flicker there too ?
Well at least this gives me hope, that there is a way around the flickering with the normal .net framework.

the Fiddler's picture

This is an interesting twist. I do not know why Mono behaves differently than .Net here but this might help come up with a solution. Nothing concrete yet but I have some ideas on what is going on and what to test for.

Have you tried scrolling without using a panel? Does the GLControl still behave this way?

Phyyl's picture

I know this is an old issue, but I'm getting exactly this. I have a Panel containing my GLControl. When I scroll the Panel (using the scrollbars) there's a weird flickering. It doesn't seem to be related to OpenGL, since I'm not clearing the buffer at all. The flciker is also only visible for 99% of the height, the top and bottom have a couple non-flickering regions. I use double buffering, but that doesn't seem to change anything. I tried all the combinations of double buffering in opengl, in the glcontrol and the container control. There's either nothing showing up, or flickering.