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.Windows.Forms;
|
2007-09-02 00:07:40 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Drawing;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.OpenGL;
|
|
|
|
|
using OpenTK.Platform;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace Examples.Tutorial
|
|
|
|
|
{
|
2007-09-26 15:39:32 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Demonstrates immediate mode rendering. Example is incomplete, and will probably go away in the future.
|
|
|
|
|
/// </summary>
|
2007-09-02 00:07:40 +00:00
|
|
|
|
public class T03_Immediate_Mode_Cube : OpenTK.GameWindow, IExample
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
|
|
|
|
#region --- Fields ---
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Denotes the cube rotation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
float angle = 0.0f;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
2007-09-02 00:07:40 +00:00
|
|
|
|
public T03_Immediate_Mode_Cube()
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
CreateWindow(new DisplayMode(800, 600));
|
2007-08-06 11:22:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnLoad
|
|
|
|
|
|
|
|
|
|
public override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
2007-09-22 22:01:43 +00:00
|
|
|
|
GL.ClearColor(Color.MidnightBlue);
|
2007-09-02 00:07:40 +00:00
|
|
|
|
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-08-06 11:22:18 +00:00
|
|
|
|
|
|
|
|
|
#region OnResize
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called when the user resizes the window.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">Contains the new width/height of the window.</param>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// You want the OpenGL viewport to match the window. This is the place to do it!
|
|
|
|
|
/// </remarks>
|
|
|
|
|
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnResize(e);
|
|
|
|
|
|
2007-08-21 12:04:01 +00:00
|
|
|
|
GL.Viewport(0, 0, Width, Height);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
double ratio = e.Width / (double)e.Height;
|
|
|
|
|
|
2007-09-02 00:07:40 +00:00
|
|
|
|
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
GL.LoadIdentity();
|
|
|
|
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-06 11:22:18 +00:00
|
|
|
|
#region OnUpdateFrame
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Prepares the next frame for rendering.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Place your control logic here. This is the place to respond to user input,
|
|
|
|
|
/// update object positions etc.
|
|
|
|
|
/// </remarks>
|
2007-09-22 22:01:43 +00:00
|
|
|
|
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-09-30 12:36:41 +00:00
|
|
|
|
/*
|
2007-09-26 11:47:30 +00:00
|
|
|
|
if (Keyboard[OpenTK.Input.Key.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
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
if ((Keyboard[OpenTK.Input.Key.AltLeft] || Keyboard[OpenTK.Input.Key.AltRight]) &&
|
|
|
|
|
Keyboard[OpenTK.Input.Key.Enter])
|
2007-07-31 21:50:29 +00:00
|
|
|
|
{
|
2007-08-05 13:51:07 +00:00
|
|
|
|
Fullscreen = !Fullscreen;
|
2007-07-31 21:50:29 +00:00
|
|
|
|
}
|
2007-09-30 12:36:41 +00:00
|
|
|
|
*/
|
2007-09-23 12:49:38 +00:00
|
|
|
|
angle += 3.0f;
|
|
|
|
|
if (angle > 720.0f)
|
|
|
|
|
angle -= 720.0f;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-06 11:22:18 +00:00
|
|
|
|
#region OnRenderFrame
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Place your rendering code here.
|
|
|
|
|
/// </summary>
|
2007-09-23 12:09:42 +00:00
|
|
|
|
public override void OnRenderFrame(RenderFrameEventArgs e)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-09-02 00:07:40 +00:00
|
|
|
|
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-09-23 12:49:38 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
DrawCube();
|
|
|
|
|
|
|
|
|
|
Context.SwapBuffers();
|
2007-08-06 12:13:50 +00:00
|
|
|
|
Thread.Sleep(0);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-03 00:14:31 +00:00
|
|
|
|
#region private void DrawCube()
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-03 00:14:31 +00:00
|
|
|
|
private void DrawCube()
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-20 10:46:37 +00:00
|
|
|
|
GL.Begin(GL.Enums.BeginMode.QUADS);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-09-02 00:07:40 +00:00
|
|
|
|
GL.Color3(Color.Silver);
|
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-09-02 00:07:40 +00:00
|
|
|
|
GL.Color3(Color.Honeydew);
|
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-09-02 00:07:40 +00:00
|
|
|
|
GL.Color3(Color.Moccasin);
|
|
|
|
|
|
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-09-02 00:07:40 +00:00
|
|
|
|
GL.Color3(Color.IndianRed);
|
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-09-02 00:07:40 +00:00
|
|
|
|
GL.Color3(Color.PaleVioletRed);
|
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);
|
2007-08-20 10:46:37 +00:00
|
|
|
|
GL.Vertex3(1.0f, 1.0f, -1.0f);
|
2007-08-01 21:14:39 +00:00
|
|
|
|
|
2007-09-02 00:07:40 +00:00
|
|
|
|
GL.Color3(Color.ForestGreen);
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
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-10-20 10:54:40 +00:00
|
|
|
|
Run(85.0, 0.0);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-10-20 10:54:40 +00:00
|
|
|
|
|
|
|
|
|
public static readonly int order = 3;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|