Starting with version 0.9.1, OpenTK requires the existence of an OpenGL context prior to the initialization of the OpenGL subsystem. In other words, you cannot use any OpenGL methods prior to the creation of a
If you create the OpenGL context through an external library (for example SDL or GTK#), you will need to inform OpenTK of the context's existence using the
GraphicsContext.CreateDummyContext() static method. This method will return a new
GraphicsContext instance for the context that is current on the calling thread. Optionally, you can pass the handle (
IntPtr) of a specific external context to
CreateDummyContext; in this case, the external context need not be current on the calling thread.
You will typically call this method as soon as the external context is created. For example, using Tao.Glfw:
Tao.Glfw.glfwOpenWindow(640, 480, 8, 8, 8, 8, 16, 0, Tao.Glfw.GLFW_WINDOW); OpenTK.Graphics.GraphicsContext.CreateDummyContext(); // You may now use OpenTK.Graphics methods normally.
Please note that it is an error to call
CreateDummyContext() multiple times for the same external context.