Hello all,
I am working on getting the particle generator from http://forum.sparrow-framework.org/topic/particle-system#post-240 working with sparrow. Because I don't need deep integration (touch ect.) only visuals and my OpenGL is very bad my hope was that I could just add another subview to the window in the Application Delegate. Unfortunately it doesn't quite work. When the game is run I end up with a solid black screen. I know it has something to do with how the OpenGL environment is being setup, but Im not seeing it. Any ideas would be greatly appreciated.
ApplicaitonDelegate.h
@interface ApplicationDelegate : NSObject <UIApplicationDelegate>
{
@private
UIWindow *mWindow;
SPView *mSparrowView;
EAGLView *glView;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet EAGLView *glView;
ApplicationDelegate.m
@implementation ApplicationDelegate
@synthesize window;
@synthesize glView;
- (id)init
{
if (self = [super init])
{
mWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
mSparrowView = [[SPView alloc] initWithFrame:mWindow.bounds];
window = mWindow;
glView = [[EAGLView alloc] initWithFrame:mWindow.bounds];;
glView.opaque = YES;
glView.alpha = 1.0f;
glView.hidden = NO;
glView.backgroundColor = [UIColor clearColor];
[mWindow addSubview:mSparrowView];
[mWindow addSubview:glView];
}
return self;
}
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
SP_CREATE_POOL(pool);
[SPStage setSupportHighResolutions:YES];
[SPAudioEngine start];
Game *game = [[Game alloc] init];
mSparrowView.stage = game;
[game release];
[mWindow makeKeyAndVisible];
[mSparrowView start];
SP_RELEASE_POOL(pool);
[glView startAnimation];
}
@end
From EAGLView setup calls:
- (id)init
{
if ((self = [super init]))
{
NSLog(@"inited");
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context])
{
[self release];
return nil;
}
// Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
glGenFramebuffersOES(1, &defaultFramebuffer);
glGenRenderbuffersOES(1, &colorRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);
[self initOpenGLES];
////////////////////////
// Create a particle emitter instance.
pe = [[ParticleEmitter alloc] initParticleEmitterWithFile:@"queenbee.pex"];
}
GLint iErr = glGetError();
if (iErr != GL_NO_ERROR)
{
NSLog(@"GL error: %d (0x%x)", iErr, iErr);
}
return self;
}
- (void)initOpenGLES {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
CGRect bounds = [[UIScreen mainScreen] bounds];
glOrthof(0, bounds.size.width, 0, bounds.size.height, -1, 1);
// Set the viewport
glViewport(0, 0, bounds.size.width, bounds.size.height);
// Switch to GL_MODELVIEW so we can now draw our objects
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Setup the texture environment and blend functions.
// This controls how a texture is blended with other textures
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ALPHA);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Set the colour to use when clearing the screen with glClear
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// We are not using the depth buffer in our 2D game so depth testing can be disabled. If depth
// testing was required then a depth buffer would need to be created as well as enabling the depth
// test
glDisable(GL_DEPTH_TEST);
// Enable the OpenGL states we are going to be using when rendering
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
GLint iErr = glGetError();
if (iErr != GL_NO_ERROR)
{
NSLog(@"GL error: %d (0x%x)", iErr, iErr);
}
}
Thanks again for your input!