objarni's picture

Render to bitmap / bitmap context

Is there any way to have a .NET Bitmap GLContext of some sort..? For "off-screen-rendering".


Comments

Comment viewing options

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

AFAIK, there are two ways to do off-screen rendering: either use OpenGL's render-to-texture functionality and read back from that texture (with ReadPixels), or use a pbuffer. OpenTK does not currently support pbuffers (it shouldn't be difficult to change Win/X11GLContext to add support, but getting the thing to work identically on both Windows and Linux is a bit of a pain), but it's easy to bind a context to an invisible window:

Form form = new Form();
GLContext context = new GLContext(new DisplayMode(), WindowInfo.GetInfoFrom(form));
context.CreateContext();   // or context.CreateContext(true, sharedContext);
form.Visible = false;

You can then use the framebuffer object extension to perform off-screen rendering.