Hi guys.
I have here some trouble wih opengl es. I
dont want to use a xib file so I changed main() to use my defined AppDelegate.
Code:
int retVal = UIApplicationMain(argc, argv, nil, @"GameAppDelegate");
In my GameAppDelegate I create a window and a glview:
Code:
// create window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// create view
glview = [[eglView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window addSubview:glview];
// show window
[window makeKeyAndVisible];
Now you are want to see some source of the eglView

Here they are:
Code:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#include <OpenGLES/ES1/gl.h>
#include <renderer/OglEsGlue.h>
/*
This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
The view content is basically an EAGL surface you render your OpenGL scene into.
Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
*/
@interface eglView : UIView {
@private
GLint backingWidth;
GLint backingHeight;
EAGLContext *context;
GLuint viewRenderbuffer, viewFramebuffer;
GLuint depthRenderbuffer;
}
Code:
#include "OglEsView.h"
#include "OpenGLES/ES1/glext.h"
static id g_context;
static int g_frame;
static int g_render;
// A class extension to declare private methods
@interface eglView ()
@property (nonatomic, retain) EAGLContext *context;
- (BOOL) createFramebuffer;
- (void) destroyFramebuffer;
@end
@implementation eglView
@synthesize context;
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
- (id) initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if ( self != nil )
{
// Get the layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = YES;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context]) {
[self release];
return nil;
}
// store context, so that it is possible to acces it from c/c++
g_context = context;
// init framebuffers
[self createFramebuffer];
}
return self;
}
- (BOOL) createFramebuffer {
glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);
// store for c/c++ access
g_render = viewRenderbuffer;
g_frame = viewFramebuffer;
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
return YES;
}
- (void) destroyFramebuffer {
glDeleteFramebuffersOES(1, &viewFramebuffer);
viewFramebuffer = 0;
glDeleteRenderbuffersOES(1, &viewRenderbuffer);
viewRenderbuffer = 0;
glDeleteRenderbuffersOES(1, &depthRenderbuffer);
depthRenderbuffer = 0;
}
- (void) dealloc
{
[self destroyFramebuffer];
if ([EAGLContext currentContext] == context) {
[EAGLContext setCurrentContext:nil];
}
[context release];
[super dealloc];
}
@end
void makeCurrent()
{
[EAGLContext setCurrentContext:g_context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, g_frame);
}
void swapBuffers()
{
glBindRenderbufferOES(GL_RENDERBUFFER_OES, g_render);
[g_context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
So I should now have a window with my eglview. This seems to work. Now if I do something like:
Code:
void cIntroState::Render()
{
makeCurrent();
glClearColor(1.0, 0.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
swapBuffers();
}
Nothing happens... screen stays black... but it should have an other color then black - see glClearColor.
it would be very cool, if someone could help me.
ac