<?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; Cocos2d for iPhone</title>
	<atom:link href="http://i.ndigo.com.br/tag/cocos2d-for-iphone/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; Camada Transparente com OpenGL ES</title>
		<link>http://i.ndigo.com.br/2010/07/cocos2d-for-iphone-0-99-4-camada-transparente-com-opengl-es/</link>
		<comments>http://i.ndigo.com.br/2010/07/cocos2d-for-iphone-0-99-4-camada-transparente-com-opengl-es/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 18:07:39 +0000</pubDate>
		<dc:creator>Raphael Petegrosso</dc:creator>
				<category><![CDATA[Go Tech]]></category>
		<category><![CDATA[Cocos2d for iPhone]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[OpenGL ES]]></category>

		<guid isPermaLink="false">http://i.ndigo.com.br/?p=182</guid>
		<description><![CDATA[Visão Geral Segundo site do Cocos2d, Cocos2d for iPhone é um framework para desenvolver jogos 2D, demos e outras aplicações gráficas/interativas. Ele é baseado no padrão cocos2d: ele usa os mesmos conceitos, mas em vez de Python ele usa Objective-C. Para os desenvolvedores do Framework, o Cocos2d for iPhone é: Fácil de usar: ele usa [...]]]></description>
			<content:encoded><![CDATA[<h3><strong>Visão Geral</strong></h3>
<p>Segundo <a href="http://www.cocos2d-iphone.org/about">site do Cocos2d</a>,  <strong>Cocos2d for iPhone</strong> é um framework para desenvolver jogos 2D, demos e outras aplicações gráficas/interativas. Ele é baseado no padrão cocos2d: ele usa os mesmos conceitos, mas em vez de Python ele usa Objective-C.</p>
<p>Para os desenvolvedores do Framework, o <strong>Cocos2d for iPhone</strong> é:</p>
<ul>
<li style="list-style: disc; margin-left: 30px;">Fácil de usar: ele usa uma API familiar e vem com uma série de exemplos</li>
<li style="list-style: disc; margin-left: 30px;">Rápido: ele usa boas práticas do OpenGL ES e otimiza estruturas de dados</li>
<li style="list-style: disc; margin-left: 30px;">Flexível: ele é fácil de ser integrado com outras bibliotecas</li>
<li style="list-style: disc; margin-left: 30px;">Grátis: é open source, compatível tanto com jogos abertos quanto fechados</li>
<li style="list-style: disc; margin-left: 30px;">Comunidade: o cocos2d tem uma comunidade ativa, grande e amigável (<a href="http://www.cocos2d-iphone.org/forum">fórum</a>, IRC)</li>
<li style="list-style: disc; margin-left: 30px;">Aprovado pela AppStore: mais de 550 jogos na AppStore o utilizam, incluindo vários jogos bem vendidos</li>
</ul>
<p>O Cocos2d vem com uma API que torna simples a criação de projetos baseados no OpenGL ES, mesmo se você não é um expert com programação em OpenGL, uma vez que tem um bom encapsulamento de algumas funcionalidades bastante usadas.</p>
<p>Um ponto negativo em usar este tipo de ferramenta é que algumas vezes você se perde quando ele automatiza algo que você não gostaria que fosse feito. Criar uma camada transparente de OpenGL ES usando o Cocos2d tem esse problema. Uma vez que muitas pessoas da comunidade tiveram esse problema, resolvemos postar sobre isso.</p>
<h3><strong>Criando uma camada transparente do OpenGL ES Layer com o Cocos2d</strong></h3>
<p>Criar uma camada transparente de OpenGL ES com o Cocos2d v 0.99.4 não foi uma tarefa simples, uma vez que seu código template contém uma Macro para inicializar uma série de variáveis internas.</p>
<p>Se você ver a macro <em>CC_DIRECTOR_INIT()</em>, localizada no arquivo <em>ccMacros.h</em>, temos o seguinte:</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>Como podemos ver, esta macro cria um <em>EAGLView</em> que tem um <em>pixelFormat</em> do tipo <em>kEAGLColorFormatRGB565</em>, que é de 16 bits. Para termos transparencia habilitada no nosso <em>EAGLView</em> precisamos criá-la com o formato <em>kEAGLColorFormatRGBA8</em>, que é de 32 bits.</p>
<p>Temos diversas formas de resolver isso, como alterar a macro ou inicializar tudo por nossa conta. O importante é certificar-se de alterar a linha:<span style="font-family: monospace;"> </span></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>para</p>
<p><span style="font-family: monospace;"> </span></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>Com isso, teremos nossa camada OpenGL ES transparente quando usando:</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>Na linha acima, o último parâmetro indica a opacidade<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>É isso! Esperamos que você goste do <strong>Cocos2d for iPhone</strong> e que esta dica lhe seja útil!</p>
<p>Este post também está disponível em inglês: <a title="Cocos2d for iPhone 0.99.4 - OpenGL ES Transparent Layer" href="http://i.ndigo.com.br/2010/07/cocos2d-for-iphone-0-99-4-opengl-es-transparent-layer">Cocos2d for iPhone 0.99.4 &#8211; OpenGL ES Transparent Layer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://i.ndigo.com.br/2010/07/cocos2d-for-iphone-0-99-4-camada-transparente-com-opengl-es/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>

