Class GLControl
OpenGL-aware WinForms control. The WinForms designer will always call the default constructor. Inherit from this class and call one of its specialized constructors to enable antialiasing or custom GraphicsModes.
Inheritance
Implements
Inherited Members
Namespace: OpenTK
Assembly: OpenTK.GLControl.dll
Syntax
public class GLControl : UserControl, UnsafeNativeMethods.IOleControl, UnsafeNativeMethods.IOleObject, UnsafeNativeMethods.IOleInPlaceObject, UnsafeNativeMethods.IOleInPlaceActiveObject, UnsafeNativeMethods.IOleWindow, UnsafeNativeMethods.IViewObject, UnsafeNativeMethods.IViewObject2, UnsafeNativeMethods.IPersist, UnsafeNativeMethods.IPersistStreamInit, UnsafeNativeMethods.IPersistPropertyBag, UnsafeNativeMethods.IPersistStorage, UnsafeNativeMethods.IQuickActivate, ISupportOleDropSource, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IArrangedElement, IComponent, IDisposable, IContainerControl
Constructors
GLControl()
Constructs a new instance.
Declaration
public GLControl()
GLControl(GraphicsMode)
Constructs a new instance with the specified GraphicsMode.
Declaration
public GLControl(GraphicsMode mode)
Parameters
Type | Name | Description |
---|---|---|
GraphicsMode | mode | The OpenTK.Graphics.GraphicsMode of the control. |
GLControl(GraphicsMode, Int32, Int32, GraphicsContextFlags)
Constructs a new instance with the specified GraphicsMode.
Declaration
public GLControl(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
Parameters
Type | Name | Description |
---|---|---|
GraphicsMode | mode | The OpenTK.Graphics.GraphicsMode of the control. |
Int32 | major | The major version for the OpenGL GraphicsContext. |
Int32 | minor | The minor version for the OpenGL GraphicsContext. |
GraphicsContextFlags | flags | The GraphicsContextFlags for the OpenGL GraphicsContext. |
Properties
AspectRatio
Gets the aspect ratio of this GLControl.
Declaration
public float AspectRatio { get; }
Property Value
Type | Description |
---|---|
Single |
Context
Gets the IGraphicsContext
instance that is associated with the GLControl
.
The associated IGraphicsContext
is updated whenever the GLControl
handle is created or recreated.
When using multiple GLControl
s, ensure that Context
is current before performing any OpenGL operations.
MakeCurrent()
Declaration
[Browsable(false)]
public IGraphicsContext Context { get; }
Property Value
Type | Description |
---|---|
IGraphicsContext |
CreateParams
Gets the CreateParams
instance for this GLControl
Declaration
protected override CreateParams CreateParams { get; }
Property Value
Type | Description |
---|---|
CreateParams |
Overrides
GraphicsMode
Gets the GraphicsMode
of the IGraphicsContext
associated with
this GLControl
. If you wish to change GraphicsMode
, you must
destroy and recreate the GLControl
.
Declaration
public GraphicsMode GraphicsMode { get; }
Property Value
Type | Description |
---|---|
GraphicsMode |
HasValidContext
Gets a value indicating whether [failed to create OpenGL context]. So that the application stays running and is able to recover.
Declaration
public bool HasValidContext { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
IsIdle
Gets a value indicating whether the current thread contains pending system messages.
Declaration
[Browsable(false)]
public bool IsIdle { get; }
Property Value
Type | Description |
---|---|
Boolean |
VSync
Gets or sets a value indicating whether vsync is active for this GLControl
.
When using multiple GLControl
s, ensure that Context
is current before accessing this property.
Context
MakeCurrent()
Declaration
public bool VSync { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
WindowInfo
Gets the IWindowInfo for this instance.
Declaration
public IWindowInfo WindowInfo { get; }
Property Value
Type | Description |
---|---|
IWindowInfo |
Methods
Dispose(Boolean)
Clean up any resources being used.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing | true if managed resources should be disposed; otherwise, false. |
Overrides
MakeCurrent()
Makes Context current in the calling thread. All OpenGL commands issued are hereafter interpreted by this context.
When using multiple GLControl
s, calling MakeCurrent
on
one control will make all other controls non-current in the calling thread.
A GLControl
can only be current in one thread at a time.
To make a control non-current, call GLControl.Context.MakeCurrent(null)
.
Declaration
public void MakeCurrent()
OnHandleCreated(EventArgs)
Raises the HandleCreated event.
Declaration
protected override void OnHandleCreated(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
Overrides
OnHandleDestroyed(EventArgs)
Raises the HandleDestroyed event.
Declaration
protected override void OnHandleDestroyed(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | Not used. |
Overrides
OnPaint(PaintEventArgs)
Raises the System.Windows.Forms.Control.Paint event.
Declaration
protected override void OnPaint(PaintEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
PaintEventArgs | e | A System.Windows.Forms.PaintEventArgs that contains the event data. |
Overrides
OnParentChanged(EventArgs)
Raises the ParentChanged event.
Declaration
protected override void OnParentChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | A System.EventArgs that contains the event data. |
Overrides
OnResize(EventArgs)
Raises the Resize event. Note: this method may be called before the OpenGL context is ready. Check that IsHandleCreated is true before using any OpenGL methods.
Declaration
protected override void OnResize(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
EventArgs | e | A System.EventArgs that contains the event data. |
Overrides
PerformContextUpdate()
Execute the delayed context update
Declaration
public void PerformContextUpdate()
SwapBuffers()
Swaps the front and back buffers, presenting the rendered scene to the screen.
This method will have no effect on a single-buffered GraphicsMode
.
Declaration
public void SwapBuffers()