awdorrin's picture

GLControl, Forms, Tooltips, etc

I recently ported my TaoFramework based application to OpenTK and have been running into a few minor issues.

The most annoying ones so far are these:

I have a C# Forms based application, at the top of the form I have a menu strip and tool strip, at the bottom I have a status strip.

When I mouse over the tool strip, the tool tips display over the top of the GLControl, and, as a result, flicker when the GLControl gets
updated. I think its due to my calling 'Invalidate' to redraw the GLControl (previously a SimpleOpenGLControl from Tao)

I'm not sure if OpenTK does things differently, and I should be forcing the redraw in another manner, or if this is just how it works.

The second issue is that, although I have my form configured as not being able to be re-sized, it is still possible to resize the window.
I can't make it smaller than the GLControl, but I can resize the window so that the statusbar gets covered by the GLControl.

I'm guessing that something in GLControl is overriding my no-resize settings for the form, but I haven't been able to figure it out yet.

I have searched the forums and didn't see either of these topics brought up previously, so I don't know if something is wrong with how I'm implementing my code, or if I am doing something that no one else has tried before, or what it might be.

Thanks for any suggestions.

- Al


Comments

Comment viewing options

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

In my experience, flickering tooltips/menus are invariably caused by driver/OS deficiencies. I have only ever seen this issue on WinXP with specific drivers (for example, I could reproduce it on an Intel netbook and an older Ati desktop, but cannot reproduce it on my Nvidia notebook, my Ati desktop or VirtualBox.) When this issue manifests, it seems to affect all OpenGL applications, in which case I don't think anything we can do about it (other than trying to install newer drivers.)

I just tried creating a fixed-size Form with a docked GLControl and it works fine. How are you setting the Form's size? What I did was set MinimumSize and MaximumSize to the same value and set MaximizeButton to false through the WinForms designer.

If you can confirm that OpenTK is the real cause of either issue (for example, by trying a different OpenGL application and seeing that it doesn't flicker or by removing/re-adding the GLControl and seeing that the Form is sized correctly/incorrectly respectively), please file bug reports and I will try to fix the library.

On a related note, OpenTK.Compatibility.dll provides direct replacements for Tao.OpenGl and Tao.Platform.Windows.SimpleOpenGlControl. If you still have your original Tao-based implementation around, you could try to replace Tao.OpenGl.dll and Tao.Platform.Windows.dll by OpenTK.dll, OpenTK.GLControl.dll and OpenTK.Compatibility.dll and recompile without changing the source code. That's not terribly useful since you have already ported the application, but it could reveal if there are any bugs/differences in behavior between GLControl and SimpleOpenGlControl.

Finally, it is said that render-loops based on Invalidate are inefficient. The recommended approach is to loop in the Idle event, like this:

// Assuming your GLControl instance is called glControl
Application.Idle += (sender, e) =>
{
    while (glControl.IsIdle)
    {
        glControl.MakeCurrent();
        GL.Clear(...);
        ...
        glControl.SwapBuffers();
    }
};

This event handler should be installed once in the Load event for your parent Form. Check out "GLControl Game Loop" for a complete example (OpenTK.sln -> OpenTK.Examples)

awdorrin's picture

Thanks for responding!

I guess I should have double checked my Tao version of code before making my post...

I am developing and running the application on XP, my system is a Dell laptop with an Nvidia Quadro NVS 135M, so it could be a driver issue as you suggest. My target system is an older IBM PC with an Intel integrated video chipset (I think it is limited to OpenGL 1.1 or 1.2 compliant, and the drivers there have not been updated in years, by either IBM or Intel.) But I have not been able to run this version on that hardware since the migration... (long story)

I can take the code home tonight and run it on my home PC (Windows 7) with an ATI 4890, and see if the flickering persists, however I have confirmed that the same behavior regarding the ToolTip exists in the Tao version of my program - so I'll probably just live with it for now.

When it comes to the form resizing, I guess I'm going to have to retract my original statement :-P

I ran the Tao version, confirmed the form properties and reran it - the resizing worked as I wanted (ie. it did not resize)
I then brought my OpenTK version back up, compared the form properties, reran - and it also worked as I wanted (no resizing)

I'm at a loss as to why it is working now, and was not this morning. Maybe something wasn't saved properly until I exited
and restarted Visual Studio.

I did originally try to use the compatibility mode - but I must have been doing something wrong, I got a lot of errors regarding the naming of functions - so I did a lot of search/replacing until I moved the OpenGL function names to the OpenTK style. Only issue I ran into after that dealt with how some functions resolved parameters with the OpenTK polymorphism approach, but I changed my code appropriately.

I did see that the OpenTK GLControl does do things somewhat differently in its example - and I would like to move that way when I can. (I think it looks a lot cleaner and simplier.) However, due to some mitigating circumstances (managers pushing an artificial deadline) I'm going to have to, unfortunately, hold off on refining the rendering loop for now. :(

Thanks!

awdorrin's picture

The tooltip flickering must be a driver issue on my work PC. I finally had a chance to try the program on my home PC, and the tooltips displayed properly.