iphone OpenGL ES 2.0 звычай будаваць выгляд Г.Л. не ўдалося, але не ведаю, чаму

I want to build a opengl es 2.0 view extend from UIview. And flow this article:http://www.raywenderlich.com/3664/opengl-es-2-0-for-iphone-tutorial

калі я скончыў першы крок. усё працуе няправільна. Ён не бег, як я Паўсюдна.

Вось мой код:

#import 

#import 
#import 
#import 


@interface NXGLES2View : UIView
- (void) render;
@end

#import "NXGLES2View.h"

@interface NXGLES2View() 
{
    CAEAGLLayer     *eaglLayer_;
    EAGLContext     *glContext_;
    GLuint          colorRenderBuffer_,frameBuffer_, depthRenderBuffer_;

    CADisplayLink   *displayLink_;
}

- (void) setupGL_;
- (void) tearDownGL_;

- (void) setupLayer_;
- (void) setupContext_;

- (void) setupRenderBuffer_;
- (void) setupFrameBuffer_;
- (void) setupDepthBuffer_;

- (void) setupDisplayLink_;
@end



    @implementation NXGLES2View

    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
           //Initialization code
            [self setupGL_];
        }
        return self;
    }

    #pragma mark -
    #pragma mark setup step

    + (Class)layerClass{
        return [CAEAGLLayer class];
    }

    - (void) setupLayer_{
        eaglLayer_ = (CAEAGLLayer *)self.layer;
        eaglLayer_.opaque = YES;
    }

    - (void) setupContext_{
        glContext_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
        if (!glContext_) {
            NSLog(@"failed to create eagl context,abort");
            abort();
        }

        if (![EAGLContext setCurrentContext:glContext_]) {
            NSLog(@"failed to set gl context, abort");
            abort();
        }
    }


    - (void) setupRenderBuffer_{
        glGenRenderbuffers(1, &colorRenderBuffer_);
        glBindRenderbuffer(GL_RENDERBUFFER, colorRenderBuffer_);
        [glContext_ renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer_];  
    }

    - (void) setupDepthBuffer_{
        glGenRenderbuffers(1, &depthRenderBuffer_);
        glBindRenderbuffer(GL_RENDERBUFFER, depthRenderBuffer_);
        glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, self.frame.size.width, self.frame.size.height);   
    }

    - (void) setupFrameBuffer_{
        glGenFramebuffers(1, &frameBuffer_);
        glBindRenderbuffer(GL_FRAMEBUFFER, frameBuffer_);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderBuffer_);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderBuffer_);
    }

    - (void) setupDisplayLink_{
        displayLink_ = [CADisplayLink displayLinkWithTarget:self selector:@selector(render)];
        [displayLink_ addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    }

    - (void) setupGL_{
        [self setupLayer_];
        [self setupContext_];
        [self setupDepthBuffer_];
        [self setupRenderBuffer_];
        [self setupFrameBuffer_];
    }

    - (void) tearDownGL_{
        glDeleteRenderbuffers(1, &colorRenderBuffer_);
        glDeleteRenderbuffers(1, &depthRenderBuffer_);
        glDeleteFramebuffers(1, &frameBuffer_);
    }


    #ifndef __IPHONE_5_0
    - (void) dealloc{

        [self tearDownGL_];

        [glContext_ release];
        glContext_ = nil;

        [super dealloc];
    }
    #endif


    #pragma mark - 
    #pragma mark draw

    - (void) render{
        glClearColor(1.0, 0.0, 0.0, 1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glEnable(GL_DEPTH_TEST);

        [glContext_ presentRenderbuffer:GL_RENDERBUFFER];
    }

Затым я ствараю пусты праект і зрабіць, як гэта:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
   //Override point for customization after application launch.
    NXGLES2View *glview = [[NXGLES2View alloc] initWithFrame:self.window.bounds];
    [self.window addSubview:glview];

    [glview performSelector:@selector(setupDisplayLink_) withObject:nil afterDelay:2.0];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    return YES;
}

Калі праграма запуску. яна не адлюстроўваецца             glClearColor (1.0, 0.0, 0.0, 1.0); чырвоны колер.

і I'v праверыць артыкул ізноў і again.I не магу зразумець, дзе гэта не так. дапамажыце мне, калі ласка. Дзякуй зноў.

1
thanks.Yes, GLKit дасканалы. Але я хачу ведаць, дзе гэта няправільна. Я хачу глыбока ў OpenGL ES КСН.
дададзена аўтар dinosaur, крыніца
Я знайшоў, што я зрабіў памылку ў setupFrameBuffer_ method.glBindRenderbuffer (GL_FRAMEBUFFER, frameBuffer_); гэта павінна быць glBindFramebuffer (GL_FRAMEBUFFER, frameBuffer_);
дададзена аўтар dinosaur, крыніца
Вы пачатковец у OpenGL на прашыўцы, вы значна лепш выкарыстоўваць GLKit. developer.apple.com/library/ios/#documentation/GLkit/R‌ правочник/& hellip;
дададзена аўтар logancautrell, крыніца

1 адказы

Я знайшоў, што я зрабіў памылку ў метадзе setupFrameBuffer_.

glBindRenderbuffer(GL_FRAMEBUFFER, frameBuffer_);

гэта павінна быць:

glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer_); 
1
дададзена