This commit is contained in:
parent
d9b0ac6e5c
commit
71e3074bea
7 changed files with 1688 additions and 14 deletions
|
@ -29,12 +29,6 @@ namespace OpenTK.Examples.OpenGL.GLSL
|
|||
|
||||
static float angle;
|
||||
|
||||
#region Constructor
|
||||
public Cube()
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Load event handler
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
|
@ -74,7 +68,7 @@ namespace OpenTK.Examples.OpenGL.GLSL
|
|||
GL.LinkProgram(shader_program);
|
||||
GL.UseProgram(shader_program);
|
||||
|
||||
//OnResize(e);
|
||||
OnResize(e);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -85,7 +79,7 @@ namespace OpenTK.Examples.OpenGL.GLSL
|
|||
|
||||
if (ClientSize.Height == 0)
|
||||
ClientSize = new System.Drawing.Size(ClientSize.Width, 1);
|
||||
|
||||
|
||||
GL.Viewport(0, 0, ClientSize.Width, ClientSize.Height);
|
||||
|
||||
double ratio = 0.0;
|
||||
|
@ -97,7 +91,6 @@ namespace OpenTK.Examples.OpenGL.GLSL
|
|||
|
||||
GL.MatrixMode(Enums.MatrixMode.PROJECTION);
|
||||
GL.LoadIdentity();
|
||||
|
||||
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
||||
}
|
||||
#endregion
|
||||
|
@ -122,6 +115,7 @@ namespace OpenTK.Examples.OpenGL.GLSL
|
|||
DrawCube();
|
||||
|
||||
Context.SwapBuffers();
|
||||
this.Invalidate();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -189,7 +183,14 @@ namespace OpenTK.Examples.OpenGL.GLSL
|
|||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Cube());
|
||||
try
|
||||
{
|
||||
Application.Run(new Cube());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.ToString());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
1443
Source/OpenGL/OpenGL/Bindings/GLContextLoad.cs
Normal file
1443
Source/OpenGL/OpenGL/Bindings/GLContextLoad.cs
Normal file
File diff suppressed because it is too large
Load diff
62
Source/OpenGL/OpenGL/Contexts/GLContext.cs
Normal file
62
Source/OpenGL/OpenGL/Contexts/GLContext.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
#region License
|
||||
/* Copyright (c) 2006 Stephen Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using OpenTK.OpenGL.Platform;
|
||||
|
||||
namespace OpenTK.OpenGL
|
||||
{
|
||||
public abstract partial class GLContext : IDisposable
|
||||
{
|
||||
#region Created property
|
||||
private bool _created = false;
|
||||
|
||||
public bool Created
|
||||
{
|
||||
get { return _created; }
|
||||
set { _created = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
public abstract void SwapBuffers();
|
||||
public abstract System.Delegate GetAddress(string function_string, Type function_type);
|
||||
public abstract void MakeCurrent();
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
public static GLContext Create(Control c, int red, int green, int blue, int alpha, int depth, int stencil)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major < 6 ||
|
||||
Environment.OSVersion.Platform == PlatformID.Win32Windows)
|
||||
{
|
||||
return new WindowsContext(c, red, green, blue, alpha, depth, stencil);
|
||||
}
|
||||
else if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6)
|
||||
{
|
||||
return new WindowsVistaContext(c, red, green, blue, alpha, depth, stencil);
|
||||
}
|
||||
else if (Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
{
|
||||
return new X11Context(c, red, green, blue, alpha, depth, stencil);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PlatformNotSupportedException("The platform on which you are trying to run this program is not currently supported. Sorry for the inconvenience.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
156
Source/OpenGL/OpenGL/Forms/GLForm.cs
Normal file
156
Source/OpenGL/OpenGL/Forms/GLForm.cs
Normal file
|
@ -0,0 +1,156 @@
|
|||
#region License
|
||||
/* Copyright (c) 2006 Stephen Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
using OpenTK.Platform.Windows;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK.OpenGL
|
||||
{
|
||||
public class GLForm : Form, IDisposable
|
||||
{
|
||||
#region Context
|
||||
private GLContext _context;
|
||||
|
||||
public GLContext Context
|
||||
{
|
||||
get { return _context; }
|
||||
set { _context = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
public GLForm()
|
||||
{
|
||||
Open(null, 640, 480, 8, 8, 8, 8, 16, 0, false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Open(string title, int width, int height, int red, int green, int blue, int alpha, int depth, int stencil, bool fullscreen)
|
||||
{
|
||||
// Hack! Should add more constructors to the GLContext class.
|
||||
Context = GLContext.Create(this, 8, 8, 8, 8, 16, 0);
|
||||
|
||||
// Todo: Why doesn't this work?
|
||||
if (title == null)
|
||||
title = "OpenTK application";
|
||||
this.Text = title;
|
||||
|
||||
// Code taken from NeHe tutorials
|
||||
this.CreateParams.Style |= (int)Api.WindowClassStyle.HRedraw | (int)Api.WindowClassStyle.VRedraw | (int)Api.WindowClassStyle.OwnDC;
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); // No Need To Erase Form Background
|
||||
this.SetStyle(ControlStyles.Opaque, true); // No Need To Draw Form Background
|
||||
//this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // Buffer Control
|
||||
//this.SetStyle(ControlStyles.ResizeRedraw, true); // Redraw On Resize
|
||||
this.SetStyle(ControlStyles.UserPaint, true); // We'll Handle Painting Ourselves
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
Api.DeviceMode ScreenSettings = new Api.DeviceMode(); // Device Mode
|
||||
ScreenSettings.Size = (short)Marshal.SizeOf(ScreenSettings); // Size Of The Devmode Structure
|
||||
ScreenSettings.PelsWidth = width; // Selected Screen Width
|
||||
ScreenSettings.PelsHeight = height; // Selected Screen Height
|
||||
ScreenSettings.BitsPerPel = red + green + blue + alpha; // Selected Bits Per Pixel
|
||||
ScreenSettings.Fields = Api.Constants.DM_BITSPERPEL | Api.Constants.DM_PELSWIDTH | Api.Constants.DM_PELSHEIGHT;
|
||||
|
||||
// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
|
||||
if (Api.ChangeDisplaySettings(ref ScreenSettings, Api.Constants.CDS_FULLSCREEN) == Api.Constants.DISP_CHANGE_SUCCESSFUL)
|
||||
{
|
||||
this.FormBorderStyle = FormBorderStyle.None;
|
||||
this.StartPosition = FormStartPosition.Manual;
|
||||
this.Location = new System.Drawing.Point(0, 0);
|
||||
this.Region = new Region(new Rectangle(0, 0, width, height));
|
||||
this.Capture = true;
|
||||
this.SetTopLevel(true);
|
||||
Cursor.Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle failure.
|
||||
}
|
||||
}
|
||||
|
||||
this.Size = new Size(width, height);
|
||||
|
||||
// Cross-platformness?
|
||||
Application.Idle += new EventHandler(OnApplicationIdle);
|
||||
}
|
||||
|
||||
#region Application main loop
|
||||
/// <summary>
|
||||
/// Called when all pending messages have been processed, this is where the application 'Main Loop' resides.
|
||||
/// </summary>
|
||||
/// <param name="sender">Not used.</param>
|
||||
/// <param name="e">Not used.</param>
|
||||
void OnApplicationIdle(object sender, EventArgs e)
|
||||
{
|
||||
// Check if any new messages have popped up. If not, then run the logic at full speed.
|
||||
//while (IsApplicationIdle())
|
||||
////while (idle)
|
||||
//{
|
||||
// // We'd like to play nice with the scheduler. If the window is not in focus,
|
||||
// // we give back some thread-time to the OS, to allow other apps to function full-speed.
|
||||
// // However, if the window _is_ in focus we grab all processor resources.
|
||||
// // Hack! Should allow the user to set a sleep interval.
|
||||
// if (ActiveForm != this)
|
||||
// Thread.Sleep(100);
|
||||
// OnPaint(null);
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if there all pending messages have been processed.
|
||||
/// </summary>
|
||||
/// <returns>Returns true if there are no messages left, false otherwise.</returns>
|
||||
static public bool IsApplicationIdle()
|
||||
{
|
||||
//Message msg = Message.Create(this.Handle, A
|
||||
|
||||
//try
|
||||
//{
|
||||
//Message msg;
|
||||
Api.Message msg;
|
||||
return !OpenTK.Platform.Windows.Api.PeekMessage(out msg, IntPtr.Zero, 0, 0, 0);
|
||||
//}
|
||||
//catch (Exception e)
|
||||
//{
|
||||
// //MessageBox.Show(e.ToString());
|
||||
// return false;
|
||||
//}
|
||||
//WndProc(ref msg);
|
||||
|
||||
//if (msg.
|
||||
//return false;
|
||||
|
||||
//Message msg = Message.Create(IntPtr.Zero, Api.Constants.WM_ENTERIDLE, IntPtr.Zero, IntPtr.Zero);
|
||||
|
||||
//return !Api.PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0);
|
||||
}
|
||||
#endregion
|
||||
|
||||
bool idle;
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
//OnPaint(null);
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
Application.Idle -= OnApplicationIdle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace OpenTK.Platform.Windows
|
|||
public const int WM_SYSKEYUP = 0x0105;
|
||||
public const int WM_COMMAND = 0x0111;
|
||||
public const int WM_SYSCOMMAND = 0x0112;
|
||||
public const int WM_ENTERIDLE = 0x121;
|
||||
|
||||
// Pixel types (found in WinGDI.h)
|
||||
public const byte PFD_TYPE_RGBA = 0;
|
||||
|
@ -62,6 +63,18 @@ namespace OpenTK.Platform.Windows
|
|||
#region WINAPI methods
|
||||
#region PeekMessage
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Message
|
||||
{
|
||||
public IntPtr hWnd;
|
||||
public int msg;
|
||||
public IntPtr wParam;
|
||||
public IntPtr lParam;
|
||||
public uint time;
|
||||
public System.Drawing.Point p;
|
||||
//System.Drawing.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Low-level WINAPI function that checks the next message in the queue.
|
||||
/// </summary>
|
||||
|
@ -73,8 +86,8 @@ namespace OpenTK.Platform.Windows
|
|||
/// <returns>True if there is a message pending.</returns>
|
||||
[System.Security.SuppressUnmanagedCodeSecurity]
|
||||
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern bool PeekMessage(out System.Windows.Forms.Message msg, IntPtr hWnd, uint messageFilterMin,
|
||||
uint messageFilterMax, uint flags);
|
||||
//public static extern bool PeekMessage(out System.Windows.Forms.Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
|
||||
public static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
..\..\..\..\..\Binaries\Debug\Libraries\OpenTK.Platform.Windows.dll
|
||||
..\..\..\..\..\Binaries\Debug\Libraries\OpenTK.Platform.Windows.pdb
|
Loading…
Reference in a new issue