james_lohr's picture

Multiple GLControls in one window - trouble rendering them all at once

Hi,

I'm trying to render multiple viewports at once (e.g. 3d editor where you have multiple views), however only the last GLControl is rendering correctly. I suspect I'm missing something obvious here. Any help would be greatly appreciated.

Many thanks


Comments

Comment viewing options

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

Call .MakeCurrent() on the control immediately before performing any operation on it.

For example:

protected override void OnLoad(EventArgs e)
        {
            glControl1.MakeCurrent();
            GL.Viewport(0, 0, glControl1.Width, glControl1.Height);
            GL.MatrixMode(MatrixMode.Projection);
            Glu.Perspective(45.0, glControl1.Width / glControl1.Height, 0.0, 1.0);
            GL.ClearColor(Color.Green);
 
            glControl2.MakeCurrent();
            GL.Viewport(0, 0, glControl2.Width, glControl2.Height); // Use all of the glControl painting area
            GL.MatrixMode(MatrixMode.Projection);
            Glu.Perspective(45.0, glControl1.Width / glControl1.Height, 0.0, 1.0);
            GL.ClearColor(Color.Red);
 
            glControl1.Paint += new PaintEventHandler(glControl1_Paint);
            glControl2.Paint += new PaintEventHandler(glControl2_Paint);
        }

This will make the first control clear to green and the second control clear to red.
Adding the glControl.MakeCurrent() for the respective control in the Paint methods will allow you to draw to that control.

I've made a quick test case of this if you want some more source code to look at.