glGenFramebuffersはフレームバッファオブジェクトを割り当てません!この小さなプログラムを動作させることができません。
コード:
/* ----- AppDelegate.h ----- */
#import <UIKit/UIKit.h>
#import "GLView.h"
@interface AppDelegate : NSObject <UIApplicationDelegate>{
@private
UIWindow *window;
GLView *view;
}
@end
/* ----- AppDelegate.h ----- */
#import "AppDelegate.h"
@implementation AppDelegate
- (void)dealloc
{
[view release];
[window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGRect frame = [[UIScreen mainScreen] bounds];
window = [[UIWindow alloc] initWithFrame:frame];
view = [[GLView alloc] initWithFrame:frame];
[window addSubview:view];
[window makeKeyAndVisible];
return YES;
}
@end
/* ----- GLView.h ----- */
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
@interface GLView : UIView{
@private
EAGLContext* context;
GLuint color_render_buffer;
GLuint depth_render_buffer;
GLuint frame_buffer;
}
-(void)render:(CADisplayLink*)displayLink;
@end
/* ----- GLView.mm ----- */
#import "GLView.h"
@implementation GLView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)self.layer;
eaglLayer.opaque = YES;
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if(!context && ![EAGLContext setCurrentContext:context]){
[self release];
return nil;
}
int width = (int)frame.size.width;
int height = (int)frame.size.height;
glGenFramebuffers(1, &frame_buffer);
glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer);
if(glIsFramebuffer(frame_buffer) == GL_FALSE){
//NSLog(@"%i", frame_buffer);
NSLog(@"frame_buffer is GL_FALSE!");
}
glGenRenderbuffers(1, &color_render_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, color_render_buffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer];
if(glIsRenderbuffer(color_render_buffer) == GL_FALSE){
NSLog(@"%i", color_render_buffer);
NSLog(@"color_render_buffer is GL_FALSE");
}
glGenRenderbuffers(1, &depth_render_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, depth_render_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
if(glIsRenderbuffer(depth_render_buffer) == GL_FALSE){
NSLog(@"depth_render_buffer is GL_FALSE");
}
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_render_buffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_render_buffer);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
#ifdef DEBUG_LOG
NSLog(@"Framebuffer is not complete!");
exit(1);
#endif
}
[[CADisplayLink displayLinkWithTarget:self selector:@selector(render:)] addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
return self;
}
+(Class)layerClass{
return [CAEAGLLayer class];
}
-(void)dealloc{
if([EAGLContext currentContext] == context){
[EAGLContext setCurrentContext:nil];
}
[context release];
[super dealloc];
}
-(void)render:(CADisplayLink*)displayLink{
/* Rendering */
[context presentRenderbuffer:GL_RENDERBUFFER];
}
@end
私はいつも「frame_bufferはGL_FALSEです!」と表示されます。コンソールに出力...frame_bufferは常に0(ウィンドウシステムのデフォルトのフレームバッファー)plistに追加する必要のある設定はありますか?それとも私は何かが足りないのですか?
助けてください。