This chapter contains instructions for people wishing to modify or extend OpenTK. It describes the project structure, wrapper design, coding style and various caveats and hacks employed by OpenTK to achieve wider platform support.
The OpenTK project consists of a number of managed, cross-platform assemblies:
In addition to these assemblies, OpenTK maintains a custom binding generator which generates the OpenGL, OpenGL|ES and OpenCL bindings. It consists of two assemblies:
Finally, OpenTK provides a QuickStart project, which shows how to setup and build an OpenTK application.
The OpenTK solution provides the following public namespaces:
The public API of OpenTK is completely cross-platform. All platform-specific code is contained in internal interfaces under the OpenTK.Platform namespace. In that sense, most public classes act as façades that forward method calls to the correct platform-specific implementation.
public class Foo : IFoo { IFoo implementation; public Foo() { implementation = OpenTK.Platform.Factory.Default.CreateFoo(); } #region IFoo Members public void Bar() { implementation.Bar(); } #endregion }
This pattern is used in all public OpenTK classes that need platform-specific code to operate: DisplayDevice, DisplayResolution, GraphicsContext, GraphicsMode, NativeWindow and the various input classes.
Classes that do not rely on platform-specific code and classes that contain performance-sensitive code do not use this pattern: the various math classes, the OpenGL, OpenCL and OpenAL bindings, the AudioContext and AudioCapture classes all fall into these categories.
OpenTK provides .Net wrappers for a various important native APIs: OpenGL, OpenGL ES, OpenAL and OpenCL (in progress). Unlike similar libraries, OpenTK places an emphasis in usability and developer efficiency, while staying true to the nature of the native interface. To that end, it utilizes a number of .Net constructs that are not available in native C by default:
Vector3 instead of Vector3f>, Vector3d, ...).The bindings are generated through an automated binding generator, which converts the official API specifications into C# code. The following pages describe the generation process in detail.
Official API specifications: