I want to develop an
IOS SDK for Unity/COCOS/SpritKit game app to record video.Main program is to synthetic video after screenshots.
Now I do the test with IOS project from unity game on IOS 7.0 device and try to use
Opengl function
glreadpiexls() to read pixel buffer, but always got the black image which troubled me for weeks.
So can anyone give me some suggestions for the screenshot on iOS for Unity/COCOS/SpritKit games, and this is my current code.
int w = 320;
int h = 480;
NSInteger myDataLength = w * h * 4;
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
GLubyte temp = 0;
int index1 = 0;
int index2 = 0;
for(int y = 0; y < h - 1 - y; y++) {
index1 = y * 4 * w;
index2 = (h -1 - y) * w * 4;
for(int x = 0; x <w * 4; x++) {
temp = buffer[index1 + x];
buffer[index1 + x] = buffer[index2 + x];
buffer[index2 + x] = temp;
}
}
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, myDataLength, NULL);
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * w;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGImageRef imageRef = CGImageCreate(w, h, bitsPerComponent, bitsPerPixel, bytesPerRow, CGColorSpaceCreateDeviceRGB(), kCGBitmapByteOrderDefault, provider, NULL, NO, kCGRenderingIntentDefault);
UIImage *myImage = [ UIImage imageWithCGImage:imageRef scale:s orientation:UIImageOrientationUp ];
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpaceRef);
What I have tried:
I try some solutions like to set the context and set the EAGLView drawing property before glreadpiexls() but not work. And some suggest to make sure to execute glreadpiexls() before presentRenderbuffer, but how . I can not modify the code from Unity.
Solutions like IOSuface depreciated on iOS 9.0 and seems only for UIView elements and IOSurface was depreciated on ios 9.0 and seems only for UIView elements. RenderTexture or Application.CaptureScreenshot are only for unity project, not for my IOS SDK.