using System;
using System.Drawing;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace OpenTKTest
{
public partial class Form1 : Form
{
static float angle = 0.0f;
private float deltaAngle = 8;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
glControl_Resize(glControl1, EventArgs.Empty);
}
void glControl_Resize(object sender, EventArgs e)
{
Init2(sender as OpenTK.GLControl);
}
private void Init2(OpenTK.GLControl c)
{
if (c.ClientSize.Height == 0)
c.ClientSize = new System.Drawing.Size(c.ClientSize.Width, 1);
GL.Viewport(0, 0, c.ClientSize.Width, c.ClientSize.Height);
float aspect_ratio = Width / (float)Height;
Matrix4 perpective = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspect_ratio, 1, 64);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadMatrix(ref perpective);
}
private void glControl1_Paint(object sender, PaintEventArgs e)
{
Render();
}
private void Render()
{
Matrix4 lookat = Matrix4.LookAt(0, 5, 5, 0, 0, 0, 0, 1, 0);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref lookat);
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
DrawTekitou();
glControl1.SwapBuffers();
}
private void DrawTekitou()
{
GL.Begin(PrimitiveType.Quads);
GL.Color3(Color.Silver);
GL.Vertex2(-1, -1);
GL.Vertex2(-1, 1);
GL.Vertex2(1, 1);
GL.Vertex2(1, -1);
GL.End();
}
private void button5_Click(object sender, EventArgs e)
{
angle += deltaAngle;
glControl1.Invalidate();
}
private void btnRight_Click(object sender, EventArgs e)
{
angle -= deltaAngle;
glControl1.Invalidate();
}
}
}
最終更新:2016年03月21日 23:22