Interface IBindingsContext
Provides methods for querying available functions in a bindings context.
Namespace: OpenTK
Assembly: OpenTK.Core.dll
Syntax
public interface IBindingsContext
Remarks
If you wish to use OpenTK OpenGL bindings in a custom environment see the example for a tutorial on its usage.
Examples
In order to use this interface, you need to figure out how to load OpenGL
function pointers in your custom environment. For example, if you are
providing a custom window using SDL, you would use the C function
SDL_GL_GetProcAddress
to implement this interface.
using System;
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Graphics.OpenGL4;
public class MySDLBindingsContext : IBindingsContext
{
public IntPtr GetProcAddress(string procName)
{
[DllImport("SDL2")]
extern static IntPtr SDL_GL_GetProcAddress([MarshalAs(UnmanagedType.LPStr)] string procName);
return SDL_GL_GetProcAddress(procName);
}
}
/// ...
// In order to load the bindings, call the following function with this
// new class you implemented.
GL.LoadBindings(new MySDLBindingsContext());
Do note that every OpenTK.Graphics.XXX namespace has its own pointer table. If you have mixed and matched the namespaces used in your project, you might run into exceptions telling you that the bindings are not loaded.
Methods
GetProcAddress(string)
Retrieves an unmanaged function pointer to the specified function on the specified bindings context.
Declaration
nint GetProcAddress(string procName)
Parameters
Type | Name | Description |
---|---|---|
string | procName | An ASCII-encoded string that defines the name of the function. |
Returns
Type | Description |
---|---|
nint | A nint that contains the address of procName or IntPtr.Zero, if the function is not supported by the drivers. |
Remarks
Note: some drivers are known to return non-zero values for unsupported functions. Typical values include 1 and 2 - inheritors are advised to check for and ignore these values.