Я только начинаю узнавать об OpenGL ES на iPhone. Я пытаюсь получить очень простой пример работы, который устанавливает EAGLContext и буфер рендеринга, а затем просто использует glClearColor для установки цвета экрана.
Мой код компилируется и выполняется, но, к сожалению, вместо ожидаемого серого экрана я вижу белое изображение со случайным шаблоном искажения. Я предполагаю, что я не все правильно настроил, и надеюсь, что моя ошибка будет очевидна для кого-то с небольшим опытом в этой области.
Мой код:
AppDelegate.h
#import "GLView.h"
#import <UIKit/UIKit.h>
@interface AppDelegate : NSObject <UIApplicationDelegate> {
@private
UIWindow* m_window;
GLView* m_view;
}
@end
AppDelegate.m
#import "AppDelegate.h"
#import "AppDelegate.h"
#import "GLView.h"
@implementation AppDelegate
- (void) applicationDidFinishLaunching: (UIApplication*) application
{
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];
}
- (void) dealloc
{
[m_view release];
[m_window release];
[super dealloc];
}
@end
GLView.h
#import <QuartzCore/QuartzCore.h>
@interface GLView : UIView {
@private
EAGLContext* m_context;
}
- (void) drawView;
@end
GLView.mm
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#import "GLView.h"
@implementation GLView
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//Set up the layer and context
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;
}
// Create & bind the color buffer so that the caller can allocate its space.
GLuint renderbuffer;
glGenRenderbuffersOES(1, &renderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderbuffer);
[m_context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer];
glViewport(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame));
[self drawView];
}
return self;
}
- (void)drawView
{
glClearColor(0.5f,0.5f,0.5f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
[m_context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
- (void) dealloc
{
if([EAGLContext currentContext] == m_context)
[EAGLContext setCurrentContext:nil];
[m_context release];
[super dealloc];
}
Большое спасибо за любую помощь.