mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-26 03:45:39 +00:00
4ceea208ac
WinRawInput now correctly subclasses WinGLNative or WinGLControl. WinRawKeyboard now correctly responds to events. Removed T10_GLSL_Cube.cs which was erroneously moved outside the Examples/Tutorial directory. Updated INativeWindow, IGameWindow and IGLControl interfaces. Updated examples to use the new GameWindow interface. Added documentation to GameWindow. Improved GameWindow error handling. More defensive programming.
167 lines
4.1 KiB
C#
167 lines
4.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.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
using OpenTK.OpenGL;
|
|
using Enums = OpenTK.OpenGL.GL.Enums;
|
|
using OpenTK;
|
|
|
|
#endregion --- Using Directives ---
|
|
|
|
namespace Examples.Tutorial
|
|
{
|
|
public partial class T07_DisplayLists_Cube : GameWindow, IExample
|
|
{
|
|
#region --- Variables ---
|
|
|
|
List<DisplayList> lists = new List<DisplayList>();
|
|
|
|
#endregion --- Variables ---
|
|
|
|
#region --- Constructors ---
|
|
|
|
public T07_DisplayLists_Cube()
|
|
{
|
|
this.CreateWindow(new OpenTK.Platform.DisplayMode(800, 600));
|
|
//Text =
|
|
// "DisplayLists example (" +
|
|
// GL.GetString(Enums.StringName.RENDERER) + " " +
|
|
// GL.GetString(Enums.StringName.VERSION)
|
|
// + ")";
|
|
|
|
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
|
|
GL.Enable(Enums.EnableCap.DEPTH_TEST);
|
|
|
|
// Build some display lists.
|
|
float c = 0;
|
|
const int numDisplayLists = 9;
|
|
for (int i = numDisplayLists; i > 0; i--)
|
|
{
|
|
DisplayList d = new DisplayList();
|
|
|
|
d.Begin();
|
|
|
|
GL.Color3(
|
|
1.0,
|
|
c,
|
|
1 - c
|
|
);
|
|
|
|
GL.Begin(Enums.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();
|
|
|
|
d.End();
|
|
|
|
lists.Add(d);
|
|
|
|
c += 1 / (float)numDisplayLists;
|
|
}
|
|
|
|
OnResize(new OpenTK.Platform.ResizeEventArgs(this.Width, this.Height));
|
|
}
|
|
|
|
#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()
|
|
{
|
|
Run();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region --- Event Handlers ---
|
|
|
|
#region OnResize
|
|
|
|
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
|
{
|
|
base.OnResize(e);
|
|
|
|
GL.Viewport(0, 0, this.Width, this.Height);
|
|
|
|
double ratio = 0.0;
|
|
ratio = this.Width / (double)this.Height;
|
|
|
|
GL.MatrixMode(Enums.MatrixMode.PROJECTION);
|
|
GL.LoadIdentity();
|
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
|
Glu.LookAt(
|
|
0.0, 0.0, 16.0,
|
|
0.0, 0.0, 0.0,
|
|
0.0, 1.0, 0.0
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region OnRenderFrame
|
|
|
|
public override void OnRenderFrame()
|
|
{
|
|
base.OnRenderFrame();
|
|
|
|
GL.MatrixMode(Enums.MatrixMode.MODELVIEW);
|
|
GL.LoadIdentity();
|
|
|
|
GL.Clear(Enums.ClearBufferMask.COLOR_BUFFER_BIT | Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
|
|
|
double angle = 0.0;
|
|
foreach (DisplayList d in lists)
|
|
{
|
|
GL.LoadIdentity();
|
|
GL.Rotated(angle, 0.0, 0.0, 1.0);
|
|
GL.Translated(5.0, 0.0, 0.0);
|
|
|
|
d.Render();
|
|
angle += 360 / lists.Count;
|
|
}
|
|
|
|
|
|
Context.SwapBuffers();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region OnUpdateFrame
|
|
|
|
public override void OnUpdateFrame()
|
|
{
|
|
base.OnUpdateFrame();
|
|
|
|
if (Keyboard[0][OpenTK.Input.Keys.Escape])
|
|
{
|
|
this.Exit();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion --- Event Handlers ---
|
|
}
|
|
} |