2007-07-23 00:15:18 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Using Directives ---
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using OpenTK.OpenGL;
|
2007-08-01 09:32:49 +00:00
|
|
|
|
using Enums = OpenTK.OpenGL.GL.Enums;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
|
|
#endregion --- Using Directives ---
|
|
|
|
|
|
|
|
|
|
namespace Examples.Tutorial
|
|
|
|
|
{
|
|
|
|
|
public partial class T07_DisplayLists_Cube : GameWindow, IExample
|
|
|
|
|
{
|
|
|
|
|
#region --- Variables ---
|
|
|
|
|
|
|
|
|
|
List<DisplayList> lists = new List<DisplayList>();
|
|
|
|
|
|
|
|
|
|
#endregion --- Variables ---
|
|
|
|
|
|
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
|
|
|
|
public T07_DisplayLists_Cube()
|
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
this.CreateWindow(new OpenTK.Platform.DisplayMode(800, 600));
|
2007-07-23 00:15:18 +00:00
|
|
|
|
//Text =
|
|
|
|
|
// "DisplayLists example (" +
|
|
|
|
|
// GL.GetString(Enums.StringName.RENDERER) + " " +
|
|
|
|
|
// GL.GetString(Enums.StringName.VERSION)
|
|
|
|
|
// + ")";
|
|
|
|
|
|
|
|
|
|
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
|
|
|
|
|
GL.Enable(Enums.EnableCap.DEPTH_TEST);
|
|
|
|
|
|
|
|
|
|
// Build some display lists.
|
|
|
|
|
float c = 0;
|
|
|
|
|
const int numDisplayLists = 9;
|
|
|
|
|
for (int i = numDisplayLists; i > 0; i--)
|
|
|
|
|
{
|
|
|
|
|
DisplayList d = new DisplayList();
|
|
|
|
|
|
|
|
|
|
d.Begin();
|
|
|
|
|
|
2007-08-01 21:14:39 +00:00
|
|
|
|
GL.Color3(
|
2007-07-23 00:15:18 +00:00
|
|
|
|
1.0,
|
|
|
|
|
c,
|
|
|
|
|
1 - c
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
GL.Begin(Enums.BeginMode.QUADS);
|
|
|
|
|
|
2007-08-01 21:14:39 +00:00
|
|
|
|
GL.Vertex3(-1.0f, -1.0f, 1.0f);
|
|
|
|
|
GL.Vertex3( 1.0f, -1.0f, 1.0f);
|
|
|
|
|
GL.Vertex3( 1.0f, 1.0f, 1.0f);
|
|
|
|
|
GL.Vertex3(-1.0f, 1.0f, 1.0f);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
GL.End();
|
|
|
|
|
|
|
|
|
|
d.End();
|
|
|
|
|
|
|
|
|
|
lists.Add(d);
|
|
|
|
|
|
|
|
|
|
c += 1 / (float)numDisplayLists;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnResize(new OpenTK.Platform.ResizeEventArgs(this.Width, this.Height));
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
#endregion
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-03 00:14:31 +00:00
|
|
|
|
#region public void Launch()
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Launches this example.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Provides a simple way for the example launcher to launch the examples.
|
|
|
|
|
/// </remarks>
|
2007-08-03 00:14:31 +00:00
|
|
|
|
public void Launch()
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
Run();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Event Handlers ---
|
|
|
|
|
|
|
|
|
|
#region OnResize
|
|
|
|
|
|
|
|
|
|
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnResize(e);
|
|
|
|
|
|
|
|
|
|
GL.Viewport(0, 0, this.Width, this.Height);
|
|
|
|
|
|
|
|
|
|
double ratio = 0.0;
|
|
|
|
|
ratio = this.Width / (double)this.Height;
|
|
|
|
|
|
|
|
|
|
GL.MatrixMode(Enums.MatrixMode.PROJECTION);
|
|
|
|
|
GL.LoadIdentity();
|
|
|
|
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
|
|
|
|
Glu.LookAt(
|
|
|
|
|
0.0, 0.0, 16.0,
|
|
|
|
|
0.0, 0.0, 0.0,
|
|
|
|
|
0.0, 1.0, 0.0
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
#region OnRenderFrame
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
public override void OnRenderFrame()
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
base.OnRenderFrame();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
GL.MatrixMode(Enums.MatrixMode.MODELVIEW);
|
|
|
|
|
GL.LoadIdentity();
|
|
|
|
|
|
|
|
|
|
GL.Clear(Enums.ClearBufferMask.COLOR_BUFFER_BIT | Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
double angle = 0.0;
|
|
|
|
|
foreach (DisplayList d in lists)
|
|
|
|
|
{
|
|
|
|
|
GL.LoadIdentity();
|
|
|
|
|
GL.Rotated(angle, 0.0, 0.0, 1.0);
|
|
|
|
|
GL.Translated(5.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
|
|
d.Render();
|
|
|
|
|
angle += 360 / lists.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Context.SwapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
#region OnUpdateFrame
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
public override void OnUpdateFrame()
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
base.OnUpdateFrame();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
if (Keyboard[0][OpenTK.Input.Keys.Escape])
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
this.Exit();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion --- Event Handlers ---
|
|
|
|
|
}
|
|
|
|
|
}
|