rakkarage's picture

overriding and calling base


OnLoad: this is the place to load resources from disk, like images or music.
OnUpdateFrame: this is a suitable place to handle input, update object positions, run physics or AI calculations.
OnRenderFrame: this contains the code that renders your graphics. It typically begins with a call to GL.Clear() and ends with a call to SwapBuffers.
OnResize: this method is called automatically whenever your game window changes size. Fullscreen applications will typically call it only once. Windowed applications may call it more often. In most circumstances, you can simply copy & paste the code from Game.cs.

the help at (http://www.opentk.net/doc/chapter/0) mentions these four methods to override and the quickstart uses them as well but does not call the base class OnLoad, OnUpdateFrame, OnRenderFrame, and OnResize

i guess it is not necessary to call those base class methods? thanks


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

It is not necessary in that your code will still work - the relevant events will simply not be raised (for example, the Resize event for the OnResize method).

This is not as bad as it sounds, since few applications will both override an On* method and hook the relevant event. Still, it's good practice to call the base method - fixed in SVN rev. 2328.

rakkarage's picture

a comment in GameWindow says

		//
		// Summary:
		//     Called when the frame is rendered.
		//
		// Parameters:
		//   e:
		//     Contains information necessary for frame rendering.
		//
		// Remarks:
		//     Subscribe to the OpenTK.GameWindow.RenderFrame event instead of overriding
		//     this method.
		protected virtual void OnRenderFrame(FrameEventArgs e);

the QuickStart uses overriding... which is prefered? i should use events instead? thanks

the Fiddler's picture

This comment looks incomplete, I'll have to clarify it.

Both approaches are perfectly acceptable and are 99% interchangeable. The only difference is that inheriting from GameWindow allows you to change the default behavior of some specific things (e.g. the main loop implementation), which makes overrides slightly more powerful.

If you wish to change how GameWindow works, inherit and override. Otherwise, pick the method which feels more natural to you (e.g. I used to prefer overriding in C# 2.0, but now prefer events with lambda functions in C# 3.0).

rakkarage's picture

why OnLoad public and the other 3 main overrides protected?

thanks

the Fiddler's picture

They all used to be public, but it seems I overlooked OnLoad when I fixed that...