mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-12 08:35:38 +00:00
Updated all examples. Added documentation and generally cleaned them up.
This commit is contained in:
parent
73903b3865
commit
8a3ad855b0
|
@ -8,14 +8,14 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using OpenTK;
|
|
||||||
using OpenTK.OpenGL;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
using OpenTK;
|
||||||
|
using OpenTK.OpenGL;
|
||||||
|
|
||||||
namespace Examples.Tests
|
namespace Examples.Tests
|
||||||
{
|
{
|
||||||
public class S02_RawInput_Logger : GameWindow//, IExample
|
public class S02_RawInput_Logger : GameWindow//, IExample
|
||||||
|
@ -61,23 +61,20 @@ namespace Examples.Tests
|
||||||
{
|
{
|
||||||
this.CreateWindow(new DisplayMode(100, 100));
|
this.CreateWindow(new DisplayMode(100, 100));
|
||||||
|
|
||||||
foreach (OpenTK.Input.Keyboard k in this.Keyboard)
|
Keyboard.KeyDown += new OpenTK.Input.KeyDownEvent(LogKeyDown);
|
||||||
{
|
Keyboard.KeyUp += new OpenTK.Input.KeyUpEvent(LogKeyUp);
|
||||||
k.KeyDown += new OpenTK.Input.KeyDownEvent(LogKeyDown);
|
|
||||||
k.KeyUp += new OpenTK.Input.KeyUpEvent(LogKeyUp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogKeyDown(object sender, OpenTK.Input.Key key)
|
void LogKeyDown(object sender, OpenTK.Input.Key key)
|
||||||
{
|
{
|
||||||
Trace.WriteLine(String.Format("OpenTK key {0} pressed on Keyboard: ({1}).",
|
Trace.WriteLine(String.Format("OpenTK key {0} pressed on Keyboard: ({1}).",
|
||||||
key, sender as OpenTK.Input.Keyboard));
|
key, sender as OpenTK.Input.KeyboardDevice));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogKeyUp(object sender, OpenTK.Input.Key key)
|
void LogKeyUp(object sender, OpenTK.Input.Key key)
|
||||||
{
|
{
|
||||||
Trace.WriteLine(String.Format("OpenTK key {0} released on Keyboard: ({1}).",
|
Trace.WriteLine(String.Format("OpenTK key {0} released on Keyboard: ({1}).",
|
||||||
key, sender as OpenTK.Input.Keyboard));
|
key, sender as OpenTK.Input.KeyboardDevice));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnLoad(EventArgs e)
|
public override void OnLoad(EventArgs e)
|
||||||
|
|
|
@ -22,119 +22,95 @@ namespace Examples.Tests
|
||||||
{
|
{
|
||||||
public partial class S04_Input_Logger : Form//, IExample
|
public partial class S04_Input_Logger : Form//, IExample
|
||||||
{
|
{
|
||||||
InputDriver driver;
|
Thread thread;
|
||||||
|
GameWindow hidden;
|
||||||
|
bool start;
|
||||||
Dictionary<IntPtr, ListBox> keyboardListBoxes = new Dictionary<IntPtr, ListBox>(4);
|
Dictionary<IntPtr, ListBox> keyboardListBoxes = new Dictionary<IntPtr, ListBox>(4);
|
||||||
|
|
||||||
public S04_Input_Logger()
|
public S04_Input_Logger()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
thread = new Thread(LaunchGameWindow);
|
||||||
|
thread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LaunchGameWindow()
|
||||||
|
{
|
||||||
|
hidden = new GameWindow();
|
||||||
|
hidden.Load += hidden_Load;
|
||||||
|
hidden.CreateWindow(new DisplayMode(30, 30), "OpenTK | Hidden input window");
|
||||||
|
hidden.Run(60.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hidden_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
start = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnLoad(EventArgs e)
|
protected override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnLoad(e);
|
base.OnLoad(e);
|
||||||
|
|
||||||
WindowInfo info = new WindowInfo(this);
|
while (!start)
|
||||||
driver = new InputDriver(info);
|
|
||||||
Trace.WriteLine(String.Format("Keyboard count: {0}", driver.Keyboard.Count));
|
|
||||||
Trace.WriteLine(String.Format("Mouse count: {0}", driver.Mouse.Count));
|
|
||||||
|
|
||||||
switch (driver.Keyboard.Count)
|
|
||||||
{
|
{
|
||||||
case 0:
|
Thread.Sleep(100);
|
||||||
Debug.Print("No keyboard present, or keyboard driver failed to load");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[0].DeviceID, listBox1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[0].DeviceID, listBox1);
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[1].DeviceID, listBox2);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[0].DeviceID, listBox1);
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[1].DeviceID, listBox2);
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[2].DeviceID, listBox3);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[0].DeviceID, listBox1);
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[1].DeviceID, listBox2);
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[2].DeviceID, listBox3);
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[3].DeviceID, listBox4);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Debug.Print("Only the first 4 keyboards will be shown in the keyboard logger.");
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[0].DeviceID, listBox1);
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[1].DeviceID, listBox2);
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[2].DeviceID, listBox3);
|
|
||||||
keyboardListBoxes.Add(driver.Keyboard[3].DeviceID, listBox4);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WindowInfo info = new WindowInfo(this);
|
||||||
|
|
||||||
|
keyboardListBoxes.Add(hidden.Keyboard.DeviceID, listBox1);
|
||||||
|
|
||||||
// Add available mice to the mouse input logger.
|
// Add available mice to the mouse input logger.
|
||||||
if (driver.Mouse.Count > 0)
|
ChooseMouse.Items.Add(String.Format("Mouse {0} ({1})", 0, hidden.Mouse.Description));
|
||||||
{
|
hidden.Mouse.ButtonDown += LogMouseButtonDown;
|
||||||
int i = 0;
|
hidden.Mouse.ButtonUp += LogMouseButtonUp;
|
||||||
foreach (Mouse m in driver.Mouse)
|
|
||||||
{
|
|
||||||
ChooseMouse.Items.Add(String.Format("Mouse {0} ({1})", ++i, m.Description));
|
|
||||||
m.ButtonDown += LogMouseButtonDown;
|
|
||||||
m.ButtonUp += LogMouseButtonUp;
|
|
||||||
}
|
|
||||||
ChooseMouse.SelectedIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (OpenTK.Input.Keyboard k in driver.Keyboard)
|
hidden.Keyboard.KeyDown += LogKeyDown;
|
||||||
{
|
hidden.Keyboard.KeyUp += LogKeyUp;
|
||||||
k.KeyDown += new KeyDownEvent(LogKeyDown);
|
|
||||||
k.KeyUp += new KeyUpEvent(LogKeyUp);
|
//Application.Idle += new EventHandler(UpdateDevices);
|
||||||
}
|
hidden.UpdateFrame += hidden_UpdateFrame;
|
||||||
|
|
||||||
Application.Idle += new EventHandler(UpdateDevices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateDevices(object sender, EventArgs e)
|
void hidden_UpdateFrame(object sender, UpdateFrameEventArgs e)
|
||||||
{
|
{
|
||||||
driver.Poll();
|
//hidden.Poll();
|
||||||
|
|
||||||
// Update mouse coordinates.
|
// Update mouse coordinates.
|
||||||
MouseXText.Text = driver.Mouse[ChooseMouse.SelectedIndex].X.ToString();
|
MouseXText.Text = hidden.Mouse.X.ToString();
|
||||||
MouseYText.Text = driver.Mouse[ChooseMouse.SelectedIndex].Y.ToString();
|
MouseYText.Text = hidden.Mouse.Y.ToString();
|
||||||
MouseDXText.Text = driver.Mouse[ChooseMouse.SelectedIndex].XDelta.ToString();
|
MouseDXText.Text = hidden.Mouse.XDelta.ToString();
|
||||||
MouseDYText.Text = driver.Mouse[ChooseMouse.SelectedIndex].YDelta.ToString();
|
MouseDYText.Text = hidden.Mouse.YDelta.ToString();
|
||||||
MouseWheelText.Text = driver.Mouse[ChooseMouse.SelectedIndex].Wheel.ToString();
|
MouseWheelText.Text = hidden.Mouse.Wheel.ToString();
|
||||||
//MouseWheelDelta.Text = driver.Mouse[ChooseMouse.SelectedIndex].WheelDelta.ToString();
|
//MouseWheelDelta.Text = driver.Mouse[ChooseMouse.SelectedIndex].WheelDelta.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogMouseButtonDown(IMouse sender, MouseButton button)
|
void LogMouseButtonDown(MouseDevice sender, MouseButton button)
|
||||||
{
|
{
|
||||||
//Trace.WriteLine(String.Format("Mouse button down: {0} on device: {1}", button, sender.DeviceID));
|
//Trace.WriteLine(String.Format("Mouse button down: {0} on device: {1}", button, sender.DeviceID));
|
||||||
if (sender.DeviceID == driver.Mouse[ChooseMouse.SelectedIndex].DeviceID)
|
if (sender.DeviceID == hidden.Mouse.DeviceID)
|
||||||
MouseButtons.Items.Add(button);
|
MouseButtons.Items.Add(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogMouseButtonUp(IMouse sender, MouseButton button)
|
void LogMouseButtonUp(MouseDevice sender, MouseButton button)
|
||||||
{
|
{
|
||||||
//Trace.WriteLine(String.Format("Mouse button up: {0} on device: {1}", button, sender.DeviceID));
|
//Trace.WriteLine(String.Format("Mouse button up: {0} on device: {1}", button, sender.DeviceID));
|
||||||
if (sender.DeviceID == driver.Mouse[ChooseMouse.SelectedIndex].DeviceID)
|
if (sender.DeviceID == hidden.Mouse.DeviceID)
|
||||||
MouseButtons.Items.Remove(button);
|
MouseButtons.Items.Remove(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogKeyDown(object sender, Key key)
|
void LogKeyDown(KeyboardDevice sender, Key key)
|
||||||
{
|
{
|
||||||
Trace.WriteLine(String.Format("Key down: {0} on device: {1}", key, (sender as Keyboard).DeviceID));
|
Trace.WriteLine(String.Format("Key down: {0} on device: {1}", key, (sender as KeyboardDevice).DeviceID));
|
||||||
keyboardListBoxes[(sender as Keyboard).DeviceID].Items.Add(key);
|
keyboardListBoxes[(sender as KeyboardDevice).DeviceID].Items.Add(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogKeyUp(object sender, Key key)
|
void LogKeyUp(KeyboardDevice sender, Key key)
|
||||||
{
|
{
|
||||||
Trace.WriteLine(String.Format("Key up: {0} on device: {1}", key, (sender as Keyboard).DeviceID));
|
Trace.WriteLine(String.Format("Key up: {0} on device: {1}", key, (sender as KeyboardDevice).DeviceID));
|
||||||
keyboardListBoxes[(sender as Keyboard).DeviceID].Items.Remove(key);
|
keyboardListBoxes[(sender as KeyboardDevice).DeviceID].Items.Remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IExample Members
|
#region IExample Members
|
||||||
|
|
|
@ -15,21 +15,39 @@ using OpenTK.OpenGL;
|
||||||
|
|
||||||
namespace Examples.Tutorial
|
namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Demonstrates the GameWindow class.
|
||||||
|
/// </summary>
|
||||||
public class T01_Simple_Window : GameWindow, IExample
|
public class T01_Simple_Window : GameWindow, IExample
|
||||||
{
|
{
|
||||||
public T01_Simple_Window()
|
public T01_Simple_Window()
|
||||||
{
|
{
|
||||||
this.CreateWindow(new DisplayMode(800, 600));
|
this.CreateWindow(new DisplayMode(800, 600), "OpenTK | Tutorial 1: Simple Window");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region OnLoad
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Load resources here.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e">Not used.</param>
|
||||||
|
public override void OnLoad(EventArgs e)
|
||||||
|
{
|
||||||
|
Trace.WriteLine(String.Format("OpenGL driver information: {0}, {1}, {2}",
|
||||||
|
GL.GetString(GL.Enums.StringName.RENDERER),
|
||||||
|
GL.GetString(GL.Enums.StringName.VENDOR),
|
||||||
|
GL.GetString(GL.Enums.StringName.VERSION)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region OnResize
|
#region OnResize
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Override the OnResize method to respond to window resize events.
|
/// Respond to resize events here.
|
||||||
/// Do not forget to call base.OnResize() so that event listeners
|
|
||||||
/// will be notified of window resize events!
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="e"></param>
|
/// <param name="e">Contains information on the new GameWindow size.</param>
|
||||||
|
/// <remarks>There is no need to call the base implementation.</remarks>
|
||||||
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
||||||
{
|
{
|
||||||
GL.Viewport(0, 0, e.Width, e.Height);
|
GL.Viewport(0, 0, e.Width, e.Height);
|
||||||
|
@ -43,14 +61,30 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region OnUpdateFrame
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add your game logic here.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e">Contains timing information.</param>
|
||||||
|
/// <remarks>There is no need to call the base implementation.</remarks>
|
||||||
|
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnUpdateFrame(e);
|
||||||
|
|
||||||
|
if (Keyboard[OpenTK.Input.Key.Escape])
|
||||||
|
this.Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region OnRenderFrame
|
#region OnRenderFrame
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Override the OnRenderFrame method to add your drawing code.
|
/// Add your game rendering code here.
|
||||||
/// Do not forget to call base.OnRenderFrame() so that event listeners
|
|
||||||
/// will be notified of frame rendering events!
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="e">Not used.</param>
|
/// <param name="e">Contains timing information.</param>
|
||||||
|
/// <remarks>There is no need to call the base implementation.</remarks>
|
||||||
public override void OnRenderFrame(RenderFrameEventArgs e)
|
public override void OnRenderFrame(RenderFrameEventArgs e)
|
||||||
{
|
{
|
||||||
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
|
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
|
||||||
|
@ -66,23 +100,17 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
GL.End();
|
GL.End();
|
||||||
|
|
||||||
Context.SwapBuffers();
|
this.SwapBuffers();
|
||||||
|
|
||||||
base.OnRenderFrame(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
|
||||||
{
|
|
||||||
base.OnUpdateFrame(e);
|
|
||||||
|
|
||||||
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
|
||||||
this.Exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IExample Members
|
#region IExample Members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Only used by the ExampleLauncher application, no need to add a Launch() method in your code.
|
||||||
|
/// Add a call to Run() in your Main() function instead.
|
||||||
|
/// </summary>
|
||||||
public void Launch()
|
public void Launch()
|
||||||
{
|
{
|
||||||
this.Run(30.0, 5.0);
|
this.Run(30.0, 5.0);
|
||||||
|
|
|
@ -80,14 +80,14 @@ namespace Examples.Tutorial
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
if (Keyboard[OpenTK.Input.Key.Escape])
|
||||||
{
|
{
|
||||||
this.Exit();
|
this.Exit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Keyboard[0][OpenTK.Input.Key.AltLeft] || Keyboard[0][OpenTK.Input.Key.AltRight]) &&
|
if ((Keyboard[OpenTK.Input.Key.AltLeft] || Keyboard[OpenTK.Input.Key.AltRight]) &&
|
||||||
Keyboard[0][OpenTK.Input.Key.Enter])
|
Keyboard[OpenTK.Input.Key.Enter])
|
||||||
{
|
{
|
||||||
Fullscreen = !Fullscreen;
|
Fullscreen = !Fullscreen;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,14 +87,14 @@ namespace Examples.Tutorial
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
if (Keyboard[OpenTK.Input.Key.Escape])
|
||||||
{
|
{
|
||||||
this.Exit();
|
this.Exit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Keyboard[0][OpenTK.Input.Key.AltLeft] || Keyboard[0][OpenTK.Input.Key.AltRight]) &&
|
if ((Keyboard[OpenTK.Input.Key.AltLeft] || Keyboard[OpenTK.Input.Key.AltRight]) &&
|
||||||
Keyboard[0][OpenTK.Input.Key.Enter])
|
Keyboard[OpenTK.Input.Key.Enter])
|
||||||
{
|
{
|
||||||
Fullscreen = !Fullscreen;
|
Fullscreen = !Fullscreen;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,9 @@ using Examples.Shapes;
|
||||||
|
|
||||||
namespace Examples.Tutorial
|
namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Demonstrates fixed-function OpenGL lighting. Tutorial is incomplete!
|
||||||
|
/// </summary>
|
||||||
class T04_Lit_Cube : GameWindow, IExample
|
class T04_Lit_Cube : GameWindow, IExample
|
||||||
{
|
{
|
||||||
float x_angle, zoom;
|
float x_angle, zoom;
|
||||||
|
@ -24,7 +27,7 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
public T04_Lit_Cube()
|
public T04_Lit_Cube()
|
||||||
{
|
{
|
||||||
this.CreateWindow(new DisplayMode(800, 600));
|
this.CreateWindow(new DisplayMode(800, 600), "OpenTK | Vertex Lighting example");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -37,7 +40,7 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
GL.ClearColor(Color.MidnightBlue);
|
GL.ClearColor(Color.MidnightBlue);
|
||||||
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
||||||
GL.Enable(GL.Enums.EnableCap.CULL_FACE);
|
//GL.Enable(GL.Enums.EnableCap.CULL_FACE);
|
||||||
|
|
||||||
GL.EnableClientState(GL.Enums.EnableCap.VERTEX_ARRAY);
|
GL.EnableClientState(GL.Enums.EnableCap.VERTEX_ARRAY);
|
||||||
GL.EnableClientState(GL.Enums.EnableCap.NORMAL_ARRAY);
|
GL.EnableClientState(GL.Enums.EnableCap.NORMAL_ARRAY);
|
||||||
|
@ -50,8 +53,8 @@ namespace Examples.Tutorial
|
||||||
GL.Lightv(GL.Enums.LightName.LIGHT0, GL.Enums.LightParameter.DIFFUSE, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
|
GL.Lightv(GL.Enums.LightName.LIGHT0, GL.Enums.LightParameter.DIFFUSE, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
|
||||||
GL.Lightv(GL.Enums.LightName.LIGHT0, GL.Enums.LightParameter.SPECULAR, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
|
GL.Lightv(GL.Enums.LightName.LIGHT0, GL.Enums.LightParameter.SPECULAR, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
|
||||||
GL.LightModelv(GL.Enums.LightModelParameter.LIGHT_MODEL_AMBIENT, new float[] { 0.2f, 0.2f, 0.2f, 1.0f });
|
GL.LightModelv(GL.Enums.LightModelParameter.LIGHT_MODEL_AMBIENT, new float[] { 0.2f, 0.2f, 0.2f, 1.0f });
|
||||||
GL.Enable(GL.Enums.EnableCap.LIGHTING);
|
//GL.Enable(GL.Enums.EnableCap.LIGHTING);
|
||||||
GL.Enable(GL.Enums.EnableCap.LIGHT0);
|
//GL.Enable(GL.Enums.EnableCap.LIGHT0);
|
||||||
|
|
||||||
// Use GL.Material to set your object's material parameters..
|
// Use GL.Material to set your object's material parameters..
|
||||||
GL.Materialv(GL.Enums.MaterialFace.FRONT, GL.Enums.MaterialParameter.AMBIENT, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });
|
GL.Materialv(GL.Enums.MaterialFace.FRONT, GL.Enums.MaterialParameter.AMBIENT, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });
|
||||||
|
@ -97,25 +100,25 @@ namespace Examples.Tutorial
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
if (Keyboard[OpenTK.Input.Key.Escape])
|
||||||
{
|
{
|
||||||
this.Exit();
|
this.Exit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Keyboard[0][OpenTK.Input.Key.AltLeft] || Keyboard[0][OpenTK.Input.Key.AltRight]) &&
|
if ((Keyboard[OpenTK.Input.Key.AltLeft] || Keyboard[OpenTK.Input.Key.AltRight]) &&
|
||||||
Keyboard[0][OpenTK.Input.Key.Enter])
|
Keyboard[OpenTK.Input.Key.Enter])
|
||||||
{
|
{
|
||||||
Fullscreen = !Fullscreen;
|
Fullscreen = !Fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Mouse[0][OpenTK.Input.MouseButton.Left])
|
if (Mouse[OpenTK.Input.MouseButton.Left])
|
||||||
x_angle += Mouse[0].XDelta * 2;
|
x_angle += Mouse.XDelta * 2;
|
||||||
else
|
else
|
||||||
x_angle += 0.5f;
|
x_angle += 0.5f;
|
||||||
|
|
||||||
if (Mouse[0][OpenTK.Input.MouseButton.Right])
|
if (Mouse[OpenTK.Input.MouseButton.Right])
|
||||||
zoom += Mouse[0].YDelta * 0.5f;
|
zoom += Mouse.YDelta * 0.5f;
|
||||||
|
|
||||||
if (x_angle > 720.0f)
|
if (x_angle > 720.0f)
|
||||||
x_angle -= 720.0f;
|
x_angle -= 720.0f;
|
||||||
|
@ -142,17 +145,10 @@ namespace Examples.Tutorial
|
||||||
0.0, 1.0, 0.0);
|
0.0, 1.0, 0.0);
|
||||||
GL.Rotate(x_angle, 0.0f, 1.0f, 0.0f);
|
GL.Rotate(x_angle, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
unsafe
|
GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, shape.Indices.Length,
|
||||||
{
|
GL.Enums.All.UNSIGNED_INT, shape.Indices);
|
||||||
fixed (int* ptr = shape.Indices)
|
|
||||||
{
|
|
||||||
GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, shape.Indices.Length,
|
|
||||||
GL.Enums.All.UNSIGNED_INT, ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GL.DrawArrays(GL.Enums.BeginMode.POINTS, 0, shape.Vertices.Length);
|
|
||||||
|
|
||||||
Context.SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -112,7 +112,7 @@ namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
base.OnUpdateFrame(e);
|
base.OnUpdateFrame(e);
|
||||||
|
|
||||||
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
if (Keyboard[OpenTK.Input.Key.Escape])
|
||||||
{
|
{
|
||||||
this.Exit();
|
this.Exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ namespace Examples.Tutorial
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
if (Keyboard[OpenTK.Input.Key.Escape])
|
||||||
{
|
{
|
||||||
this.Exit();
|
this.Exit();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -21,6 +21,9 @@ using OpenTK;
|
||||||
|
|
||||||
namespace Examples.Tutorial
|
namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Demonstrates how to load and use a simple OpenGL shader program.
|
||||||
|
/// </summary>
|
||||||
public class T10_GLSL_Cube : GameWindow, IExample
|
public class T10_GLSL_Cube : GameWindow, IExample
|
||||||
{
|
{
|
||||||
#region --- Fields ---
|
#region --- Fields ---
|
||||||
|
@ -55,7 +58,7 @@ void main()
|
||||||
|
|
||||||
public T10_GLSL_Cube()
|
public T10_GLSL_Cube()
|
||||||
{
|
{
|
||||||
this.CreateWindow(new DisplayMode(800, 600));
|
this.CreateWindow(new DisplayMode(800, 600), "OpenTK | GLSL Example 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -127,7 +130,7 @@ void main()
|
||||||
GL.LinkProgram(shader_program);
|
GL.LinkProgram(shader_program);
|
||||||
GL.UseProgram(shader_program);
|
GL.UseProgram(shader_program);
|
||||||
|
|
||||||
OnResize(new OpenTK.Platform.ResizeEventArgs(this.Width, this.Height));
|
//OnResize(new OpenTK.Platform.ResizeEventArgs(this.Width, this.Height));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -167,14 +170,14 @@ void main()
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
if (Keyboard[OpenTK.Input.Key.Escape])
|
||||||
{
|
{
|
||||||
this.Exit();
|
this.Exit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Keyboard[0][OpenTK.Input.Key.AltLeft] || Keyboard[0][OpenTK.Input.Key.AltRight]) &&
|
if ((Keyboard[OpenTK.Input.Key.AltLeft] || Keyboard[OpenTK.Input.Key.AltRight]) &&
|
||||||
Keyboard[0][OpenTK.Input.Key.Enter])
|
Keyboard[OpenTK.Input.Key.Enter])
|
||||||
{
|
{
|
||||||
Fullscreen = !Fullscreen;
|
Fullscreen = !Fullscreen;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue