rwols's picture

Inheriting from GLControl

Hi everyone, first post here.

I'm having trouble figuring out how to tackle this problem.

Basically I have a custom view class that inherits from GLControl and overrides the OnPaint, OnResize, OnMouseClick, etc, methods that handle various events. Everything that is drawn is two-dimensional. This works excellent so far.

Now let's assume that my custom class has various child controls in it, located in this.Controls. I would like to draw all of these controls with OpenGL too. I'm thinking something along the lines of this:

// ...
// the viewport is set so that the lower left corner has coordinates (0,0).
GL.Begin(BeginMode.Quads);
foreach (Control c in this.Controls)
{
    // Draw each little quad using its Location property, its Size property and its BackColor property.
    GL.Color3(c.BackColor);
    GL.Vertex2(c.Location.X, this.Height - c.Location.Y);
    GL.Vertex2(c.Location.X + c.Width, this.Height - c.Location.Y);
    GL.Vertex2(c.Location.X + c.Width, this.Height - (c.Location.Y + c.Height));
    GL.Vertex2(c.Location.X, this.Height - (c.Location.Y + c.Height));
}
// ...
GL.End();

*edit: corrected some code mistakes

However, I think GDI interferes and draws on top of my little quads. Basically I'd like to turn this off (the drawing of the many child controls is why I'm on the OpenTK endeavour). Is this really happening though? I don't quite understand the relationship between the OpenGL drawing and the GDI drawing.


Comments

Comment viewing options

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

After trying to override the OnPaint method on my custom control, GDI still draws "on top of" my custom GLControl view.

// My custom GLControl class has all of these controls in its Controls collection
public class MyControl : Control
{
    // ...
    public override void OnPaint(System.PaintEventArgs e)
    {
        // do nothing
    }
    // ...
}

So this does not work. What gives? Should I not iterate over my controls collection?