adityatan's picture

Where to put GL.Rotate in Windows App?

Hi there:

I have made a program that works in a Console App. But now, as I try to move the whole thing to a Windows App, my GL.Rotate does not work properly. Please help me in catching the error.

Here's where I set up my GL.Rotate.

private void glControl1_Paint(object sender, PaintEventArgs e)
{
            GL.MatrixMode(MatrixMode.Modelview);
            GL.Translate(0, 0, -500);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.LoadMatrix(ref cameraMatrix);
 
            GL.Rotate(camera_rotationY, 0, 1, 0); // Add the Y-rotation
            GL.Rotate(camera_rotationZ, 0, 0, 1); // Add the Z-rotation
 
            glControl1.SwapBuffers();
}
 
private void glControl1_KeyDown(object sender, KeyEventArgs e)
{
            ...
 
            if (e.KeyCode == Keys.Up)
            {
                camera_rotationZ -= 5;
            }
 
            if (e.KeyCode == Keys.Down)
            {
                camera_rotationZ += 5;
            }
 
            if (e.KeyCode == Keys.Left)
            {
                camera_rotationY -= 5;
            }
 
            if (e.KeyCode == Keys.Right)
            {
                camera_rotationY += 5;
            }
 
            Vector3 lookatPoint = new Vector3((float)Math.Cos(facing), (float)Math.Sin(pitch / 2), (float)Math.Sin(facing));
            cameraMatrix = Matrix4.LookAt(location, location + lookatPoint, up);
 
            glControl1.Invalidate();
}

Every single code is a replica of what I've done in the Console App; but again, it does not seem to work here. Any idea why? Am I, maybe, supposed to put "GL.Rotate(camera_rotationY, 0, 1, 0);" somewhere else, such as inside "private void glControl1_Resize(object sender, EventArgs e)," or "private void glControl1_Load(object sender, EventArgs e)?"

Thank you for your help!

Aditya


Comments

Comment viewing options

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

Got it! Everything is here: http://www.opentk.com/doc/chapter/2/glcontrol. I wish I had found this site much earlier!

Thanks!

Aditya