Я запускаю новый проект opengles из xcode 4 и удаляю все ссылки и вызовы ES2 (я хочу использовать код рисования ES1).Мой пример проекта отлично работает на iphone 4, но не работает на iphone 3g и ipod 2-го поколения.Вот мой модифицированный код:
EAGLView.m
#import <QuartzCore/QuartzCore.h>
#import "EAGLView.h"
@interface EAGLView (PrivateMethods)
- (void)createFramebuffer;
- (void)deleteFramebuffer;
@end
@implementation EAGLView
@synthesize context;
// You must implement this method
+ (Class)layerClass
{
return [CAEAGLLayer class];
}
//The EAGL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:.
- (id)initWithCoder:(NSCoder*)coder
{
self = [super initWithCoder:coder];
if (self) {
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = TRUE;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
nil];
}
return self;
}
- (void)dealloc
{
[self deleteFramebuffer];
[context release];
[super dealloc];
}
- (void)setContext:(EAGLContext *)newContext
{
if (context != newContext) {
[self deleteFramebuffer];
[context release];
context = [newContext retain];
[EAGLContext setCurrentContext:nil];
}
}
- (void)createFramebuffer
{
if (context && !defaultFramebuffer) {
[EAGLContext setCurrentContext:context];
// Create default framebuffer object.
glGenFramebuffersOES(1, &defaultFramebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
// Create color render buffer and allocate backing store.
glGenRenderbuffersOES(1, &colorRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer *)self.layer];
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &framebufferWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &framebufferHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
}
}
- (void)deleteFramebuffer
{
if (context) {
[EAGLContext setCurrentContext:context];
if (defaultFramebuffer) {
glDeleteFramebuffersOES(1, &defaultFramebuffer);
defaultFramebuffer = 0;
}
if (colorRenderbuffer) {
glDeleteRenderbuffersOES(1, &colorRenderbuffer);
colorRenderbuffer = 0;
}
}
}
- (void)setFramebuffer
{
if (context) {
[EAGLContext setCurrentContext:context];
if (!defaultFramebuffer)
[self createFramebuffer];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
glViewport(0, 0, framebufferWidth, framebufferHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, framebufferWidth, framebufferHeight, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
}
- (BOOL)presentFramebuffer
{
BOOL success = FALSE;
if (context) {
[EAGLContext setCurrentContext:context];
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
success = [context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
return success;
}
- (void)layoutSubviews
{
// The framebuffer will be re-created at the beginning of the next setFramebuffer method call.
[self deleteFramebuffer];
}
@end
testViewController.m
#import "testAppDelegate.h"
#import "testViewController.h"
#import "EAGLView.h"
// Uniform index.
enum {
UNIFORM_TRANSLATE,
NUM_UNIFORMS
};
GLint uniforms[NUM_UNIFORMS];
// Attribute index.
enum {
ATTRIB_VERTEX,
ATTRIB_COLOR,
NUM_ATTRIBUTES
};
@interface testViewController ()
@property (nonatomic, retain) EAGLContext *context;
@property (nonatomic, assign) CADisplayLink *displayLink;
@end
@implementation PyrotexniViewController
@synthesize animating, context, displayLink;
- (void)awakeFromNib
{
EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!aContext)
NSLog(@"Failed to create ES context");
else if (![EAGLContext setCurrentContext:aContext])
NSLog(@"Failed to set ES context current");
self.context = aContext;
[aContext release];
[(EAGLView *)self.view setContext:context];
[(EAGLView *)self.view setFramebuffer];
animating = FALSE;
animationFrameInterval = 1;
self.displayLink = nil;
- (void)dealloc
{
// Tear down context.
if ([EAGLContext currentContext] == context)
[EAGLContext setCurrentContext:nil];
[context release];
[EAGLView dealloc];
[self stopAnimation];
[super dealloc];
}
- (NSInteger)animationFrameInterval
{
return animationFrameInterval;
}
- (void)setAnimationFrameInterval:(NSInteger)frameInterval
{
if (frameInterval >= 1) {
animationFrameInterval = frameInterval;
if (animating) {
[self stopAnimation];
[self startAnimation];
}
}
}
- (void)startAnimation
{
if (!animating) {
CADisplayLink *aDisplayLink = [[UIScreen mainScreen] displayLinkWithTarget:self selector:@selector(drawFrame)];
[aDisplayLink setFrameInterval:animationFrameInterval];
[aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
self.displayLink = aDisplayLink;
animating = TRUE;
}
}
- (void)stopAnimation
{
if (animating) {
[self.displayLink invalidate];
self.displayLink = nil;
animating = FALSE;
}
}
- (void)drawFrame
{
[(EAGLView *)self.view setFramebuffer];
......draw code here.....
[(EAGLView *)self.view presentFramebuffer];
}
, основанный на этой схеме проекта, которая должна работать на устройствах opengles 1.1, нонет (этот код работает только на iphone4)!что здесь не так?Помогите мне, пожалуйста.Спасибо.