0

こんにちは、私は ios と OpenGL の初心者です。本 iPhone 3d プログラミングの指示に従おうとしています。OpenGL から灰色の画面をレンダリングしたいだけです。

私は何が間違っていたのか本当にわかりません.なぜOpenGLウィンドウが表示されないのかを理解する必要があります.

さらにサポートできる場合は、コメントを投稿してください :)

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 {
    // Protected fields
    EAGLContext* m_context;
}

// public fields
-(void)drawWiew;

@end

GLView.mm:

#import "GLView.h"

@implementation GLView

+(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;
        }

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

        glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
        glBindRenderbufferOES(GL_RENDERBUFFER_OES, 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 drawWiew];
    }
    return self;
}

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

    [m_context presentRenderbuffer:GL_RENDERBUFFER_OES];

    NSLog(@"drawView called");
}

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

    [m_context release];
    [super dealloc];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end

HellowArrowAppDelegate.h:

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

@interface HelloArrowAppDelegate : UIResponder <UIApplicationDelegate> {
    UIWindow* window;
    GLView* view;
}

@property (strong, nonatomic) UIWindow *window;

@end

HellowArrowAppDelegate.mm:

#import "HelloArrowAppDelegate.h"

@implementation HelloArrowAppDelegate

@synthesize window = _window;

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    _window = [[UIWindow alloc] initWithFrame:screenBounds];
    view = [[GLView alloc] initWithFrame:screenBounds];   

    [_window addSubview:view];
    [_window makeKeyWindow];

//    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
//    // Override point for customization after application launch.
//    self.window.backgroundColor = [UIColor whiteColor];
//    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     */
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /*
     Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
     */
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    /*
     Called when the application is about to terminate.
     Save data if appropriate.
     See also applicationDidEnterBackground:.
     */
}

@end
4

1 に答える 1

0

OpenGL の画面は、使用している OS のバージョンや、描画される画面ウィンドウのサイズによっては黒くなることがあります。たとえば、4.0、4.1、および 4.3 で正常に実行されるコードは、4.2 では黒く表示される可能性があります。または、OpenGL ウィンドウのサイズを 2 倍にすると機能します。ファームウェアが邪魔になる場合があります。新しいバージョンの OS を使ってみて、よりうまく機能するかどうかを確認してください。

于 2013-04-07T22:53:07.253 に答える