Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3348118
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:30:14+00:00 2026-05-18T01:30:14+00:00

I followed the tutorial on this page: http://iphone-3d-programming.labs.oreilly.com/ch01.html I got down to the part

  • 0

I followed the tutorial on this page:

http://iphone-3d-programming.labs.oreilly.com/ch01.html

I got down to the part where it says, “Compile and build and you should now see a solid gray screen. Hurray!” However, when I ran the program, I just get a black screen.

These are what the files look like:

HelloArrowAppDelegate.h

#import <UIKit/UIKit.h>
#import "GLView.h"

@interface HelloArrowAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *m_window;
    GLView* m_view;
}

@end

HelloArrowAppDelegate.mm

#import "HelloArrowAppDelegate.h"

@implementation HelloArrowAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    m_window = [[UIWindow alloc] initWithFrame: screenBounds];
    m_view = [[GLView alloc] initWithFrame:screenBounds];

    [m_window addSubview: m_view];
    [m_window makeKeyAndVisible];

    return YES;
}

- (void)dealloc {
    [m_view release];
    [m_window release];
    [super dealloc];
}

@end

GLView.h

#import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h>
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>

@interface GLView : UIView {
    EAGLContext* m_context;
}

-(void) drawView;

@end

GLView.mm

#import "GLView.h"

@implementation GLView

- (void) drawView
{
    glClearColor(0.5f, 0.5f, 0.5f, 1);
    glClear(GL_COLOR_BUFFER_BIT);

    [m_context presentRenderbuffer:GL_RENDERBUFFER_OES];
}

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

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        CAEAGLLayer* eaglLayer = (CAEAGLLayer*) super.layer;
        eaglLayer.opaque = YES;

        m_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];

        if (!m_context || ![EAGLContext setCurrentContext:m_context]) {
            [self release];
            return nil;
        }

        // OpenGL Initialization
        GLuint framebuffer, renderbuffer;
        glGenFramebuffersOES(1, &framebuffer);
        glGenFramebuffersOES(1, &renderbuffer);

        [m_context
         renderbufferStorage:GL_RENDERBUFFER_OES
         fromDrawable: eaglLayer];

        glFramebufferRenderbufferOES(
                                     GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES,
                                     GL_RENDERBUFFER_OES, renderbuffer);

        glViewport(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame));

        [self drawView];
    }
    return self;
}

- (void)dealloc {
    if ([EAGLContext currentContext] == m_context) {
        [EAGLContext setCurrentContext:nil];
    }

    [m_context release];
    [super dealloc];
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:30:14+00:00Added an answer on May 18, 2026 at 1:30 am

    The initWithFrame is incorrect. You want to generate a framebuffer and a renderbuffer and link the two. Instead you generate two framebuffers and completely ignore one. You should also keep the references to them (the variables ‘renderbuffer’ and ‘framebuffer’) in your class, as you’ll need to delete them later unless you want to leak memory.

    Without fixing the second issue, I recommend:

    - (id)initWithFrame:(CGRect)frame {
        if ((self = [super initWithFrame:frame])) {
            CAEAGLLayer* eaglLayer = (CAEAGLLayer*) super.layer;
            eaglLayer.opaque = YES;
    
            m_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
    
            if (!m_context || ![EAGLContext setCurrentContext:m_context]) {
                [self release];
                   return nil;
            }
    
            // these should be in the class so that we can release them later,
            // this will leak resources
            GLuint framebuffer, renderbuffer;
    
            // generate and bind a framebuffer
            glGenFramebuffersOES(1, &framebuffer);
            glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
    
            // generate a colour renderbuffer; this example doesn't seem to want
            // e.g. a depth buffer, but if it did then you'd generate and add one
            // of those here also
    
            // generate and bind
            glGenRenderbuffersOES(1, &renderbuffer);
            glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderbuffer);
    
            // get storage from the layer
            [m_context
             renderbufferStorage:GL_RENDERBUFFER_OES
             fromDrawable: eaglLayer];
    
            // link to the framebuffer
            glFramebufferRenderbufferOES(
                                         GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES,
                                         GL_RENDERBUFFER_OES, renderbuffer);
    
            glViewport(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame));
    
            [self drawView];
        }
        return self;
    }
    

    Put framebuffer and renderbuffer somewhere you can get to them again at the relevant moment and you should also:

    - (void)dealloc {
    
        if(renderbuffer) glDeleteRenderbuffersOES(1, &renderbuffer);
        if(framebuffer) glDeleteFramebuffersOES(1, &framebuffer);
    
        if ([EAGLContext currentContext] == m_context) {
            [EAGLContext setCurrentContext:nil];
        }
    
        [m_context release];
        [super dealloc];
    }
    

    I’ve tested this against the code you provide. I get the grey screen. Changing the call to glClearColor changes the colour of the screen, so clearly the GL context is working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new facebook application deverloper. I followed this tutorial: http://www.adobe.com/devnet/facebook/articles/video_facebook_quick_start.html but I
This is probably very simple! I followed a tutorial from http://webdesignerwall.com/demo/jquery-sequential/jquery-sequential-list.html It works fine
I'm building an ogre3d tutorial based on this setup http://www.ogre3d.org/wiki/index.php/SettingUpAnApplication#XCode I've followed all steps
I followed this tutorial on configuring the Rails plugin ExceptionNotifier. I know that I
I've followed this otherwise excellent tutorial on getting Xen working with Ubuntu but am
I have followed all the instructions here: http://www.tonyspencer.com/2003/10/22/curl-with-php-and-apache-on-windows/ to install & config apache get
I have followed the suggestion in this question... [ How to handle checkboxes in
I've followed this example: RCP+JavaWS but the app just briefly comes up and goes
I started with core-plot now and came to some problems. I followed the tutorial
Program followed by output. Someone please explain to me why 10,000,000 milliseconds from Jan

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.