Strange problem with draw

Jun 7, 2013 at 2:54 PM
I have two OpenGLControls on a single winform.

If I right click one of those windows, I maximize the clicked window, and hide the other.

This works fine about half the time. The other half the time, it renders to the right half the winform, and then "slides" off the right side.

Here are some pictures of the problem:

Normal:
Image

Normal Maximized:

Image

Problem:

Image


The fact that this only happens half the time is confusing me to no end.

Here's some relevent code:

The draw:
private void DrawLense(Render eye, float width, float height)
        { 
            const float centerOffset = -22f;
            CalculateRotation();
        eye.Clear();
            eye.MatrixMode(OpenGL.GL_MODELVIEW);
            eye.PushMatrix();
            eye.LoadIdentity();
            eye.Translate(0.0f, 0.0f, _cameraZoom);
            eye.Rotate(_xRot, _zRot);
            eye.Translate(0.0f, 0.0f, centerOffset);
            eye.AdjustPerspective(width,height);
            eye.Draw();
            eye.PopMatrix();
        }
The maximize switch:
private void FocusOnControl(Control s)
        {
            _isFocused = !_isFocused;
            var eyeIndex = GetEyeIndex(s);

            var width = _isFocused ? this.Width : this.Width / 2;
            var height = _isFocused ? this.Height : this.Height / (_eyes.Length / 2);
            var xPosition = _isFocused ? 0 : eyeIndex % 2 == 0 ? 0 : this.Width / 2;
            var yPosition = _isFocused ? 0 : (eyeIndex / 2) * height;

            foreach (var c in this.Controls.OfType<OpenGLControl>().Where(c => c != s))
            {
                c.Enabled = !c.Enabled;
                c.Visible = !c.Visible;
            }
            s.Size = new Size(width, height);
            s.Location = new Point(xPosition, yPosition);
        }
And the method to adjust the view:
 public void AdjustPerspective(double width, double height)
        {
            Debug.WriteLine(control.Name + " : " + width + " : " +  height);
            _gl.MatrixMode(OpenGL.GL_VIEWPORT);
            _gl.Viewport(0, 0, (int)width, (int)height);
            _gl.MatrixMode(OpenGL.GL_PROJECTION);
            _gl.LoadIdentity();
            _gl.Perspective(45.0f, width/height, .1, 400);

            _gl.MatrixMode(OpenGL.GL_MODELVIEW);

        }
I've been working on this for a couple days, and this I cannot figure this problem out.
Jun 7, 2013 at 4:03 PM
I fixed it by setting the RenderContextMode to RenderContext.NativeWindow