Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-17-2009, 07:07 AM   #1 (permalink)
New Member
 
Join Date: May 2009
Posts: 6
paul84 is on a distinguished road
Default Render UIView into byte-buffer

Hello,

I'd like to display the contents of an UIView-subclass (such as UITableView or UITextView) on the surface of an OpenGL-object (a cube). Therefore I need to render the tableView (textView respectively) into my own context.

I experimented with UIGraphicsPushContext(...) and UIGraphicsPopContext() hoping that subviews like the tableView would render themself into the alternative context (which is my texture), but they didn't. Here's my code to create the texture:

Code:
...
size_t TEXTURE_WIDTH = 256;
size_t TEXTURE_HEIGHT = 256;
GLubyte *textureData = (GLubyte*)malloc(TEXTURE_WIDTH * TEXTURE_HEIGHT * 4);
CGContextRef textureContext = CGBitmapContextCreate(textureData,
	TEXTURE_WIDTH, TEXTURE_HEIGHT, 8, TEXTURE_WIDTH * 4,
	CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
// Try to render tableView on texture
UIGraphicsPushContext(textureContext);
[tableView drawRect:CGRectMake(0, 0, 193, 138)];
UIGraphicsPopContext();
...
Any suggestions preventing me from adopting the lookalike of the ready-existing views all by myself , will be much appreciated.

Thanks in advance,
Paul
paul84 is offline   Reply With Quote
Old 07-08-2010, 06:17 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 17
Mehuge is on a distinguished road
Default

Quote:
Originally Posted by paul84 View Post
Hello,

I'd like to display the contents of an UIView-subclass (such as UITableView or UITextView) on the surface of an OpenGL-object (a cube). Therefore I need to render the tableView (textView respectively) into my own context.

I experimented with UIGraphicsPushContext(...) and UIGraphicsPopContext() hoping that subviews like the tableView would render themself into the alternative context (which is my texture), but they didn't. Here's my code to create the texture:

Code:
...
size_t TEXTURE_WIDTH = 256;
size_t TEXTURE_HEIGHT = 256;
GLubyte *textureData = (GLubyte*)malloc(TEXTURE_WIDTH * TEXTURE_HEIGHT * 4);
CGContextRef textureContext = CGBitmapContextCreate(textureData,
	TEXTURE_WIDTH, TEXTURE_HEIGHT, 8, TEXTURE_WIDTH * 4,
	CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
// Try to render tableView on texture
UIGraphicsPushContext(textureContext);
[tableView drawRect:CGRectMake(0, 0, 193, 138)];
UIGraphicsPopContext();
...
Any suggestions preventing me from adopting the lookalike of the ready-existing views all by myself , will be much appreciated.

Thanks in advance,
Paul
I too would be interested to know how to do this.

Found this http://www.iphonedevsdk.com/forum/ip...ot-uiview.html
going to have a play.
Mehuge is offline   Reply With Quote
Old 07-08-2010, 06:43 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 17
Mehuge is on a distinguished road
Default

Code:
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
Did the trick for me. I created a version of the Flow Cover sample code that renders a view instead of an image with a few simple changes.

In the imageToTextureUIImage*)image method which I renamed to viewToTextureUIView*)view I replaced the middle section of that code which sized and scaled the image and rendered the image in the graphic context with a the above call.
Mehuge is offline   Reply With Quote
Reply

Bookmarks

Tags
create an instance, image

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 338
6 members and 332 guests
givensur, ipodphone, jbro, mer10, n00b, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,881
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:08 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0