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
Afficher le fichier Open project: andykorth/opentk Class Usage Examples

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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

Méthode 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 méthode

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

Dispose() protected méthode

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.
Résultat void

Exit() public méthode

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
Résultat void

GameWindow() public méthode

Constructs a new GameWindow with sensible default attributes.
public GameWindow ( ) : System
Résultat System

GameWindow() public méthode

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.
Résultat System

GameWindow() public méthode

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.
Résultat System

GameWindow() public méthode

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.
Résultat System

GameWindow() public méthode

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.
Résultat System

GameWindow() public méthode

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.
Résultat System

GameWindow() public méthode

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.
Résultat System

GameWindow() public méthode

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.
Résultat System

MakeCurrent() public méthode

Makes the GraphicsContext current on the calling thread.
public MakeCurrent ( ) : void
Résultat void

OnClosing() protected méthode

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.
Résultat void

OnLoad() protected méthode

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

OnRenderFrame() protected méthode

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.
Résultat void

OnResize() protected méthode

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.
Résultat void

OnUnload() protected méthode

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

OnUpdateFrame() protected méthode

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.
Résultat void

OnWindowInfoChanged() protected méthode

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

Run() public méthode

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

Run() public méthode

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

Run() public méthode

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.
Résultat void

SwapBuffers() public méthode

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