2009-06-26 21:06:28 +00:00
|
|
|
|
#region License
|
|
|
|
|
//
|
|
|
|
|
// The Open Toolkit Library License
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights to
|
|
|
|
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
|
// the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
|
// so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
//
|
2009-02-22 10:43:35 +00:00
|
|
|
|
#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 System.Threading;
|
|
|
|
|
|
|
|
|
|
using OpenTK;
|
2009-08-14 13:13:28 +00:00
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
#endregion --- Using Directives ---
|
|
|
|
|
|
|
|
|
|
namespace Examples.Tutorial
|
|
|
|
|
{
|
2009-04-20 09:48:33 +00:00
|
|
|
|
[Example("Display Lists", ExampleCategory.OpenGL, "1.1", Documentation="DisplayLists")]
|
2009-02-22 10:43:35 +00:00
|
|
|
|
public class T07_Display_Lists_Flower : GameWindow
|
|
|
|
|
{
|
|
|
|
|
#region --- Fields ---
|
|
|
|
|
|
|
|
|
|
const int num_lists = 13;
|
|
|
|
|
int[] lists = new int[num_lists];
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Constructor ---
|
|
|
|
|
|
|
|
|
|
public T07_Display_Lists_Flower()
|
|
|
|
|
: base(800, 600)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnLoad
|
|
|
|
|
|
2009-10-21 13:33:00 +00:00
|
|
|
|
protected override void OnLoad(EventArgs e)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
GL.ClearColor(Color.MidnightBlue);
|
|
|
|
|
GL.Enable(EnableCap.DepthTest);
|
|
|
|
|
|
|
|
|
|
GL.MatrixMode(MatrixMode.Modelview);
|
|
|
|
|
GL.LoadIdentity();
|
|
|
|
|
|
|
|
|
|
// Build some display lists.
|
|
|
|
|
int first_list = GL.GenLists(num_lists);
|
|
|
|
|
float c = 0;
|
|
|
|
|
for (int i = 0; i < num_lists; i++)
|
|
|
|
|
{
|
|
|
|
|
lists[i] = first_list + i;
|
|
|
|
|
GL.NewList(first_list + i, ListMode.Compile);
|
|
|
|
|
|
|
|
|
|
GL.Color3(0.3 + 0.7 * c * c, 0.3 + 1.4 * c * c, 0.7 - 0.7 * c * c);
|
|
|
|
|
c += 1 / (float)num_lists;
|
|
|
|
|
|
|
|
|
|
GL.PushMatrix();
|
|
|
|
|
|
|
|
|
|
GL.Rotate(c * 360.0f, 0.0, 0.0, 1.0);
|
|
|
|
|
GL.Translate(5.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
|
|
GL.Begin(BeginMode.Quads);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
GL.End();
|
|
|
|
|
|
|
|
|
|
GL.PopMatrix();
|
|
|
|
|
|
|
|
|
|
GL.EndList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnUnload
|
|
|
|
|
|
|
|
|
|
public override void OnUnload(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GL.DeleteLists(lists[0], num_lists);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnResize
|
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
|
protected override void OnResize(EventArgs e)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-06-25 22:47:59 +00:00
|
|
|
|
GL.Viewport(ClientRectangle);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
2009-06-25 22:47:59 +00:00
|
|
|
|
float aspect = this.ClientSize.Width / (float)this.ClientSize.Height;
|
|
|
|
|
|
|
|
|
|
Matrix4 projection_matrix;
|
|
|
|
|
Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, aspect, 1, 64, out projection_matrix);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
GL.MatrixMode(MatrixMode.Projection);
|
2009-06-25 22:47:59 +00:00
|
|
|
|
GL.LoadMatrix(ref projection_matrix);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnUpdateFrame
|
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
|
protected override void OnUpdateFrame(FrameEventArgs e)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
if (Keyboard[OpenTK.Input.Key.Escape])
|
|
|
|
|
{
|
|
|
|
|
this.Exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnRenderFrame
|
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
|
protected override void OnRenderFrame(FrameEventArgs e)
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-08-14 13:13:28 +00:00
|
|
|
|
Matrix4 lookat = Matrix4.LookAt(0, 0, 16, 0, 0, 0, 0, 1, 0);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
GL.MatrixMode(MatrixMode.Modelview);
|
2009-08-14 13:13:28 +00:00
|
|
|
|
GL.LoadMatrix(ref lookat);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
|
|
|
|
GL.CallLists(num_lists, ListNameType.Int, lists);
|
|
|
|
|
|
|
|
|
|
SwapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public static void Main()
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Entry point of this example.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main()
|
|
|
|
|
{
|
|
|
|
|
using (T07_Display_Lists_Flower example = new T07_Display_Lists_Flower())
|
|
|
|
|
{
|
2009-06-26 21:06:28 +00:00
|
|
|
|
Utilities.SetWindowTitle(example);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
example.Run(30.0, 0.0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|