<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Indigo &#187; transparency</title>
	<atom:link href="http://i.ndigo.com.br/tag/transparency/feed/" rel="self" type="application/rss+xml" />
	<link>http://i.ndigo.com.br</link>
	<description>I.ndigo Website</description>
	<lastBuildDate>Fri, 03 Feb 2012 19:01:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Cocos2d for iPhone 0.99.4 &#8211; OpenGL ES Transparent Layer</title>
		<link>http://i.ndigo.com.br/2010/07/cocos2d-for-iphone-0-99-4-opengl-es-transparent-layer/</link>
		<comments>http://i.ndigo.com.br/2010/07/cocos2d-for-iphone-0-99-4-opengl-es-transparent-layer/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 18:07:25 +0000</pubDate>
		<dc:creator>Raphael Petegrosso</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Cocos2d for iPhone]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[transparency]]></category>

		<guid isPermaLink="false">http://i.ndigo.com.br/?p=173</guid>
		<description><![CDATA[Overview According to Cocos2d website, Cocos2d for iPhone is a framework for building 2D games, demos, and other graphical/interactive applications. It is based on the cocos2d design: it uses the same concepts, but instead of using Python it uses Objective-C. Their website says that Cocos2d for iPhone is: Easy to use: it uses a familiar [...]]]></description>
			<content:encoded><![CDATA[<h3><strong>Overview</strong></h3>
<p>According to <a href="http://www.cocos2d-iphone.org/about">Cocos2d website</a>,  <strong>Cocos2d for iPhone</strong> is a framework for building 2D games, demos, and other graphical/interactive applications. It is based on the cocos2d design: it uses the same concepts, but instead of using Python it uses Objective-C.</p>
<p>Their website says that <strong>Cocos2d for iPhone</strong> is:</p>
<ul>
<li style="list-style: disc; margin-left: 30px;">Easy to use: it uses a familiar API, and comes with lots of examples</li>
<li style="list-style: disc; margin-left: 30px;">Fast: it uses the OpenGL ES best practices and optimized data structures</li>
<li style="list-style: disc; margin-left: 30px;">Flexible: it is easy to extend, easy to integrate with 3rd party libraries</li>
<li style="list-style: disc; margin-left: 30px;">Free: is open source, compatible both with closed and open source games</li>
<li style="list-style: disc; margin-left: 30px;">Community supported: cocos2d has an active, big and friendly community (<a href="http://www.cocos2d-iphone.org/forum">forum</a>, IRC)</li>
<li style="list-style: disc; margin-left: 30px;">AppStore approved: More than 550 AppStore games already use it, including many best seller games.</li>
</ul>
<p>Cocos2d comes with an API that makes it simple to create an OpenGL ES based project, even if you are not an expert with OpenGL programming, once it has a nice encapsulation of some functionalities that are mostly used.</p>
<p>One negative point of using this kind of tool is that sometimes you get lost when it automates something that you didn&#8217;t want to be done for you. When trying to create a transparent OpenGL ES Layer with Cocos2d we saw that lot of people had this problem so we resolved to post about it.</p>
<h3><strong>Creating a Transparent OpenGL ES Layer with Cocos2d</strong></h3>
<p>Creating a transparent OpenGL ES Layer with Cocos2d v 0.99.4 was not an easy job, once its template code use a Macro to initialize a set of variables.</p>
<p>If you see the <em>CC_DIRECTOR_INIT()</em> macro, located on the <em>ccMacros.h file</em>, we have the following:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#define CC_DIRECTOR_INIT()                                                        \</span>
<span style="color: #a61390;">do</span> <span style="color: #49f;">&#123;</span>                                                                              \
                                                                                  \
    window <span style="color: #49f;">=</span> <span style="color: #49f;">&#91;</span><span style="color: #49f;">&#91;</span>UIWindow alloc<span style="color: #49f;">&#93;</span> initWithFrame<span style="color: #49f;">:</span><span style="color: #49f;">&#91;</span><span style="color: #49f;">&#91;</span>UIScreen mainScreen<span style="color: #49f;">&#93;</span> bounds<span style="color: #49f;">&#93;</span><span style="color: #49f;">&#93;</span>;     \
                                                                                  \
    <span style="color: #a61390;">if</span><span style="color: #49f;">&#40;</span> <span style="color: #49f;">!</span> <span style="color: #49f;">&#91;</span>CCDirector setDirectorType<span style="color: #49f;">:</span>kCCDirectorTypeDisplayLink<span style="color: #49f;">&#93;</span> <span style="color: #49f;">&#41;</span>               \
        <span style="color: #49f;">&#91;</span>CCDirector setDirectorType<span style="color: #49f;">:</span>kCCDirectorTypeNSTimer<span style="color: #49f;">&#93;</span>;                      \
                                                                                  \
     CCDirector <span style="color: #49f;">*</span>__director <span style="color: #49f;">=</span> <span style="color: #49f;">&#91;</span>CCDirector sharedDirector<span style="color: #49f;">&#93;</span>;                        \
     <span style="color: #49f;">&#91;</span>__director setDeviceOrientation<span style="color: #49f;">:</span>kCCDeviceOrientationPortrait<span style="color: #49f;">&#93;</span>;              \
     <span style="color: #49f;">&#91;</span>__director setDisplayFPS<span style="color: #49f;">:</span><span style="color: #a61390;">NO</span><span style="color: #49f;">&#93;</span>;                                               \
     <span style="color: #49f;">&#91;</span>__director setAnimationInterval<span style="color: #49f;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #49f;">/</span><span style="color: #2400d9;">60</span><span style="color: #49f;">&#93;</span>;                                    \
                                                                                  \
     EAGLView <span style="color: #49f;">*</span>__glView <span style="color: #49f;">=</span> <span style="color: #49f;">&#91;</span>EAGLView viewWithFrame<span style="color: #49f;">:</span><span style="color: #49f;">&#91;</span>window bounds<span style="color: #49f;">&#93;</span>                 \
                                      pixelFormat<span style="color: #49f;">:</span>kEAGLColorFormatRGB565          \
                                      depthFormat<span style="color: #49f;">:</span><span style="color: #2400d9;">0</span>                               \
                               preserveBackbuffer<span style="color: #49f;">:</span><span style="color: #a61390;">NO</span><span style="color: #49f;">&#93;</span>;                            \
                                                                                  \
     <span style="color: #49f;">&#91;</span>__director setOpenGLView<span style="color: #49f;">:</span>__glView<span style="color: #49f;">&#93;</span>;                                         \
                                                                                  \
     <span style="color: #49f;">&#91;</span>window addSubview<span style="color: #49f;">:</span>__glView<span style="color: #49f;">&#93;</span>;                                                \
     <span style="color: #49f;">&#91;</span>window makeKeyAndVisible<span style="color: #49f;">&#93;</span>;                                                  \
                                                                                  \
 <span style="color: #49f;">&#125;</span> <span style="color: #a61390;">while</span><span style="color: #49f;">&#40;</span><span style="color: #2400d9;">0</span><span style="color: #49f;">&#41;</span>;                                                                      \</pre></div></div>

<p>As we can see, this macro creates an <em>EAGLView</em> that has <em>pixelFormat</em> of type <em>kEAGLColorFormatRGB565</em>, which is 16 bits. In order to have transparency enabled in our <em>EAGLView</em> we need to create it using <em>kEAGLColorFormatRGBA8</em> format, which is 32 bits.</p>
<p>We have lot of ways to solve it, such as changing that macro or initializing everything by ourselves. The important thing is to make sure to change the line:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">EAGLView <span style="color: #49f;">*</span>__glView <span style="color: #49f;">=</span> <span style="color: #49f;">&#91;</span>EAGLView viewWithFrame<span style="color: #49f;">:</span><span style="color: #49f;">&#91;</span>window bounds<span style="color: #49f;">&#93;</span>                      \
                                 pixelFormat<span style="color: #49f;">:</span>kEAGLColorFormatRGB565               \
                                 depthFormat<span style="color: #49f;">:</span><span style="color: #2400d9;">0</span>                                    \
                          preserveBackbuffer<span style="color: #49f;">:</span><span style="color: #a61390;">NO</span><span style="color: #49f;">&#93;</span>;                                 \</pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">EAGLView <span style="color: #49f;">*</span>__glView <span style="color: #49f;">=</span> <span style="color: #49f;">&#91;</span>EAGLView viewWithFrame<span style="color: #49f;">:</span><span style="color: #49f;">&#91;</span>window bounds<span style="color: #49f;">&#93;</span>                      \
                                 pixelFormat<span style="color: #49f;">:</span>kEAGLColorFormatRGBA8                \
                                 depthFormat<span style="color: #49f;">:</span><span style="color: #2400d9;">0</span>                                    \
                          preserveBackbuffer<span style="color: #49f;">:</span><span style="color: #a61390;">NO</span><span style="color: #49f;">&#93;</span>;                                 \</pre></div></div>

<p>So, we will have a transparent layer when using:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">glClearColor<span style="color: #49f;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #49f;">&#41;</span>;</pre></div></div>

<p>In the above line, the last parameter indicates the opacity.<br />
(<a href="http://www.khronos.org/opengles/sdk/1.1/docs/man/">http://www.khronos.org/opengles/sdk/1.1/docs/man/</a>).</p>
<p>So that&#8217;s it! We hope you enjoy <strong>Cocos2d for iPhone</strong> and this tip helps you!</p>
<p>This post is also available in Portuguese: <a title="Cocos2d for iPhone 0.99.4 - Camada Transparente com OpenGL ES" href="http://i.ndigo.com.br/2010/07/cocos2d-for-iphone-0-99-4-camada-transparente-com-opengl-es">Cocos2d for iPhone 0.99.4 &#8211; Camada Transparente com OpenGL ES</a></p>
]]></content:encoded>
			<wfw:commentRss>http://i.ndigo.com.br/2010/07/cocos2d-for-iphone-0-99-4-opengl-es-transparent-layer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

