mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 07:45:37 +00:00
Updates to fullscreen toggling for windows.
Added the ColorDepth, ZDepth and StencilDepth properties to the Framework. Merged Context creation for windows into a single file.
This commit is contained in:
parent
977a41059c
commit
f0f03d58db
|
@ -1,4 +1,10 @@
|
||||||
using System;
|
#region License
|
||||||
|
/* Copyright (c) 2006 Stephen Apostolopoulos
|
||||||
|
* See license.txt for license info
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
@ -110,6 +116,7 @@ namespace OpenTK.Examples.OpenGL.GLSL
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Paint event handler
|
#region Paint event handler
|
||||||
|
|
||||||
protected override void OnPaint(PaintEventArgs e)
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnPaint(e);
|
base.OnPaint(e);
|
||||||
|
@ -129,18 +136,28 @@ namespace OpenTK.Examples.OpenGL.GLSL
|
||||||
DrawCube();
|
DrawCube();
|
||||||
|
|
||||||
Context.SwapBuffers();
|
Context.SwapBuffers();
|
||||||
this.Invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region KeyDown event handler
|
#region KeyDown event handler
|
||||||
|
|
||||||
protected override void OnKeyDown(KeyEventArgs e)
|
protected override void OnKeyDown(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnKeyDown(e);
|
base.OnKeyDown(e);
|
||||||
|
|
||||||
if (e.KeyData == Keys.Escape)
|
switch (e.KeyData)
|
||||||
Application.Exit();
|
{
|
||||||
|
case Keys.Escape:
|
||||||
|
Application.Exit();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Keys.F1:
|
||||||
|
//this.Fullscreen = !this.Fullscreen;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DrawCube
|
#region DrawCube
|
||||||
|
|
|
@ -40,7 +40,43 @@ namespace OpenTK.Frameworks
|
||||||
public bool Fullscreen
|
public bool Fullscreen
|
||||||
{
|
{
|
||||||
get { return _fullscreen; }
|
get { return _fullscreen; }
|
||||||
set { _fullscreen = Implementation.ToggleFullscreen(_fullscreen); }
|
private set { _fullscreen = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ColorDepth property
|
||||||
|
|
||||||
|
private OpenTK.OpenGL.ColorDepth _color_depth;
|
||||||
|
|
||||||
|
public OpenTK.OpenGL.ColorDepth ColorDepth
|
||||||
|
{
|
||||||
|
get { return _color_depth; }
|
||||||
|
set { _color_depth = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ZDepth property
|
||||||
|
|
||||||
|
private int _z_depth;
|
||||||
|
|
||||||
|
public int ZDepth
|
||||||
|
{
|
||||||
|
get { return _z_depth; }
|
||||||
|
set { _z_depth = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region StencilDepth property
|
||||||
|
|
||||||
|
private int _stencil_depth;
|
||||||
|
|
||||||
|
public int StencilDepth
|
||||||
|
{
|
||||||
|
get { return _stencil_depth; }
|
||||||
|
set { _stencil_depth = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -77,18 +113,24 @@ namespace OpenTK.Frameworks
|
||||||
|
|
||||||
public Framework()
|
public Framework()
|
||||||
{
|
{
|
||||||
Setup(null, 640, 480, 8, 8, 8, 8, 16, 0, false);
|
Setup(null, 640, 480, new OpenTK.OpenGL.ColorDepth(8, 8, 8, 8), 16, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Framework(string title, int width, int height, int red, int green, int blue, int alpha, int depth, int stencil, bool fullscreen)
|
|
||||||
|
public Framework(string title, int width, int height, OpenTK.OpenGL.ColorDepth color, int depth, int stencil, bool fullscreen)
|
||||||
{
|
{
|
||||||
Setup(title, width, height, red, green, blue, alpha, depth, stencil, fullscreen);
|
Setup(title, width, height, color, depth, stencil, fullscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public void Setup(string title, int width, int height, int red, int green, int blue, int alpha, int depth, int stencil, bool fullscreen)
|
public void Setup(string title, int width, int height, OpenTK.OpenGL.ColorDepth color, int depth, int stencil, bool fullscreen)
|
||||||
{
|
{
|
||||||
|
// Initialise components.
|
||||||
|
ColorDepth = color;
|
||||||
|
ZDepth = depth;
|
||||||
|
StencilDepth = stencil;
|
||||||
|
|
||||||
// Set platform.
|
// Set platform.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -111,7 +153,6 @@ namespace OpenTK.Frameworks
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
Implementation.Setup();
|
|
||||||
this.HandleCreated += new EventHandler(Implementation.OnHandleCreated);
|
this.HandleCreated += new EventHandler(Implementation.OnHandleCreated);
|
||||||
|
|
||||||
//Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
//Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
||||||
|
@ -120,23 +161,26 @@ namespace OpenTK.Frameworks
|
||||||
// Context = GLContext.Create(this, 8, 8, 8, 8, 16, 0);
|
// Context = GLContext.Create(this, 8, 8, 8, 8, 16, 0);
|
||||||
// //Context.MakeCurrent();
|
// //Context.MakeCurrent();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
Context = GLContext.Create(this, red, green, blue, alpha, depth, stencil);
|
Context = GLContext.Create(this, color, depth, stencil);
|
||||||
|
|
||||||
// Code taken from NeHe tutorials
|
// Code taken from NeHe tutorials
|
||||||
this.CreateParams.Style |= (int)Api.WindowClassStyle.HRedraw | (int)Api.WindowClassStyle.VRedraw | (int)Api.WindowClassStyle.OwnDC;
|
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.AllPaintingInWmPaint, true); // No Need To Erase Form Background
|
||||||
this.SetStyle(ControlStyles.Opaque, true); // No Need To Draw Form Background
|
this.SetStyle(ControlStyles.Opaque, true); // No Need To Draw Form Background
|
||||||
//this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // Buffer Control
|
//this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // Buffer Control
|
||||||
//this.SetStyle(ControlStyles.ResizeRedraw, true); // Redraw On Resize
|
//this.SetStyle(ControlStyles.ResizeRedraw, true); // Redraw On Resize
|
||||||
this.SetStyle(ControlStyles.UserPaint, true); // We'll Handle Painting Ourselves
|
this.SetStyle(ControlStyles.UserPaint, true); // We'll Handle Painting Ourselves
|
||||||
|
|
||||||
|
this.Width = width;
|
||||||
|
this.Height = height;
|
||||||
|
|
||||||
|
Fullscreen = Implementation.ToggleFullscreen(fullscreen);
|
||||||
|
|
||||||
if (title == null)
|
if (title == null)
|
||||||
title = "OpenTK Windows application";
|
title = "OpenTK Windows application";
|
||||||
this.Text = title;
|
this.Text = title;
|
||||||
|
|
||||||
this.Size = new Size(width, height);
|
|
||||||
|
|
||||||
Application.Idle += new EventHandler(OnIdle);
|
Application.Idle += new EventHandler(OnIdle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
using System;
|
#region License
|
||||||
|
/* Copyright (c) 2006 Stephen Apostolopoulos
|
||||||
|
* See license.txt for license info
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace OpenTK.Frameworks
|
||||||
public WindowsImplementation(Framework f)
|
public WindowsImplementation(Framework f)
|
||||||
{
|
{
|
||||||
framework = f;
|
framework = f;
|
||||||
|
|
||||||
|
Setup();
|
||||||
// Set desktop resolution, refresh rate, pixel depth
|
// Set desktop resolution, refresh rate, pixel depth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,13 +54,22 @@ namespace OpenTK.Frameworks
|
||||||
{
|
{
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
{
|
{
|
||||||
Api.DeviceMode ScreenSettings = new Api.DeviceMode(); // Device Mode
|
Application.Idle -= framework.OnIdle;
|
||||||
|
//framework.Context.Dispose();
|
||||||
|
|
||||||
|
Api.DeviceMode ScreenSettings = new Api.DeviceMode(); // Device Mode
|
||||||
ScreenSettings.Size = (short)Marshal.SizeOf(ScreenSettings); // Size Of The Devmode Structure
|
ScreenSettings.Size = (short)Marshal.SizeOf(ScreenSettings); // Size Of The Devmode Structure
|
||||||
ScreenSettings.PelsWidth = 640;// width; // Selected Screen Width
|
ScreenSettings.PelsWidth = framework.Width; // Selected Screen Width
|
||||||
ScreenSettings.PelsHeight = 480;// height; // Selected Screen Height
|
ScreenSettings.PelsHeight = framework.Height; // Selected Screen Height
|
||||||
ScreenSettings.BitsPerPel = 32;// red + green + blue + alpha; // Selected Bits Per Pixel
|
ScreenSettings.BitsPerPel = framework.ColorDepth.Alpha + // Selected Bits Per Pixel
|
||||||
|
framework.ColorDepth.Red +
|
||||||
|
framework.ColorDepth.Green +
|
||||||
|
framework.ColorDepth.Blue;
|
||||||
ScreenSettings.Fields = Api.Constants.DM_BITSPERPEL | Api.Constants.DM_PELSWIDTH | Api.Constants.DM_PELSHEIGHT;
|
ScreenSettings.Fields = Api.Constants.DM_BITSPERPEL | Api.Constants.DM_PELSWIDTH | Api.Constants.DM_PELSHEIGHT;
|
||||||
|
|
||||||
|
//framework.Context = GLContext.Create(framework, framework.ColorDepth, 16, 0);
|
||||||
|
Application.Idle += framework.OnIdle;
|
||||||
|
|
||||||
// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
|
// 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)
|
if (Api.ChangeDisplaySettings(ref ScreenSettings, Api.Constants.CDS_FULLSCREEN) == Api.Constants.DISP_CHANGE_SUCCESSFUL)
|
||||||
{
|
{
|
||||||
|
@ -70,15 +81,15 @@ namespace OpenTK.Frameworks
|
||||||
framework.SetTopLevel(true);
|
framework.SetTopLevel(true);
|
||||||
Cursor.Hide();
|
Cursor.Hide();
|
||||||
|
|
||||||
return !fullscreen;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Handle failure.
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fullscreen;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -89,10 +89,6 @@ namespace OpenTK.OpenGL.Bind
|
||||||
sw.WriteLine(" static public partial class {0}", class_name);
|
sw.WriteLine(" static public partial class {0}", class_name);
|
||||||
sw.WriteLine(" {");
|
sw.WriteLine(" {");
|
||||||
|
|
||||||
sw.WriteLine(" static public void Init()");
|
|
||||||
sw.WriteLine(" {");
|
|
||||||
sw.WriteLine(" }");
|
|
||||||
|
|
||||||
WriteCoreFunctionSignatures(sw, functions);
|
WriteCoreFunctionSignatures(sw, functions);
|
||||||
WriteDllImports(sw, functions);
|
WriteDllImports(sw, functions);
|
||||||
WriteCoreFunctions(sw, functions);
|
WriteCoreFunctions(sw, functions);
|
||||||
|
|
|
@ -43,9 +43,6 @@ namespace OpenTK.OpenGL
|
||||||
{
|
{
|
||||||
static public partial class GL
|
static public partial class GL
|
||||||
{
|
{
|
||||||
static public void Init()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#region Function signatures
|
#region Function signatures
|
||||||
|
|
||||||
public static class Delegates
|
public static class Delegates
|
||||||
|
|
|
@ -30,13 +30,13 @@ namespace OpenTK.OpenGL
|
||||||
|
|
||||||
public abstract void Dispose();
|
public abstract void Dispose();
|
||||||
|
|
||||||
public static GLContext Create(Control c, int red, int green, int blue, int alpha, int depth, int stencil)
|
public static GLContext Create(Control c, ColorDepth color, int depth, int stencil)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT || Environment.OSVersion.Platform == PlatformID.Win32Windows)
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT || Environment.OSVersion.Platform == PlatformID.Win32Windows)
|
||||||
{
|
{
|
||||||
return new WindowsContext(c, red, green, blue, alpha, depth, stencil);
|
return new WindowsContext(c, color, depth, stencil);
|
||||||
}
|
}
|
||||||
//else if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6)
|
//else if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6)
|
||||||
//{
|
//{
|
||||||
|
@ -44,7 +44,7 @@ namespace OpenTK.OpenGL
|
||||||
//}
|
//}
|
||||||
else if (Environment.OSVersion.Platform == PlatformID.Unix)
|
else if (Environment.OSVersion.Platform == PlatformID.Unix)
|
||||||
{
|
{
|
||||||
return new X11Context(c, red, green, blue, alpha, depth, stencil);
|
return new X11Context(c, color, depth, stencil);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using OpenTK.OpenGL;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace OpenTK.OpenGL.Platform
|
|
||||||
{
|
|
||||||
public class WindowsBaseContext : GLContext
|
|
||||||
{
|
|
||||||
protected const string _dll_name = "OPENGL32.DLL";
|
|
||||||
protected int _dll_handle;
|
|
||||||
protected int _device_context;
|
|
||||||
protected int _render_context;
|
|
||||||
protected IntPtr _window_handle;
|
|
||||||
|
|
||||||
public override void SwapBuffers()
|
|
||||||
{
|
|
||||||
OpenTK.Platform.Windows.Api.SwapBuffers(_device_context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Delegate GetAddress(string function_string, Type function_type)
|
|
||||||
{
|
|
||||||
IntPtr address = Wgl.GetProcAddress(function_string);
|
|
||||||
if (address == IntPtr.Zero)
|
|
||||||
return null;
|
|
||||||
else
|
|
||||||
return Marshal.GetDelegateForFunctionPointer(address, function_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void MakeCurrent()
|
|
||||||
{
|
|
||||||
Wgl.MakeCurrent(_device_context, _render_context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose()
|
|
||||||
{
|
|
||||||
if (_render_context != 0)
|
|
||||||
Wgl.DeleteContext(_render_context);
|
|
||||||
|
|
||||||
if (_device_context != 0)
|
|
||||||
OpenTK.Platform.Windows.Api.ReleaseDC(_window_handle.ToInt32(), _device_context);
|
|
||||||
|
|
||||||
if (_dll_handle != 0)
|
|
||||||
OpenTK.Platform.Windows.Api.FreeLibrary(_dll_handle);
|
|
||||||
|
|
||||||
_render_context = 0;
|
|
||||||
_device_context = 0;
|
|
||||||
_dll_handle = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
#region License
|
#region License
|
||||||
/* Copyright (c) 2006 Stephen Apostolopoulos
|
/* Copyright (c) 2006 Stephen Apostolopoulos
|
||||||
* See license.txt for license info
|
* See license.txt for license info
|
||||||
*/
|
*/
|
||||||
|
@ -7,15 +7,20 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
|
||||||
using OpenTK.OpenGL;
|
using OpenTK.OpenGL;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace OpenTK.OpenGL.Platform
|
namespace OpenTK.OpenGL.Platform
|
||||||
{
|
{
|
||||||
public partial class WindowsContext : WindowsBaseContext
|
public class WindowsContext : GLContext
|
||||||
{
|
{
|
||||||
public WindowsContext(Control c, int red, int green, int blue, int alpha, int depth, int stencil)
|
protected const string _dll_name = "OPENGL32.DLL";
|
||||||
|
protected int _dll_handle;
|
||||||
|
protected int _device_context;
|
||||||
|
protected int _render_context;
|
||||||
|
protected IntPtr _window_handle;
|
||||||
|
|
||||||
|
public WindowsContext(System.Windows.Forms.Control c, ColorDepth color, int depth, int stencil)
|
||||||
{
|
{
|
||||||
int error_code = 0;
|
int error_code = 0;
|
||||||
_window_handle = c.Handle;
|
_window_handle = c.Handle;
|
||||||
|
@ -39,11 +44,11 @@ namespace OpenTK.OpenGL.Platform
|
||||||
_device_context = OpenTK.Platform.Windows.Api.GetDC(_window_handle.ToInt32());
|
_device_context = OpenTK.Platform.Windows.Api.GetDC(_window_handle.ToInt32());
|
||||||
OpenTK.Platform.Windows.Api.PixelFormatDescriptor pixel_format = new OpenTK.Platform.Windows.Api.PixelFormatDescriptor();
|
OpenTK.Platform.Windows.Api.PixelFormatDescriptor pixel_format = new OpenTK.Platform.Windows.Api.PixelFormatDescriptor();
|
||||||
|
|
||||||
pixel_format.ColorBits = (byte)(red + green + blue);
|
pixel_format.ColorBits = (byte)(color.Red + color.Green + color.Blue);
|
||||||
pixel_format.RedBits = (byte)red;
|
pixel_format.RedBits = (byte)color.Red;
|
||||||
pixel_format.GreenBits = (byte)green;
|
pixel_format.GreenBits = (byte)color.Green;
|
||||||
pixel_format.BlueBits = (byte)blue;
|
pixel_format.BlueBits = (byte)color.Blue;
|
||||||
pixel_format.AlphaBits = (byte)alpha;
|
pixel_format.AlphaBits = (byte)color.Alpha;
|
||||||
|
|
||||||
pixel_format.DepthBits = (byte)depth;
|
pixel_format.DepthBits = (byte)depth;
|
||||||
pixel_format.StencilBits = (byte)stencil;
|
pixel_format.StencilBits = (byte)stencil;
|
||||||
|
@ -95,5 +100,40 @@ namespace OpenTK.OpenGL.Platform
|
||||||
//if (load_extensions)
|
//if (load_extensions)
|
||||||
// LoadExtensions();
|
// LoadExtensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void SwapBuffers()
|
||||||
|
{
|
||||||
|
OpenTK.Platform.Windows.Api.SwapBuffers(_device_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Delegate GetAddress(string function_string, Type function_type)
|
||||||
|
{
|
||||||
|
IntPtr address = Wgl.GetProcAddress(function_string);
|
||||||
|
if (address == IntPtr.Zero)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return Marshal.GetDelegateForFunctionPointer(address, function_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void MakeCurrent()
|
||||||
|
{
|
||||||
|
Wgl.MakeCurrent(_device_context, _render_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
if (_render_context != 0)
|
||||||
|
Wgl.DeleteContext(_render_context);
|
||||||
|
|
||||||
|
if (_device_context != 0)
|
||||||
|
OpenTK.Platform.Windows.Api.ReleaseDC(_window_handle.ToInt32(), _device_context);
|
||||||
|
|
||||||
|
if (_dll_handle != 0)
|
||||||
|
OpenTK.Platform.Windows.Api.FreeLibrary(_dll_handle);
|
||||||
|
|
||||||
|
_render_context = 0;
|
||||||
|
_device_context = 0;
|
||||||
|
_dll_handle = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
/* Copyright (c) 2006 Stephen Apostolopoulos
|
|
||||||
* See license.txt for license info
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using OpenTK.OpenGL;
|
|
||||||
|
|
||||||
namespace OpenTK.OpenGL.Platform
|
|
||||||
{
|
|
||||||
public partial class WindowsVistaContext : WindowsBaseContext
|
|
||||||
{
|
|
||||||
public WindowsVistaContext(Control c, int red, int green, int blue, int alpha, int depth, int stencil)
|
|
||||||
{
|
|
||||||
int error_code = 0;
|
|
||||||
_window_handle = c.Handle;
|
|
||||||
|
|
||||||
// Dynamically load the OpenGL32.dll in order to use the extension loading capabilities of Wgl.
|
|
||||||
if (_dll_handle == 0)
|
|
||||||
{
|
|
||||||
_dll_handle = OpenTK.Platform.Windows.Api.LoadLibrary(_dll_name);
|
|
||||||
|
|
||||||
error_code = Marshal.GetLastWin32Error();
|
|
||||||
if (error_code != 0)
|
|
||||||
{
|
|
||||||
Console.WriteLine("LoadLibrary({0}) set error code: {1}. Will not load extensions.", _dll_name, error_code);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Loaded dll: {0}", _dll_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_device_context = OpenTK.Platform.Windows.Api.GetDC(_window_handle.ToInt32());
|
|
||||||
OpenTK.Platform.Windows.Api.PixelFormatDescriptor pixel_format = new OpenTK.Platform.Windows.Api.PixelFormatDescriptor();
|
|
||||||
|
|
||||||
pixel_format.ColorBits = (byte)(red + green + blue);
|
|
||||||
pixel_format.RedBits = (byte)red;
|
|
||||||
pixel_format.GreenBits = (byte)green;
|
|
||||||
pixel_format.BlueBits = (byte)blue;
|
|
||||||
pixel_format.AlphaBits = (byte)alpha;
|
|
||||||
|
|
||||||
pixel_format.DepthBits = (byte)depth;
|
|
||||||
pixel_format.StencilBits = (byte)stencil;
|
|
||||||
|
|
||||||
/*
|
|
||||||
pixel_format.AccumBits = (byte)(AccumRed + AccumGreen + AccumBlue);
|
|
||||||
pixel_format.AccumRedBits = (byte)AccumRed;
|
|
||||||
pixel_format.AccumGreenBits = (byte)AccumGreen;
|
|
||||||
pixel_format.AccumBlueBits = (byte)AccumBlue;
|
|
||||||
pixel_format.AccumAlphaBits = (byte)AccumAlpha;
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (depth <= 0)
|
|
||||||
{
|
|
||||||
pixel_format.Flags |= OpenTK.Platform.Windows.Api.PixelFormatDescriptorFlags.DEPTH_DONTCARE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (Stereo)
|
|
||||||
{
|
|
||||||
pixel_format.Flags |= OpenTK.Platform.Windows.Api.PixelFormatDescriptorFlags.STEREO;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (DoubleBuffer)
|
|
||||||
{
|
|
||||||
pixel_format.Flags |= OpenTK.Platform.Windows.Api.PixelFormatDescriptorFlags.DOUBLEBUFFER;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
int pixel = OpenTK.Platform.Windows.Api.ChoosePixelFormat(_device_context, pixel_format);
|
|
||||||
|
|
||||||
if (pixel == 0)
|
|
||||||
{
|
|
||||||
// "The pixel format requested is not supported by the hardware configuration."
|
|
||||||
throw new Exception("Pixel format not supported.");
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenTK.Platform.Windows.Api.SetPixelFormat(_device_context, pixel, pixel_format);
|
|
||||||
|
|
||||||
_render_context = Wgl.CreateContext(_device_context);
|
|
||||||
|
|
||||||
MakeCurrent();
|
|
||||||
|
|
||||||
//GL.Init();
|
|
||||||
//new GL();
|
|
||||||
|
|
||||||
//if (load_extensions)
|
|
||||||
// LoadExtensions();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,7 +22,7 @@ namespace OpenTK.OpenGL.Platform
|
||||||
private IntPtr display;
|
private IntPtr display;
|
||||||
const string _dll_name = "libGL.so.1";
|
const string _dll_name = "libGL.so.1";
|
||||||
|
|
||||||
public X11Context(Control c, int red, int green, int blue, int alpha, int depth, int stencil)
|
public X11Context(Control c, ColorDepth color, int depth, int stencil)
|
||||||
{
|
{
|
||||||
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
||||||
if (xplatui != null)
|
if (xplatui != null)
|
||||||
|
|
|
@ -54,16 +54,13 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Bindings\GL.cs" />
|
<Compile Include="Bindings\GL.cs" />
|
||||||
<Compile Include="Bindings\GLEnums.cs" />
|
<Compile Include="Bindings\GLEnums.cs" />
|
||||||
<Compile Include="Contexts\WindowsBaseContext.cs" />
|
<Compile Include="Contexts\WindowsContext.cs" />
|
||||||
<Compile Include="Contexts\WindowsVistaContext.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="GL.cs" />
|
<Compile Include="GL.cs" />
|
||||||
<Compile Include="Glu.cs" />
|
<Compile Include="Glu.cs" />
|
||||||
<Compile Include="Contexts\GLContext.cs" />
|
<Compile Include="Contexts\GLContext.cs" />
|
||||||
<Compile Include="Contexts\WindowsContext.cs" />
|
|
||||||
<Compile Include="Contexts\X11Context.cs" />
|
<Compile Include="Contexts\X11Context.cs" />
|
||||||
<Compile Include="Glx.cs" />
|
<Compile Include="Glx.cs" />
|
||||||
|
<Compile Include="Structures.cs" />
|
||||||
<Compile Include="Wgl.cs" />
|
<Compile Include="Wgl.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
27
Source/OpenGL/OpenGL/Structures.cs
Normal file
27
Source/OpenGL/OpenGL/Structures.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#region License
|
||||||
|
/* Copyright (c) 2006 Stephen Apostolopoulos
|
||||||
|
* See license.txt for license info
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace OpenTK.OpenGL
|
||||||
|
{
|
||||||
|
#region ColorDepth struct
|
||||||
|
|
||||||
|
public struct ColorDepth
|
||||||
|
{
|
||||||
|
public ColorDepth(byte red, byte green, byte blue, byte alpha)
|
||||||
|
{
|
||||||
|
Red = red;
|
||||||
|
Green = green;
|
||||||
|
Blue = blue;
|
||||||
|
Alpha = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte Red, Green, Blue, Alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
Loading…
Reference in a new issue