Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture a OpenGL view as UIImage?

When I try to use this method to convert a OpenGL view to UIImage, only the view's background is returned, but not the GLView content. How can I convert OpenGL's context into a UIImage?

like image 459
ohho Avatar asked Jun 12 '11 11:06

ohho


1 Answers

It depends on what OpenGL view you are using. Since iOS 5 you can make use of GLKit and the corresponding GLKView that greatly simplifies the process of rendering an UIImage.

GLKView* v = (GLKView*) _previewViewController.view;
UIImage* thumbnail = [v snapshot];

http://developer.apple.com/library/ios/#documentation/GLkit/Reference/GLKView_ClassReference/Reference/Reference.html

like image 163
Christoph Avatar answered Sep 30 '22 20:09

Christoph