Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-08-2009, 12:07 PM   #1 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 2
Default OpenGL Es Init probelm.

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
austriancoder is offline   Reply With Quote
Old 01-08-2009, 01:42 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Unhappy

Your OpenGL and drawing code looks tip-top; I pasted it into the GLSprite example, and it works fine (pink background.) Maybe there's something wrong with the changes you made to eliminate the .xib file - I tried to integrate those changes into the same project, and got nothing but a white screen.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-08-2009, 02:03 PM   #3 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 2
Default

I think I will switch back to the xib file as time is running out and this problem needs to be fixed now. Maybe I will find time later to find a fix.
Oh.. in GLSprite i also get a white screen
austriancoder is offline   Reply With Quote
Old 02-06-2009, 11:48 AM   #4 (permalink)
New Member
 
Join Date: Feb 2009
Posts: 2
Default

Quote:
Originally Posted by austriancoder View Post
I think I will switch back to the xib file as time is running out and this problem needs to be fixed now. Maybe I will find time later to find a fix.
Oh.. in GLSprite i also get a white screen
I've been trying to get this to work as well and get the same results. I think that the xib might be doing some voodoo to make it work.
billyzelsnack is offline   Reply With Quote
Old 02-10-2009, 10:43 AM   #5 (permalink)
New Member
 
Join Date: Feb 2009
Location: Bucharest
Posts: 1
Default

Did you look at GLPaint sample? It's not using .xib and inits OpenGL ES. I'm using that as a startup point and it works
fili is offline   Reply With Quote
Old 02-10-2009, 10:55 AM   #6 (permalink)
New Member
 
Join Date: Feb 2009
Posts: 2
Default

Quote:
Originally Posted by fili View Post
Did you look at GLPaint sample? It's not using .xib and inits OpenGL ES. I'm using that as a startup point and it works
I did not. I'll go look at it now. Thanks for the heads-up.
billyzelsnack is offline   Reply With Quote
Reply

Bookmarks

Tags
opengl es

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 316
20 members and 296 guests
ADY, Alsahir, Dani77, e2applets, iph_s, JasonR, keeshux, mer10, Monstertaco, piesia, prchn4christ, Promo Dispenser, Robiwan, Rudy, sebasx, sly24, Touchmint, twerner
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,759
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0