C# Class OpenTK.GameWindow

The GameWindow class contains cross-platform methods to create and render on an OpenGL window, handle input and load resources.
GameWindow contains several events you can hook or override to add your custom logic: OnLoad: Occurs after creating the OpenGL context, but before entering the main loop. Override to load resources. OnUnload: Occurs after exiting the main loop, but before deleting the OpenGL context. Override to unload resources. OnResize: Occurs whenever GameWindow is resized. You should update the OpenGL Viewport and Projection Matrix here. OnUpdateFrame: Occurs at the specified logic update rate. Override to add your game logic. OnRenderFrame: Occurs at the specified frame render rate. Override to add your rendering code. Call the Run() method to start the application's main loop. Run(double, double) takes two parameters that specify the logic update rate, and the render update rate.
Inheritance: NativeWindow, IGameWindow, IDisposable
Datei anzeigen Open project: andykorth/opentk Class Usage Examples

Public Methods

Method Description
Dispose ( ) : void

Disposes of the GameWindow, releasing all resources consumed by it.

Exit ( ) : void

Closes the GameWindow. Equivalent to NativeWindow.Close method.

Override if you are not using GameWindow.Run().

If you override this method, place a call to base.Exit(), to ensure proper OpenTK shutdown.

GameWindow ( ) : System

Constructs a new GameWindow with sensible default attributes.

GameWindow ( int width, int height ) : System

Constructs a new GameWindow with the specified attributes.

GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode ) : System

Constructs a new GameWindow with the specified attributes.

GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode, string title ) : System

Constructs a new GameWindow with the specified attributes.

GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options ) : System

Constructs a new GameWindow with the specified attributes.

GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device ) : System

Constructs a new GameWindow with the specified attributes.

GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device, int major, int minor, GraphicsContextFlags flags ) : System

Constructs a new GameWindow with the specified attributes.

GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device, int major, int minor, GraphicsContextFlags flags, IGraphicsContext sharedContext ) : System

Constructs a new GameWindow with the specified attributes.

MakeCurrent ( ) : void

Makes the GraphicsContext current on the calling thread.

Run ( ) : void

Enters the game loop of the GameWindow using the maximum update rate.

Run ( double updateRate ) : void

Enters the game loop of the GameWindow using the specified update rate. maximum possible render frequency.

Run ( double updates_per_second, double frames_per_second ) : void

Enters the game loop of the GameWindow updating and rendering at the specified frequency.

When overriding the default game loop you should call ProcessEvents() to ensure that your GameWindow responds to operating system events.

Once ProcessEvents() returns, it is time to call update and render the next frame.

SwapBuffers ( ) : void

Swaps the front and back buffer, presenting the rendered scene to the user.

Protected Methods

Method Description
Dispose ( bool manual ) : void

Override to add custom cleanup logic.

OnClosing ( System e ) : void

Called when the NativeWindow is about to close.

OnLoad ( EventArgs e ) : void

Called after an OpenGL context has been established, but before entering the main loop.

OnRenderFrame ( FrameEventArgs e ) : void

Called when the frame is rendered.

Subscribe to the RenderFrame event instead of overriding this method.

OnResize ( EventArgs e ) : void

Called when this window is resized.

You will typically wish to update your viewport whenever the window is resized. See the OpenTK.Graphics.OpenGL.GL.Viewport(int, int, int, int) method.

OnUnload ( EventArgs e ) : void

Called after GameWindow.Exit was called, but before destroying the OpenGL context.

OnUpdateFrame ( FrameEventArgs e ) : void

Called when the frame is updated.

Subscribe to the UpdateFrame event instead of overriding this method.

OnWindowInfoChanged ( EventArgs e ) : void

Called when the WindowInfo for this GameWindow has changed.

Private Methods

Method Description
DispatchUpdateAndRenderFrame ( object sender, EventArgs e ) : void
OnLoadInternal ( EventArgs e ) : void
OnRenderFrameInternal ( FrameEventArgs e ) : void
OnUnloadInternal ( EventArgs e ) : void
OnUpdateFrameInternal ( FrameEventArgs e ) : void
OnWindowInfoChangedInternal ( EventArgs e ) : void
RaiseRenderFrame ( Stopwatch render_watch, double &next_render, FrameEventArgs render_args ) : void
RaiseUpdateFrame ( Stopwatch update_watch, double &next_update, FrameEventArgs update_args ) : void

Method Details

Dispose() public method

Disposes of the GameWindow, releasing all resources consumed by it.
public Dispose ( ) : void
return void

Dispose() protected method

Override to add custom cleanup logic.
protected Dispose ( bool manual ) : void
manual bool True, if this method was called by the application; false if this was called by the finalizer thread.
return void

Exit() public method

Closes the GameWindow. Equivalent to NativeWindow.Close method.

Override if you are not using GameWindow.Run().

If you override this method, place a call to base.Exit(), to ensure proper OpenTK shutdown.

public Exit ( ) : void
return void

GameWindow() public method

Constructs a new GameWindow with sensible default attributes.
public GameWindow ( ) : System
return System

GameWindow() public method

Constructs a new GameWindow with the specified attributes.
public GameWindow ( int width, int height ) : System
width int The width of the GameWindow in pixels.
height int The height of the GameWindow in pixels.
return System

GameWindow() public method

Constructs a new GameWindow with the specified attributes.
public GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode ) : System
width int The width of the GameWindow in pixels.
height int The height of the GameWindow in pixels.
mode OpenTK.Graphics.GraphicsMode The OpenTK.Graphics.GraphicsMode of the GameWindow.
return System

GameWindow() public method

Constructs a new GameWindow with the specified attributes.
public GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode, string title ) : System
width int The width of the GameWindow in pixels.
height int The height of the GameWindow in pixels.
mode OpenTK.Graphics.GraphicsMode The OpenTK.Graphics.GraphicsMode of the GameWindow.
title string The title of the GameWindow.
return System

GameWindow() public method

Constructs a new GameWindow with the specified attributes.
public GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options ) : System
width int The width of the GameWindow in pixels.
height int The height of the GameWindow in pixels.
mode OpenTK.Graphics.GraphicsMode The OpenTK.Graphics.GraphicsMode of the GameWindow.
title string The title of the GameWindow.
options GameWindowFlags GameWindow options regarding window appearance and behavior.
return System

GameWindow() public method

Constructs a new GameWindow with the specified attributes.
public GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device ) : System
width int The width of the GameWindow in pixels.
height int The height of the GameWindow in pixels.
mode OpenTK.Graphics.GraphicsMode The OpenTK.Graphics.GraphicsMode of the GameWindow.
title string The title of the GameWindow.
options GameWindowFlags GameWindow options regarding window appearance and behavior.
device DisplayDevice The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.
return System

GameWindow() public method

Constructs a new GameWindow with the specified attributes.
public GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device, int major, int minor, GraphicsContextFlags flags ) : System
width int The width of the GameWindow in pixels.
height int The height of the GameWindow in pixels.
mode OpenTK.Graphics.GraphicsMode The OpenTK.Graphics.GraphicsMode of the GameWindow.
title string The title of the GameWindow.
options GameWindowFlags GameWindow options regarding window appearance and behavior.
device DisplayDevice The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.
major int The major version for the OpenGL GraphicsContext.
minor int The minor version for the OpenGL GraphicsContext.
flags GraphicsContextFlags The GraphicsContextFlags version for the OpenGL GraphicsContext.
return System

GameWindow() public method

Constructs a new GameWindow with the specified attributes.
public GameWindow ( int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device, int major, int minor, GraphicsContextFlags flags, IGraphicsContext sharedContext ) : System
width int The width of the GameWindow in pixels.
height int The height of the GameWindow in pixels.
mode OpenTK.Graphics.GraphicsMode The OpenTK.Graphics.GraphicsMode of the GameWindow.
title string The title of the GameWindow.
options GameWindowFlags GameWindow options regarding window appearance and behavior.
device DisplayDevice The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.
major int The major version for the OpenGL GraphicsContext.
minor int The minor version for the OpenGL GraphicsContext.
flags GraphicsContextFlags The GraphicsContextFlags version for the OpenGL GraphicsContext.
sharedContext IGraphicsContext An IGraphicsContext to share resources with.
return System

MakeCurrent() public method

Makes the GraphicsContext current on the calling thread.
public MakeCurrent ( ) : void
return void

OnClosing() protected method

Called when the NativeWindow is about to close.
protected OnClosing ( System e ) : void
e System /// The for this event. /// Set e.Cancel to true in order to stop the GameWindow from closing.
return void

OnLoad() protected method

Called after an OpenGL context has been established, but before entering the main loop.
protected OnLoad ( EventArgs e ) : void
e System.EventArgs Not used.
return void

OnRenderFrame() protected method

Called when the frame is rendered.
Subscribe to the RenderFrame event instead of overriding this method.
protected OnRenderFrame ( FrameEventArgs e ) : void
e FrameEventArgs Contains information necessary for frame rendering.
return void

OnResize() protected method

Called when this window is resized.
You will typically wish to update your viewport whenever the window is resized. See the OpenTK.Graphics.OpenGL.GL.Viewport(int, int, int, int) method.
protected OnResize ( EventArgs e ) : void
e System.EventArgs Not used.
return void

OnUnload() protected method

Called after GameWindow.Exit was called, but before destroying the OpenGL context.
protected OnUnload ( EventArgs e ) : void
e System.EventArgs Not used.
return void

OnUpdateFrame() protected method

Called when the frame is updated.
Subscribe to the UpdateFrame event instead of overriding this method.
protected OnUpdateFrame ( FrameEventArgs e ) : void
e FrameEventArgs Contains information necessary for frame updating.
return void

OnWindowInfoChanged() protected method

Called when the WindowInfo for this GameWindow has changed.
protected OnWindowInfoChanged ( EventArgs e ) : void
e System.EventArgs Not used.
return void

Run() public method

Enters the game loop of the GameWindow using the maximum update rate.
public Run ( ) : void
return void

Run() public method

Enters the game loop of the GameWindow using the specified update rate. maximum possible render frequency.
public Run ( double updateRate ) : void
updateRate double
return void

Run() public method

Enters the game loop of the GameWindow updating and rendering at the specified frequency.
When overriding the default game loop you should call ProcessEvents() to ensure that your GameWindow responds to operating system events.

Once ProcessEvents() returns, it is time to call update and render the next frame.

public Run ( double updates_per_second, double frames_per_second ) : void
updates_per_second double The frequency of UpdateFrame events.
frames_per_second double The frequency of RenderFrame events.
return void

SwapBuffers() public method

Swaps the front and back buffer, presenting the rendered scene to the user.
public SwapBuffers ( ) : void
return void