1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
// This code was written for the OpenTK library and has been released
// to the Public Domain.
// It is provided "as is" without express or implied warranty of any kind.
#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;
using OpenTK.Graphics.OpenGL;
#endregion --- Using Directives ---
namespace Examples.Tutorial
{
[Example("Display Lists", ExampleCategory.OpenGL, "1.x", 2, Documentation = "DisplayLists")]
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
protected override void OnLoad(EventArgs e)
{
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(PrimitiveType.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
protected override void OnUnload(EventArgs e)
{
GL.DeleteLists(lists[0], num_lists);
}
#endregion
#region OnResize
protected override void OnResize(EventArgs e)
{
GL.Viewport(ClientRectangle);
float aspect = this.ClientSize.Width / (float)this.ClientSize.Height;
Matrix4 projection_matrix;
Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, aspect, 1, 64, out projection_matrix);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadMatrix(ref projection_matrix);
}
#endregion
#region OnUpdateFrame
protected override void OnUpdateFrame(FrameEventArgs e)
{
var keyboard = OpenTK.Input.Keyboard.GetState();
if (keyboard[OpenTK.Input.Key.Escape])
{
this.Exit();
}
}
#endregion
#region OnRenderFrame
protected override void OnRenderFrame(FrameEventArgs e)
{
Matrix4 lookat = Matrix4.LookAt(0, 0, 16, 0, 0, 0, 0, 1, 0);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref lookat);
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())
{
Utilities.SetWindowTitle(example);
example.Run(30.0, 0.0);
}
}
#endregion
}
}
|