Dieses Dokuwiki verwendet ein von Anymorphic Webdesign erstelltes Thema.

You can easily use cocos2d to render Open GL content with a transparent background on UIKit views. The most common use for this type of behaviour would be to implement Augemented Reality applications which display an overlay view on top of the camera using UIImagePickerController.

Just open CCDirector.m and look for the selector [CCDirector initGLDefaultValues]. Here's the code you can use to make the EAGLView render a transparent background:

-(void) initGLDefaultValues
{
	// This method SHOULD be called only after openGLView_ was initialized
	NSAssert( openGLView_, @"openGLView_ must be initialized");

	[self setAlphaBlending: YES];
	[self setDepthTest: YES];
	[self setProjection: CCDirectorProjectionDefault];
	
	// ***** NEW CODE: make open gl view transparent
	openGLView_.opaque = NO;
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	// disable regular, opaque clear color
	//glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        // ***** NEW CODE end
	
	
#if CC_DIRECTOR_FAST_FPS
    if (!FPSLabel)
        FPSLabel = [[CCLabelAtlas labelAtlasWithString:@"00.0" charMapFile:@"fps_images.png" 
itemWidth:16 itemHeight:24 startCharMap:'.'] retain];
#endif	
}

As riq correctly pointed out, you can also make these adjustments outside of CCDirector by obtaining a reference to the EAGLView via [CCDirector openGLView] and setting its opaque property.

tips/director_transparentview.txt · Last modified: 2010/04/22 20:56 by bebroll
Trace: tips 0_99_2 2_0_0 code_snippets migrate_to_v2.0 0_8_rc 0_8_rc2 1_1_0 lesson_1._install_test director_transparentview
Dieses Dokuwiki verwendet ein von Anymorphic Webdesign erstelltes Thema.
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0