#region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Threading;
using OpenTK;
using OpenTK.OpenGL;
namespace Examples.Tutorial
{
class T02_Vertex_Array_Cube : GameWindow, IExample
{
float angle;
#region Constructor
public T02_Vertex_Array_Cube()
{
this.CreateWindow(new DisplayMode(800, 600));
}
#endregion
#region OnLoad
public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
GL.ClearColor(Color.MidnightBlue);
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
GL.EnableClientState(GL.Enums.EnableCap.VERTEX_ARRAY);
GL.EnableClientState(GL.Enums.EnableCap.COLOR_ARRAY);
GL.VertexPointer(3, GL.Enums.VertexPointerType.FLOAT, 0, Shapes.Cube.Vertices);
GL.ColorPointer(4, GL.Enums.ColorPointerType.UNSIGNED_BYTE, 0, Shapes.Cube.Colors);
}
#endregion
#region OnResize
///
/// Called when the user resizes the window.
///
/// Contains the new width/height of the window.
///
/// You want the OpenGL viewport to match the window. This is the place to do it!
///
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
{
base.OnResize(e);
GL.Viewport(0, 0, Width, Height);
double ratio = e.Width / (double)e.Height;
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
GL.LoadIdentity();
Glu.Perspective(45.0, ratio, 1.0, 64.0);
}
#endregion
#region OnUpdateFrame
///
/// Prepares the next frame for rendering.
///
///
/// Place your control logic here. This is the place to respond to user input,
/// update object positions etc.
///
public override void OnUpdateFrame(UpdateFrameEventArgs e)
{
if (Keyboard[0][OpenTK.Input.Key.Escape])
{
this.Exit();
return;
}
if ((Keyboard[0][OpenTK.Input.Key.AltLeft] || Keyboard[0][OpenTK.Input.Key.AltRight]) &&
Keyboard[0][OpenTK.Input.Key.Enter])
{
Fullscreen = !Fullscreen;
}
//angle += 180.0f * (float)e.Time;
angle += 3.0f;
if (angle > 720.0f)
angle -= 720.0f;
}
#endregion
#region OnRenderFrame
///
/// Place your rendering code here.
///
public override void OnRenderFrame(RenderFrameEventArgs e)
{
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
GL.LoadIdentity();
Glu.LookAt(
0.0, 5.0, 5.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0
);
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, Shapes.Cube.Indices.Length,
GL.Enums.All.UNSIGNED_SHORT, Shapes.Cube.Indices);
Context.SwapBuffers();
}
#endregion
#region public void Launch()
///
/// Launches this example.
///
///
/// Provides a simple way for the example launcher to launch the examples.
///
public void Launch()
{
// Lock UpdateFrame and RenderFrame at 60Hz.
Run(60.0, 60.0);
}
#endregion
}
}