2012-03-11 6 views
2

私は本当にうまく動作するOpenGLを使用してiPhoneゲームを作成しています。ホームボタンが押されるとゲームがバックグラウンドになると、iOSはアプリがフォアグラウンドに戻るときに表示される画面のスクリーンショットを作成します。iPhoneバックグラウンドからの返信はすべて白です

問題は、ゲームをもう一度起動(バックグラウンドから戻す)すると、ゲームの最後の画面ではなく、白い画像が表示されることです。もちろん、ゲームはすぐに背景に行くためにうまくいきます。

私は実際のiPhone(Simulator v.5.0、iOS v.5.0)ではなく、シミュレータでのみこの問題をテストしました。

誰にもこの問題とその解決策がありますか?私は何かを逃していますか?

更新:私は一部のCocos2Dユーザーにhave the same problem but without a solutionが見つかりました。私はCocos2Dを使用しません。

アップデート:iOSで撮影したスナップショットが640x960の白いjpgファイルであることを確認しました。だから、おそらく問題は、OpenGL-ESとゲームのビューとの間の何らかのタイプの接続です。

+0

スクリーンショットをどのようにキャプチャしていますか?私たちを見せてください。 –

+0

Jeshua私はスクリーンショットをキャプチャしていません。アプリがアクティブになったときに自動的にそのスクリーンショットを表示してiOSシステムを再起動します(高速なビジュアル読み込みエクスペリエンスを作成するためです)。そのスクリーンショットは、ゲームの最後のフレームの代わりにすべて白く表示されます。 – jfcalvo

答えて

1

アプリケーションがOpenGLの場合、glReadPixelsを使用してイメージスクリーンを読み取ることができます。

- (UIImage*) getGLScreenshot { 
    NSInteger myDataLength = 320 * 480 * 4; 

    // allocate array and read pixels into it. 
    GLubyte *buffer = (GLubyte *) malloc(myDataLength); 
    glReadPixels(0, 0, 320, 480, GL_RGBA, GL_UNSIGNED_BYTE, buffer); 

    // gl renders "upside down" so swap top to bottom into new array. 
    // there's gotta be a better way, but this works. 
    GLubyte *buffer2 = (GLubyte *) malloc(myDataLength); 
    for(int y = 0; y <480; y++) 
    { 
     for(int x = 0; x <320 * 4; x++) 
     { 
      buffer2[(479 - y) * 320 * 4 + x] = buffer[y * 4 * 320 + x]; 
     } 
    } 

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

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

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

    // then make the uiimage from that 
    UIImage *myImage = [UIImage imageWithCGImage:imageRef]; 
    return myImage; 
} 

- (void)saveGLScreenshotToPhotosAlbum { 
    UIImageWriteToSavedPhotosAlbum([self getGLScreenshot], nil, nil, nil); 
} 
関連する問題