Why is glReadPixels() failing in this code in iOS 6.0?
CAEAGLLayer *eaglLayer = (CAEAGLLayer *) self.layer;
eaglLayer.drawableProperties = @{
kEAGLDrawablePropertyRetainedBacking: [NSNumber numberWithBool:YES],
kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8
};
set
kEAGLDrawablePropertyRetainedBacking = YES
(I do not know why this tip is going well..///)
glReadPixel stopped working with iOS6 Beta
Thanks for the apple private list suggestion - that's where I found the solution to that problem.
In the Cocos2D Class "EAGLView.m" I was setting the "preserveBackbuffer" variable to "YES" at the init method. It now works again also in iOS 6 Beta.
glReadPixels gives a black image only on iOS 7 device
As posted in the comments I managed to use your code and it worked. However, I defined your BACKING_TYPE_LAYERBACKED
which generates the render buffer from the view.
The other pipeline that creates the FBO did not work though. The issue in your FBO pipeline is calling [self.context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:nil]
. Remove this line and you should be fine.
Cocos2D 2.0 screenshots on iOS 6
I am not sure what the GitHub version does but this code will take a screenshot and I just tested it on iOS 6 and it works fine.
+(UIImage*) screenshotWithStartNode:(CCNode*)startNode
{
[CCDirector sharedDirector].nextDeltaTimeZero = YES;
CGSize winSize = [CCDirector sharedDirector].winSize;
CCRenderTexture* rtx =
[CCRenderTexture renderTextureWithWidth:winSize.width
height:winSize.height];
[rtx begin];
[startNode visit];
[rtx end];
return [rtx getUIImage];
}
You can call it like this
CCScene *scene = [[CCDirector sharedDirector] runningScene];
CCNode *n = [scene.children objectAtIndex:0];
UIImage *img = [AppController screenshotWithStartNode:n];
Related Topics
iOS (Iphone, iPad, Ipodtouch) View Real-Time Console Log Terminal
How to Iterate For Loop in Reverse Order in Swift
How to Hide the Status Bar in a Swift iOS App
Xcode 9 Error: "Iphone Has Denied the Launch Request"
How to Launch Safari and Open Url from iOS App
Add Image to Uialertaction in Uialertcontroller
How to Compress/Resize Image on iOS Before Uploading to a Server
How to Handle Background Audio Playing While iOS Device Is Locked or on Another Application
Get Indexpath of Uitableviewcell on Click of Button from Cell
iOS 7 Tableview Like in Settings App on iPad
How to Perform Wireless Debugging in Xcode 9 With iOS 11, Apple Tv 4K, etc
How to Create .Ipa File Using Xcode
Cgcontextdrawimage Draws Image Upside Down When Passed Uiimage.Cgimage
Error When Testing on iOS Simulator: Couldn't Register With the Bootstrap Server