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-26-2010, 10:00 AM   #1 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 9
Default Issues with multithread and opengl for loading textures

Hi everyone !

I'm trying to use sharegroup to load textures in Background, but i have some issues. I use the myEAGLView from CrashLanding sample. Textures are loaded, but when i use them, it's just white on the screen with this recurrent message on gdb : Failed to swap renderbuffer in -[MyEAGLView swapBuffers]
I use my device to test my app.

Here is some code :

Code:
// viewDidLoad of my rootViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadArcadeViewController];
// add ActivityIndicator
    [arcadeViewController performSelectorInBackground:@selector(loadImages:) withObject:self];
}
With a classic load of viewController :
Code:
- (void) loadArcadeViewController {
	ArcadeViewController *viewController = [[ArcadeViewController alloc] initWithNibName:@"ArcadeViewController" bundle:nil];
	self.arcadeViewController = viewController;
	[viewController release];
}
initWithNIBName for ArcadeViewController
Code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {

		NSBundle*				bundle = [NSBundle mainBundle];

		CGRect					rect = [[UIScreen mainScreen] bounds];	

		FarWestAppDelegate *appDelegate = (FarWestAppDelegate*)[[UIApplication sharedApplication] delegate];
		glView = [appDelegate.eaglView retain];
		[self.view addSubview:glView];
		//Set up OpenGL projection matrix

		glMatrixMode(GL_PROJECTION);

		// on dimensionne la taille de la zone de dessin
		glOrthof(-rect.size.width / 2.0f, rect.size.width / 2.0f, -rect.size.height / 2, rect.size.height / 2, -10.0f, 10.0f);
		// on fait une rotation de 90° pour gérer le mode portrait
		glRotatef(kOrientationAngle, 0, 0, 1);
		// on se translate pour mettre l'origine en bas à droite
                glTranslatef(-rect.size.height / 2.0f, -rect.size.width / 2, 0.0);

		glMatrixMode(GL_MODELVIEW);
    }

    return self;

}
Then my method loadImages from ArcadeViewController (i use a singleton to manage my textures :
Code:
- (void) loadImages:(id)sender {

	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

	myGlobal = [GameGlobals globalInstance:sender];

	[pool release];

}
And to conclude :
Code:
+ (GameGlobals*)globalInstance:(id)sender {

	static GameGlobals *globalInstance;	

	@synchronized(self) {

		if(!globalInstance) {

			globalInstance = [[GameGlobals alloc] initWithSender:(id)sender];

		}

	}

	return globalInstance;

}


- (id) initWithSender:(id)sender {

	self.dictionaryOfTexture = [[NSMutableDictionary alloc] init];


	NSMutableArray *arrayOfText = [[NSMutableArray alloc] init];


	FarWestAppDelegate *appDelegate = (FarWestAppDelegate*)[[UIApplication sharedApplication] delegate];

	// i use shareGroup
	EAGLContext *secondContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:[appDelegate.eaglView._context sharegroup]];

	[EAGLContext setCurrentContext:secondContext];

	glMatrixMode(GL_MODELVIEW);

	

	//Initialize OpenGL states

	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

	glEnable(GL_TEXTURE_2D);

	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	glEnableClientState(GL_VERTEX_ARRAY);

	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	

	//Load the background texture and configure it

	_textures[kTexture_Background] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"fond.png"]];

	glBindTexture(GL_TEXTURE_2D, [_textures[kTexture_Background] name]);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	

	// Load the textures (maybe that's not the better solution i'm aware of this)

	_textures[kTexture_Batiment] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"batiment_Ext.png"]];

	_textures[kTexture_Balcon] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"balcon.png"]];

	_textures[kTexture_Devanture] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"devanture.png"]];

	_textures[kTexture_Cactus_Troncs] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"cactus-troncs.png"]];

	_textures[kTexture_Cactus_Gauche] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"cactus1.png"]];

	_textures[kTexture_Cactus_Droit] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"cactus2.png"]];

	_textures[kTexture_Pierre] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"pierre.png"]];

	_textures[kTexture_Enseigne] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"enseigne.png"]];

	_textures[kTexture_Menu] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"saloonIntro.jpg"]];

	_textures[kTexture_GameOver] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"gameOver.jpg"]];



	for (int i = 0 ; i < kNumTexturesScene ; i ++)

	{
		[arrayOfText addObject:[[[NSData alloc] init] autorelease]];	
	}

	

	for (int i = 0 ; i < kNumTexturesScene ; i ++)

	{
		[arrayOfText replaceObjectAtIndex:i withObject:_textures[i]];

	}

	

	[dictionaryOfTexture setObject:[arrayOfText copy] forKey:kTextureDecor];

	[arrayOfText removeAllObjects];

	

	// and so on until these lines

	NSLog(@"* %d", [appDelegate.eaglView isCurrentContext]);	
// -> the context is not _context

	[secondContext release];

	[EAGLContext setCurrentContext:appDelegate.eaglView._context];

	NSLog(@"* %d", [appDelegate.eaglView isCurrentContext]);	
// -> the context is _context

if([sender isKindOfClass:[RootViewController class]])

{

	RootViewController *root = (RootViewController*)sender;

	[root performEndOfLoading];

}

	return self;

}
Just to be sure we have the same EAGLView :
Code:
//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:

- (id)initWithCoder:(NSCoder*)coder {

	

	if ((self = [super initWithCoder:coder])) {

		CAEAGLLayer *eaglLayer = (CAEAGLLayer*)[self layer];

		

		[eaglLayer setDrawableProperties:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGB565, kEAGLDrawablePropertyColorFormat, nil]];

		_format = kEAGLColorFormatRGB565;

		_depthFormat = 0;

		

		self._context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];

		[EAGLContext setCurrentContext:_context];



		if(_context == nil) {

			[self release];

			return nil;

		}

		

		if(![self _createSurface]) {

			[self release];

			return nil;

		}

	}

	

	return self;

}
So i can't understand why this is not working ?

Thanks !

See you
ipodishima is offline   Reply With Quote
Old 03-12-2010, 04:07 PM   #2 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 20
Default

bump...

I am having the same problem...
bluelobster is offline   Reply With Quote
Reply

Bookmarks

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
» Stats
Members: 158,485
Threads: 89,094
Posts: 380,133
Top Poster: BrianSlick (7,091)
Welcome to our newest member, janice23
Powered by vBadvanced CMPS v3.1.0

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