j'ai suivi le tutoriel sur cette page:Pourquoi je ne reçois pas un fond gris dans ce programme
http://iphone-3d-programming.labs.oreilly.com/ch01.html
Je suis descendu à la partie où il est dit, « compiler et construire et vous devriez maintenant voir un écran gris uni, Hourra! Cependant, quand j'ai lancé le programme, j'ai juste un écran noir.
Ce sont ce que les fichiers ressemblent:
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
Je ne sais pas si cela est un problème, mais il semble étrange que vous dessiniez avant que la vue ne soit attachée à la fenêtre. Que se passe-t-il si vous ajoutez ce qui suit à la fin de l'application: didFinishLaunchingWithOptions: call? '[m_view performSelector: @selector (drawView) withObject: nil afterDelay: 0.0];' –