Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1452 | chris | 1 | #region License |
| 2 | // |
||
| 3 | // The Open Toolkit Library License |
||
| 4 | // |
||
| 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. |
||
| 6 | // |
||
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
||
| 8 | // of this software and associated documentation files (the "Software"), to deal |
||
| 9 | // in the Software without restriction, including without limitation the rights to |
||
| 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||
| 11 | // the Software, and to permit persons to whom the Software is furnished to do |
||
| 12 | // so, subject to the following conditions: |
||
| 13 | // |
||
| 14 | // The above copyright notice and this permission notice shall be included in all |
||
| 15 | // copies or substantial portions of the Software. |
||
| 16 | // |
||
| 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||
| 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||
| 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||
| 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
||
| 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||
| 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
| 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||
| 24 | // OTHER DEALINGS IN THE SOFTWARE. |
||
| 25 | // |
||
| 26 | #endregion |
||
| 27 | |||
| 28 | #region --- Using Directives --- |
||
| 29 | |||
| 30 | using System; |
||
| 31 | using System.Collections.Generic; |
||
| 32 | using System.ComponentModel; |
||
| 33 | using System.Data; |
||
| 34 | using System.Drawing; |
||
| 35 | using System.Text; |
||
| 36 | using System.Windows.Forms; |
||
| 37 | using System.Threading; |
||
| 38 | |||
| 39 | using OpenTK; |
||
| 40 | using OpenTK.Graphics.OpenGL; |
||
| 41 | |||
| 42 | #endregion --- Using Directives --- |
||
| 43 | |||
| 44 | namespace Examples.Tutorial |
||
| 45 | { |
||
| 46 | [Example("Display Lists", ExampleCategory.OpenGL, "1.x", 2, Documentation="DisplayLists")] |
||
| 47 | public class T07_Display_Lists_Flower : GameWindow |
||
| 48 | { |
||
| 49 | #region --- Fields --- |
||
| 50 | |||
| 51 | const int num_lists = 13; |
||
| 52 | int[] lists = new int[num_lists]; |
||
| 53 | |||
| 54 | #endregion |
||
| 55 | |||
| 56 | #region --- Constructor --- |
||
| 57 | |||
| 58 | public T07_Display_Lists_Flower() |
||
| 59 | : base(800, 600) |
||
| 60 | { |
||
| 61 | } |
||
| 62 | |||
| 63 | #endregion |
||
| 64 | |||
| 65 | #region OnLoad |
||
| 66 | |||
| 67 | protected override void OnLoad(EventArgs e) |
||
| 68 | { |
||
| 69 | GL.ClearColor(Color.MidnightBlue); |
||
| 70 | GL.Enable(EnableCap.DepthTest); |
||
| 71 | |||
| 72 | GL.MatrixMode(MatrixMode.Modelview); |
||
| 73 | GL.LoadIdentity(); |
||
| 74 | |||
| 75 | // Build some display lists. |
||
| 76 | int first_list = GL.GenLists(num_lists); |
||
| 77 | float c = 0; |
||
| 78 | for (int i = 0; i < num_lists; i++) |
||
| 79 | { |
||
| 80 | lists[i] = first_list + i; |
||
| 81 | GL.NewList(first_list + i, ListMode.Compile); |
||
| 82 | |||
| 83 | GL.Color3(0.3 + 0.7 * c * c, 0.3 + 1.4 * c * c, 0.7 - 0.7 * c * c); |
||
| 84 | c += 1 / (float)num_lists; |
||
| 85 | |||
| 86 | GL.PushMatrix(); |
||
| 87 | |||
| 88 | GL.Rotate(c * 360.0f, 0.0, 0.0, 1.0); |
||
| 89 | GL.Translate(5.0, 0.0, 0.0); |
||
| 90 | |||
| 91 | GL.Begin(BeginMode.Quads); |
||
| 92 | |||
| 93 | GL.Vertex3(-1.0f, -1.0f, 1.0f); |
||
| 94 | GL.Vertex3(1.0f, -1.0f, 1.0f); |
||
| 95 | GL.Vertex3(1.0f, 1.0f, 1.0f); |
||
| 96 | GL.Vertex3(-1.0f, 1.0f, 1.0f); |
||
| 97 | |||
| 98 | GL.End(); |
||
| 99 | |||
| 100 | GL.PopMatrix(); |
||
| 101 | |||
| 102 | GL.EndList(); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | #endregion |
||
| 107 | |||
| 108 | #region OnUnload |
||
| 109 | |||
| 110 | protected override void OnUnload(EventArgs e) |
||
| 111 | { |
||
| 112 | GL.DeleteLists(lists[0], num_lists); |
||
| 113 | } |
||
| 114 | |||
| 115 | #endregion |
||
| 116 | |||
| 117 | #region OnResize |
||
| 118 | |||
| 119 | protected override void OnResize(EventArgs e) |
||
| 120 | { |
||
| 121 | GL.Viewport(ClientRectangle); |
||
| 122 | |||
| 123 | float aspect = this.ClientSize.Width / (float)this.ClientSize.Height; |
||
| 124 | |||
| 125 | Matrix4 projection_matrix; |
||
| 126 | Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, aspect, 1, 64, out projection_matrix); |
||
| 127 | |||
| 128 | GL.MatrixMode(MatrixMode.Projection); |
||
| 129 | GL.LoadMatrix(ref projection_matrix); |
||
| 130 | } |
||
| 131 | |||
| 132 | #endregion |
||
| 133 | |||
| 134 | #region OnUpdateFrame |
||
| 135 | |||
| 136 | protected override void OnUpdateFrame(FrameEventArgs e) |
||
| 137 | { |
||
| 138 | if (Keyboard[OpenTK.Input.Key.Escape]) |
||
| 139 | { |
||
| 140 | this.Exit(); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | #endregion |
||
| 145 | |||
| 146 | #region OnRenderFrame |
||
| 147 | |||
| 148 | protected override void OnRenderFrame(FrameEventArgs e) |
||
| 149 | { |
||
| 150 | Matrix4 lookat = Matrix4.LookAt(0, 0, 16, 0, 0, 0, 0, 1, 0); |
||
| 151 | GL.MatrixMode(MatrixMode.Modelview); |
||
| 152 | GL.LoadMatrix(ref lookat); |
||
| 153 | |||
| 154 | GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); |
||
| 155 | GL.CallLists(num_lists, ListNameType.Int, lists); |
||
| 156 | |||
| 157 | SwapBuffers(); |
||
| 158 | } |
||
| 159 | |||
| 160 | #endregion |
||
| 161 | |||
| 162 | #region public static void Main() |
||
| 163 | |||
| 164 | /// <summary> |
||
| 165 | /// Entry point of this example. |
||
| 166 | /// </summary> |
||
| 167 | [STAThread] |
||
| 168 | public static void Main() |
||
| 169 | { |
||
| 170 | using (T07_Display_Lists_Flower example = new T07_Display_Lists_Flower()) |
||
| 171 | { |
||
| 172 | Utilities.SetWindowTitle(example); |
||
| 173 | example.Run(30.0, 0.0); |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | #endregion |
||
| 178 | } |
||
| 179 | } |