2010-05-26 10 views
0

현재 백킹 및 너비가 모두 15로 설정된 OpenGL ES 렌더 버퍼에 문제가 있습니다. 너비를 320으로 설정하는 방법이 있습니까? 480? 내 프로젝트는 Apple의 EAGLView 클래스와 ES1Renderer에 구축되어 있지만 앱 대리인에서 컨트롤러로 옮겼습니다. 또한 CADisplayLink를 외부로 옮겼습니다 (게임 타임을이 게임의 타임 스탬프로 업데이트합니다).렌더 버퍼 너비 및 높이 설정 (Open GL ES)

도움이 될만한 점이 많습니다. 다음과 같이

나는 창에 glview을 추가

CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame]; 
    [window addSubview:gameController.glview]; 
    [window makeKeyAndVisible]; 

나는 컨트롤러와 그 안에 glview을 합성. 그렇지 않으면 EAGLView와 Renderer가 수정되지 않습니다.

렌더러 초기화 :

// Get the layer 
    CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; 

    eaglLayer.opaque = TRUE; 
    eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: 
            [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; 

    renderer = [[ES1Renderer alloc] init]; 

"레이어에서 크기 조정"렌더 방법

- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer 
{ 
    // Allocate color buffer backing based on the current layer size 
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); 
    [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer]; 
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); 
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); 

    NSLog(@"Backing Width:%i and Height: %i", backingWidth, backingHeight); 

    if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) 
    { 
     NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES)); 
     return NO; 
    } 

return YES; 

} 당신이 renderbufferStorage 호출 할 때

답변

1

: fromDrawable :, layer.bounds 무엇인가? renderbuffer의 픽셀 너비와 높이는 layer.bounds.size와 일치하도록 할당됩니다.

+0

, 값을 layer.bounds을 위해 : 나를 위해 완벽하게 작동 -Origin : (50, 1650) | 크기 : w : 30, h : 1675 –

+0

올바른 길로 나를 설정해 주셔서 고마워요. 알아 냈어. –

0

Apple의 문서에서. CGRect은

어떤 이유를 들어
- (UIImage*)snapshot:(UIView*)eaglview { 
    GLint backingWidth, backingHeight; 
// Bind the color renderbuffer used to render the OpenGL ES view 
// If your application only creates a single color renderbuffer which is already bound at this point, 
// this call is redundant, but it is needed if you're dealing with multiple renderbuffers. 
// Note, replace "_colorRenderbuffer" with the actual name of the renderbuffer object defined in your class. 
glBindRenderbufferOES(GL_RENDERBUFFER_OES, _colorRenderbuffer); 

// Get the size of the backing CAEAGLLayer 
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); 
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); 

NSInteger x = 0, y = 0, width = backingWidth, height = backingHeight; 
NSInteger dataLength = width * height * 4; 
GLubyte *data = (GLubyte*)malloc(dataLength * sizeof(GLubyte)); 

// Read pixel data from the framebuffer 
glPixelStorei(GL_PACK_ALIGNMENT, 4); 
glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); 

// Create a CGImage with the pixel data 
// If your OpenGL ES content is opaque, use kCGImageAlphaNoneSkipLast to ignore the alpha channel 
// otherwise, use kCGImageAlphaPremultipliedLast 
CGDataProviderRef ref = CGDataProviderCreateWithData(NULL, data, dataLength, NULL); 
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); 
CGImageRef iref = CGImageCreate(width, height, 8, 32, width * 4, colorspace, kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast, 
           ref, NULL, true, kCGRenderingIntentDefault); 

// OpenGL ES measures data in PIXELS 
// Create a graphics context with the target size measured in POINTS 
NSInteger widthInPoints, heightInPoints; 
if (NULL != UIGraphicsBeginImageContextWithOptions) { 
    // On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration 
    // Set the scale parameter to your OpenGL ES view's contentScaleFactor 
    // so that you get a high-resolution snapshot when its value is greater than 1.0 
    CGFloat scale = eaglview.contentScaleFactor; 
    widthInPoints = width/scale; 
    heightInPoints = height/scale; 
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(widthInPoints, heightInPoints), NO, scale); 
} 
else { 
    // On iOS prior to 4, fall back to use UIGraphicsBeginImageContext 
    widthInPoints = width; 
    heightInPoints = height; 
    UIGraphicsBeginImageContext(CGSizeMake(widthInPoints, heightInPoints)); 
} 

CGContextRef cgcontext = UIGraphicsGetCurrentContext(); 

// UIKit coordinate system is upside down to GL/Quartz coordinate system 
// Flip the CGImage by rendering it to the flipped bitmap context 
CGContextSetBlendMode(cgcontext, kCGBlendModeCopy); 
CGContextDrawImage(cgcontext, CGRectMake(0.0, 0.0, widthInPoints, heightInPoints), iref); 

// Retrieve the UIImage from the current context 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 

// Clean up 
free(data); 
CFRelease(ref); 
CFRelease(colorspace); 
CGImageRelease(iref); 

return image; 
} 
관련 문제