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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 08-26-2009, 04:46 AM   #20 (permalink)
saran
Registered Member
 
Join Date: Aug 2009
Posts: 10
Default

- (CGImageRef) getPicture
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

// Create and init the textures
Texture2D *_textures[2];
_textures[0] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"clean.png"]];
_textures[1] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"testbkgnd1.jpg"]];

// Get the drawing in the screen
glBindTexture(GL_TEXTURE_2D,[_textures[0] name]);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, kScreenWidth, kScreenHeight);

// Redraw the scene
[_textures[1] drawInRect:[self bounds]];
[_textures[0] drawInRect:[self bounds]];

// Entire data length
NSInteger myDataLength = kScreenWidth * kScreenHeight * 4;

// allocate array and read pixels into it.
static GLubyte *buffer = NULL;
static GLubyte *invertedBuffer = NULL;

if(buffer == NULL)
buffer = (GLubyte *) malloc(myDataLength);

if(invertedBuffer == NULL)
invertedBuffer = (GLubyte *) malloc(myDataLength);

glReadPixels(0, 0, kScreenWidth, kScreenHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

// reverse the height as opengl draws it upside down
for(int y = 0; y <kScreenHeight; y++)
{
for(int x = 0; x <kScreenWidth * 4; x++)
{
invertedBuffer[((kScreenHeight-1) - y) * kScreenWidth * 4 + x] = buffer[y * 4 * kScreenWidth + x];
}
}

// make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, invertedBuffer, myDataLength, NULL);

// prep the ingredients
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * kScreenWidth;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

// make the cgimage
CGImageRef imageRef = CGImageCreate(kScreenWidth, kScreenHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);

// Redraw the drawings w/o the background
[self erase];
[_textures[0] drawInRect:[self bounds]];
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
[self swapBuffers];


// Bind the brush stoke texture to the default one
glBindTexture(GL_TEXTURE_2D, brushTexture[0]);

// Release the textures
[ _textures[0] release];
[ _textures[1] release];

return imageRef;
}


This is my code... but still get a darker _texture[1] with higher contrast.
and when i Redraw the drawings w/o the background the drawings were also dark w/o any additive drawings also...

comments please.

Saran.
saran is offline   Reply With Quote
 

» Advertisements
» Online Users: 365
20 members and 345 guests
ADY, apatsufas, bobli, Dani77, Dattee, Desert Diva, HDshot, HemiMG, ilmman, leahov, MarcoAlmeida, mer10, michelle, Punkjumper, Raffaello, Robiwan, Rudy, skrew88, wilky94
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,877
Threads: 89,222
Posts: 380,726
Top Poster: BrianSlick (7,129)
Welcome to our newest member, peterkessler45
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:36 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.