mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-26 18:15:39 +00:00
2f64fb372e
Updated the ExampleLauncher to not process exceptions. Updated the IExample interface to contain the Launch method. Updated examples and the ExampleLauncher according to the IExample interface. Synced with gl3 branch.
191 lines
5.1 KiB
C#
191 lines
5.1 KiB
C#
#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;
|
|
|
|
using OpenTK;
|
|
using OpenTK.OpenGL;
|
|
using OpenTK.Platform;
|
|
using Enums = OpenTK.OpenGL.GL.Enums;
|
|
|
|
#endregion
|
|
|
|
namespace Examples.Tutorial
|
|
{
|
|
public class T03_RotatingCube : OpenTK.GameWindow, IExample
|
|
{
|
|
#region --- Fields ---
|
|
|
|
/// <summary>
|
|
/// Denotes the cube rotation.
|
|
/// </summary>
|
|
float angle = 0.0f;
|
|
|
|
#endregion
|
|
|
|
#region --- Constructors ---
|
|
|
|
public T03_RotatingCube()
|
|
{
|
|
Context.MakeCurrent();
|
|
|
|
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
|
|
GL.Enable(Enums.EnableCap.DEPTH_TEST);
|
|
|
|
this.OnResize(new ResizeEventArgs(this.Width, this.Height));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Resize event handler
|
|
|
|
/// <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);
|
|
|
|
GL.Viewport(0, 0, e.Width, e.Height);
|
|
|
|
double ratio = e.Width / (double)e.Height;
|
|
|
|
GL.MatrixMode(Enums.MatrixMode.PROJECTION);
|
|
GL.LoadIdentity();
|
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region UpdateFrame function
|
|
|
|
/// <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>
|
|
public override void UpdateFrame()
|
|
{
|
|
if (Key[OpenTK.Input.Keys.Escape])
|
|
{
|
|
Quit = true;
|
|
return;
|
|
}
|
|
|
|
if ((Key[OpenTK.Input.Keys.LeftAlt] || Key[OpenTK.Input.Keys.RightAlt]) &&
|
|
Key[OpenTK.Input.Keys.Enter])
|
|
{
|
|
Fullscreen = true;
|
|
}
|
|
|
|
GL.MatrixMode(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.Rotatef(angle, 0.0f, 1.0f, 0.0f);
|
|
angle += 0.5f;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region RenderFrame function
|
|
|
|
/// <summary>
|
|
/// Place your rendering code here.
|
|
/// </summary>
|
|
public override void RenderFrame()
|
|
{
|
|
GL.Clear(Enums.ClearBufferMask.COLOR_BUFFER_BIT | Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
|
|
|
DrawCube();
|
|
|
|
Context.SwapBuffers();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private void DrawCube()
|
|
|
|
private void DrawCube()
|
|
{
|
|
GL.Begin(GL.Enums.BeginMode.QUADS);
|
|
|
|
GL.Color3(1.0f, 0.0f, 0.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.Vertex3(1.0f, -1.0f, -1.0f);
|
|
|
|
GL.Color3(1.0f, 1.0f, 0.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.Vertex3(-1.0f, -1.0f, 1.0f);
|
|
|
|
GL.Color3(1.0f, 0.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.Vertex3(-1.0f, 1.0f, -1.0f);
|
|
|
|
GL.Color3(0.0f, 1.0f, 0.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.Vertex3(-1.0f, 1.0f, 1.0f);
|
|
|
|
GL.Color3(0.0f, 0.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.Vertex3(1.0f, 1.0f, -1.0f);
|
|
|
|
GL.Color3(0.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.Vertex3(1.0f, -1.0f, 1.0f);
|
|
|
|
GL.End();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region public void Launch()
|
|
|
|
/// <summary>
|
|
/// Launches this example.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Provides a simple way for the example launcher to launch the examples.
|
|
/// </remarks>
|
|
public void Launch()
|
|
{
|
|
//using (T03_RotatingCube ex = new T03_RotatingCube())
|
|
{
|
|
//ex.Run();
|
|
Run();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|