GL not rendering?

Posts: 13
Joined: 2009.06
Post: #1
I am following the 71squared tutorials(somewhat), and I started my project by redoing the game loop to not use the timer. For some reason, however, the screen in black. The screen isn't being cleared to the glClear color. There are no warnings or errors. drawView is being called.

- (void)initOpenGL {

    glOrthof(0, screenBounds.size.width, 0, screenBounds.size.height, -1, 1);
    glClearColor(1.0f, 0.5f, 0.5f, 1.0f);
    glInitialized = YES;

- (void)gameLoop {
    CFTimeInterval time;
    float delta;
    while (true) {
        time = CFAbsoluteTimeGetCurrent();
        delta = (time - lastTime) * 1000;
        while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource);
        [self drawView];
        lastTime = time;

- (void)drawView {
    // Replace the implementation of this method to do your own custom drawing
    NSLog(@"drawView called");
    if(!glInitialized) {
        [self initOpenGL];
    [EAGLContext setCurrentContext:context];
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glViewport(0, 0, screenBounds.size.width, screenBounds.size.height);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
Quote this message in a reply
Posts: 65
Joined: 2009.03
Post: #2
Hi Cirdan

How are you calling the gameLoop? and are you using OS 3.0?

If you are calling the game loop using something like

[glView gameLoop];

then you will see a blank screen, something to do with applicationDidFinishLaunching running on its own thread in 3.0 I think.

If you call it using the code below, you may find that it works

[glView performSelectorOnMainThread:@selector(gameLoop) withObject:nil waitUntilDone:NO];

I'm not completely sure if this is the problem as you say the drawView method is being called, but thought I'd check Wink

Quote this message in a reply
Posts: 13
Joined: 2009.06
Post: #3
Ohh, ok. That fixed it and makes sense. Thanks!
Quote this message in a reply
Post Reply