<?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>AndroGeek</title>
	<atom:link href="http://androgeek.info/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://androgeek.info</link>
	<description>Android Programming &#38; News</description>
	<lastBuildDate>Fri, 10 Jun 2011 16:10:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Android NDK r5c now available</title>
		<link>http://androgeek.info/?p=374</link>
		<comments>http://androgeek.info/?p=374#comments</comments>
		<pubDate>Fri, 10 Jun 2011 16:09:57 +0000</pubDate>
		<dc:creator>Bill Hsu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[available]]></category>
		<category><![CDATA[NDK]]></category>
		<category><![CDATA[r5c]]></category>

		<guid isPermaLink="false">http://androgeek.info/?p=374</guid>
		<description><![CDATA[Android NDK r5c is now publicly available at the usual URL: http://developer.android.com/sdk/ndk/index.html This release only contains bug-fixes, there are no new APIs or features. See below for the corresponding change log. The most important things, being: - no more crashes of code linked to gnustl_static on Eclair and older platforms. - gdbserver no longer crashes [...]]]></description>
			<content:encoded><![CDATA[<p>Android NDK r5c is now publicly available at the usual URL: http://developer.android.com/sdk/ndk/index.html</p>
<p>This release only contains bug-fixes, there are no new APIs or features.<br />
See below for the corresponding change log. The most important things, being:</p>
<p>- no more crashes of code linked to gnustl_static on Eclair and older platforms.<br />
- gdbserver no longer crashes on Honeycomb devices like the Motorola Xoom</p>
<p><strong>Android NDK ChangeLog:</strong></p>
<p>----------------------------------------------------------------<br />
android-ndk-r5c</p>
<p>This release fixes a few bugs in r5b. There are no new features.</p>
<p><strong>IMPORTANT BUG FIXES:</strong><br />
<span id="more-374"></span><br />
- Fixed a typo that prevented LOCAL_WHOLE_STATIC_LIBRARIES to work correctly  with the new toolchain. Also properly document this variable in  docs/ANDROID-MK.html.</p>
<p>- Fixed a bug where code linked against gnustl_static would crash when run  on Android platform releases older than 2.2.</p>
<p>- : Two functions in this header file, introduced  by API level 9 (a.k.a. 2.3) were incorrect and have been fixed. While  this breaks the source API, the binary interface to the system is  unchanged.</p>
<p>The functions missing a third 'history_index' parameter. They correct  definition is now:</p>
<p>float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event,<br />
size_t pointer_index,<br />
size_t history_index);</p>
<p>float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event,<br />
size_t pointer_index,<br />
size_t history_index);</p>
<p>- Updated the android-9 C library arm binary to correctly expose at link time  new functions that were added to it in Gingerbread (e.g. pthread_rwlock_init).</p>
<p>- Fixed a bug that made gdbserver crash on misc. Honeycomb devices (e.g.  the Motorola Xoom).</p>
<p><strong>OTHER FIXES &amp; CHANGES:</strong></p>
<p>- Object files are now always linked in the order they appear in  LOCAL_SRC_FILES. This was not the case previously because the files  were grouped by source extensions instead.</p>
<p>- download-toolchain-sources.sh: Fixed a silly bug that prevented the  --git-date option to work properly when downloading the master branch.</p>
<p>- Fix an issue where a module could import itself, resulting in an infinite  loop in GNU Make.</p>
<p>- When import-module fails, it now prints the list of directories  that were searched. This is useful to check that the NDK_MODULE_PATH  definition used by the build system is correct.</p>
<p>- When import-module succeeds, it now prints the directory where the module  was found to the log (visible with NDK_LOG=1).</p>
<p>-<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; white-space: pre;">&lt;pthread.h&gt;</span>: Fixed the definition of PTHREAD_RWLOCK_INITIALIZER for  android-9 API level and higher.</p>
<p>- Fixed a bug where LOCAL_ARM_NEON was defined to true would make the build  fail (typo in build/core/build-binary.mk)</p>
<p>- Fixed a bug that prevented the compilation of .s assembly files  (.S files were ok).</p>
<p>- Speed-up the build of debuggable applications when there is a very  large number of include directories in a project.</p>
<p>- ndk-gdb: Better detection of 'adb shell' failures (improves error messages).</p>
<p>- ndk-build: Fix a rare bug that appeared when trying to perform parallel  builds of debuggable projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://androgeek.info/?feed=rss2&#038;p=374</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>“Debug certificate expired” error in eclipse android plugins</title>
		<link>http://androgeek.info/?p=367</link>
		<comments>http://androgeek.info/?p=367#comments</comments>
		<pubDate>Wed, 11 May 2011 10:31:27 +0000</pubDate>
		<dc:creator>Bill Hsu</dc:creator>
				<category><![CDATA[Android Programming]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[certificate expired]]></category>
		<category><![CDATA[eclipse]]></category>

		<guid isPermaLink="false">http://androgeek.info/?p=367</guid>
		<description><![CDATA[I opened my eclipse today and get a error saying: Error generating final archive:Debug certificate expired on ... After searching on Google, this post(http://stackoverflow.com/questions/2194808/debug-certificate-expired-error-in-eclipse-android-plugins)helps a lot. Upon installation, the Android SDK generates a "debug" signing certificate for you in a keystore called debug.keystore. The Eclipse plug-in uses this certificate to sign each application build that [...]]]></description>
			<content:encoded><![CDATA[<p>I opened my eclipse today and get a error saying:</p>
<blockquote><p>Error generating final archive:Debug certificate expired on ...</p></blockquote>
<p>After searching on Google, this post(<a href="http://stackoverflow.com/questions/2194808/debug-certificate-expired-error-in-eclipse-android-plugins" target="_blank">http://stackoverflow.com/questions/2194808/debug-certificate-expired-error-in-eclipse-android-plugins</a>)helps a lot.</p>
<blockquote><p>Upon installation, the Android SDK generates a "debug" signing certificate for you in a keystore called debug.keystore. The Eclipse plug-in uses this certificate to sign each application build that is generated.</p>
<p>Unfortunately a debug certificate is only valid for 365 days. To generate a new one you must delete the existing debug.keystore file.</p></blockquote>
<p>For Linux user: Delete your debug certificate (debug.keystore and ddms.cfg) under ~/.android/debug.keystore</p>
<p>For Windows user: Delete your debug certificate (debug.keystore and ddms.cfg)  under C:\Documents and Settings\Administrator\.android</p>
]]></content:encoded>
			<wfw:commentRss>http://androgeek.info/?feed=rss2&#038;p=367</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>found a powerful calculator handyCalc</title>
		<link>http://androgeek.info/?p=357</link>
		<comments>http://androgeek.info/?p=357#comments</comments>
		<pubDate>Wed, 23 Mar 2011 07:10:23 +0000</pubDate>
		<dc:creator>Bill Hsu</dc:creator>
				<category><![CDATA[Android APPs]]></category>
		<category><![CDATA[calculator]]></category>
		<category><![CDATA[handyCalc]]></category>

		<guid isPermaLink="false">http://androgeek.info/?p=357</guid>
		<description><![CDATA[There are many calculator apps in Android Market. Maybe RealCalc is most famous, but actually I don't think RealCalc is a good one because it doesn't support Regular Expressions. Recently while I was browsing in the Android Market, I found a powerful calculator handyCalc. Followings are the introductions of handyCalc from it's website http://handycalc.wordpress.com/ ------------------------------------- [...]]]></description>
			<content:encoded><![CDATA[<p>There are many calculator apps in Android Market. Maybe RealCalc is most famous, but actually I don't think RealCalc is a good one because it doesn't support Regular Expressions.<br />
Recently while I was browsing in the Android Market, I found a powerful calculator handyCalc.<br />
<img class="alignnone size-full wp-image-358" title="2593633778_354ca7b1c9_o" src="http://androgeek.info/wp-content/uploads/2011/03/2593633778_354ca7b1c9_o.png" alt="" width="320" height="456" /></p>
<p>Followings are the introductions of handyCalc from it's website <a href="http://handycalc.wordpress.com/" target="_blank">http://handycalc.wordpress.com/</a></p>
<p>-------------------------------------</p>
<p>handyCalc is first be designed a symbolic calculate system to handle some complicated mathematica features. You can:</p>
<p>* Solve equation and equation set<br />
* Define variables<br />
* Define your own functions<br />
* Plot graph</p>
<p><span id="more-357"></span></p>
<h1>Solve equations</h1>
<p>The most common situation is solve one equation with one symbol. For  example, x+1=2. Of course you know what x is. So let’s try something.</p>
<p><a title="calc_eq_1 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2410021930/"><img src="http://farm3.static.flickr.com/2378/2410021930_09a3e7a910_o.png" alt="calc_eq_1" width="320" height="320" /></a></p>
<p>Notice that there is a equals inside that expression. Don’t press  your big equals button on your keypad. Flip to the next keypad and there  is a smaller equals.</p>
<p><a title="keypad_2 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2409196509/"><img src="http://farm3.static.flickr.com/2064/2409196509_068ac4b764_o.png" alt="keypad_2" width="320" height="180" /></a></p>
<p>There are two equals on your second keypad. They are different. The  big one means “Solve it and give me the answer”. While the smaller one  is the real equals. It gives you a “=” on your input. And that is  essential to solve equations.</p>
<p>Now after you input your equation, just press the big equals button. The result will be shown directly.</p>
<p>Try another.</p>
<p><a title="equation_v03_4 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2593749498/"><img src="http://farm4.static.flickr.com/3243/2593749498_39240de9cb_o.png" alt="equation_v03_4" width="320" height="213" /></a></p>
<p>This equation is more complicated than the first one. handyCalc use a  method based on Newton method to find it’s root (since v0.3). But as  you see, there is a chance that some roots are left behind. In such  cases, you can just click the “Show graph and explicit root area” and  aim at the cross point of two graphs as shown below. handyCalc will find  the most nearest root as you give.</p>
<p><a title="equation_v03_2 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2593633778/"><img src="http://farm4.static.flickr.com/3238/2593633778_354ca7b1c9_o.png" alt="equation_v03_2" width="320" height="456" /></a></p>
<p>Okay, now let’s try some equation sets.</p>
<p><a title="equation_v03_3 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2593633784/"><img src="http://farm4.static.flickr.com/3134/2593633784_daf09d0b29_o.png" alt="equation_v03_3" width="320" height="456" /></a></p>
<p>Notice you have three lines, each line contains one equation. Goto a  newline by press the return button on the second keypad or return key on  your keyboard. And again, when you finish input, press the equals to  solve it.<br />
<a name="variables"></a></p>
<h1>Variables</h1>
<p>Variable is a symbol that you store a value in it. Like the [M+]  function on most calculators. The “ans” mentioned in Basic tutorial is a  variable, too.</p>
<p>With variables, you can do a lot of things in an easier way.</p>
<p><a title="calc_with_var_1 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2410021480/"><img src="http://farm3.static.flickr.com/2284/2410021480_aee4bd951e_o.png" alt="calc_with_var_1" width="320" height="320" /></a></p>
<p>It’s the Einstein’s famous formula. The first line define the  variable m, and the second line define the variable c. c is a constant  of light speed in m/s. You probably do not change it. m is the mess.  Each time I want to change the mess, I just have to go to the first  line, and change it instead of change the formula in the third line.  Notice that there is a forth line with a single symbol E. that means  just output the E as the answer. Of course you can delete it,  but the  handyCalc will output every single variable you have defined which is  not what you want at this time.</p>
<p>The variable will be existed even you flip to the next page or a  previous page. But how to remove that variable? Two ways, you can go to  the Document menu and press [New], and you get a new document. And you  can go to the Tools menu and press [Variable &amp; Function].</p>
<p><a title="var_1 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2409196905/"><img src="http://farm3.static.flickr.com/2287/2409196905_b768e6a2b0_o.png" alt="var_1" width="320" height="456" /></a></p>
<p>And you have all your variables.</p>
<p><a title="var_2 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2409196773/"><img src="http://farm4.static.flickr.com/3251/2409196773_bd0fde175e_o.png" alt="var_2" width="320" height="456" /></a></p>
<p>The [x] icon on the rightside means it’s a variable, and the F(x) icon means it’s a function you defined.<br />
<a name="functions"></a></p>
<h1>Functions</h1>
<p>You can define your own functions. It’s similar with define a variable. Let’s try it.</p>
<p><a title="calc_with_var_2 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2410021556/"><img src="http://farm4.static.flickr.com/3039/2410021556_c80cedcf19_o.png" alt="calc_with_var_2" width="320" height="213" /></a></p>
<p>It’s a physics formula which calculate the speed when an object fall  from h meters height and hit the ground. The g(gravity)=9.8, and V(3)  give you the speed when it’s fall from 3 meters height.</p>
<p>And now you have the V(h) function, and you have the  acceleration(g=9.8). You can make a T(h) function which calculate how  many time it takes to fall to the ground from h meters height.</p>
<p><a title="calc_with_var_3 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2409189525/"><img src="http://farm4.static.flickr.com/3226/2409189525_d1e1ce95b8_o.png" alt="calc_with_var_3" width="320" height="212" /></a></p>
<p>Simple and powerful, isn’t it.<br />
<a name="graph"></a></p>
<h1>Graph</h1>
<p>Graph is easy in handyCalc. Just type your expression and there will be a [Draw graph] below.</p>
<p><a title="graph_2 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2446275806/"><img src="http://farm4.static.flickr.com/3084/2446275806_d7a54e0bd1_o.png" alt="graph_2" width="320" height="230" /></a></p>
<p>Press it and the graph is shown. It maybe a bit small in the first  time to plot more areas of the graph. You can zoom in (just click the  graph or the zoom in button)  to make the graph clear and drag the graph  to navigate as you wish.</p>
<p><a title="graph_3 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2445449069/"><img src="http://farm3.static.flickr.com/2266/2445449069_f0d5de5248_o.png" alt="graph_3" width="320" height="291" /></a></p>
<p>Also, you can plot multi-graph in one time. Just input multi-line expressions and the graph will be shown in different colors.</p>
<p><a title="graph_1 by mmin18, on Flickr" href="http://www.flickr.com/photos/25621873@N07/2445384251/"><img src="http://farm4.static.flickr.com/3110/2445384251_6b1235a1c8_o.png" alt="graph_1" width="320" height="456" /></a></p>
<p>NOTICE: when graphing, handyCalc needs a lot of calculation which will slow down your handset.</p>
<p>handyCalc is free. You can donate the developer by purchasing the donation version.</p>
]]></content:encoded>
			<wfw:commentRss>http://androgeek.info/?feed=rss2&#038;p=357</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a particle system on Android</title>
		<link>http://androgeek.info/?p=331</link>
		<comments>http://androgeek.info/?p=331#comments</comments>
		<pubDate>Sat, 26 Feb 2011 16:02:52 +0000</pubDate>
		<dc:creator>Bill Hsu</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[NDK]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[particle system]]></category>

		<guid isPermaLink="false">http://androgeek.info/?p=331</guid>
		<description><![CDATA[Particle systems are widely used in games. Explosions, snow and smoke for example are created by particle system in most of today's games. What I wanna do in this post is to show you how to build an extensible OpenGL ES 2.0 particle system for Android. To make it extensible, maybe we need add a [...]]]></description>
			<content:encoded><![CDATA[<p>Particle systems are widely used in games. Explosions, snow and smoke for example are created by particle system in most of today's games. What I wanna do in this post is to show you how to build an extensible OpenGL ES 2.0 particle system for Android.<br />
To make it extensible, maybe we need add a script support for the particle system. But considering it's not a easy job writing a perfect script parser and running a script may decrease the frame rates significantly( anyway android devices are not PCs), so my solution is writing a virtual base class that contains basic particle methods and then overload these methods with specific particle effects.</p>
<p>Explosion Particle in <a href="http://market.android.com/details?id=com.billhsu.fruit3d">Happy Fruit 3D</a><br />
<img class="alignnone size-full wp-image-333" title="Particle" src="http://androgeek.info/wp-content/uploads/2011/02/exppar.jpg" alt="" width="295" height="230" /></p>
<p>My base class in this post is not virtual nor doing noting, it is rendering Explosions.</p>
<p>First let's see how to initialize the system:</p>
<pre class="brush:cpp">void Particle::init()
{
	char gVertexShader[] =
		  "uniform mat4 u_mvpMatrix;                            \n"
	      "uniform float u_time;		                        \n"
	      "uniform vec3 u_centerPosition;                       \n"
	      "attribute float a_lifetime;                          \n"
	      "attribute vec3 a_startPosition;                      \n"
	      "attribute vec3 a_endPosition;                        \n"
	      "varying float v_lifetime;                            \n"
	      "void main()                                          \n"
	      "{                                                    \n"
	      "  if ( u_time &lt;= a_lifetime )                        \n"
	      "  {                                                  \n"
	      "    gl_Position.xyz = a_startPosition + 				\n"
	      "                      (u_time * a_endPosition);   	\n"
		  "    gl_Position=(u_mvpMatrix*gl_Position);			\n"
	      "  }                                                  \n"
	      "  v_lifetime = 1.0 - ( u_time / a_lifetime );        \n"
	      "  v_lifetime = clamp ( v_lifetime, 0.0, 1.0 );       \n"
	      "  gl_PointSize =sin( v_lifetime*v_lifetime *3.1416 ) \n"
		  "						* 80.0; 						\n"
	      "}";

	char gFragmentShader[] =
	      "precision mediump float;                             \n"
	      "uniform vec4 u_color;		                        \n"
	      "varying float v_lifetime;                            \n"
	      "uniform sampler2D s_texture;                         \n"
	      "void main()                                          \n"
	      "{                                                    \n"
	      "  vec4 texColor;                                     \n"
	      "  texColor = texture2D( s_texture, gl_PointCoord );  \n"
	      "  gl_FragColor =  texColor;      					\n"
	      "  gl_FragColor.a *= (v_lifetime);}					\n";

	if(gFragmentShader!=0 &amp;&amp; gVertexShader!=0)
	{
		gProgram = createProgram(gVertexShader, gFragmentShader);
	}
	if (!gProgram)
	{
		LOGE("Could not create program for particle.");
		return;
	}
	LOGI("particle program ok");
<span id="more-331"></span>
	lifetimeLoc = glGetAttribLocation ( gProgram, "a_lifetime" );
	startPositionLoc = glGetAttribLocation ( gProgram, "a_startPosition" );
	endPositionLoc = glGetAttribLocation ( gProgram, "a_endPosition" );

	// Get the uniform locations
	mvpLoc = glGetUniformLocation ( gProgram, "u_mvpMatrix" );
	timeLoc = glGetUniformLocation ( gProgram, "u_time" );
	centerPositionLoc = glGetUniformLocation ( gProgram, "u_centerPosition" );
	colorLoc = glGetUniformLocation ( gProgram, "u_color" );
	samplerLoc = glGetUniformLocation ( gProgram, "s_texture" );

	LOGI("glGetAttribLocation(\"a_lifetime\") = %d\n",lifetimeLoc);
	LOGI("glGetAttribLocation(\"a_startPosition\") = %d\n",startPositionLoc);
	LOGI("glGetAttribLocation(\"a_endPosition\") = %d\n",endPositionLoc);
	LOGI("glGetAttribLocation(\"u_mvpMatrix\") = %d\n",mvpLoc);
	LOGI("glGetAttribLocation(\"u_time\") = %d\n",timeLoc);
	LOGI("glGetAttribLocation(\"u_centerPosition\") = %d\n",centerPositionLoc);
	LOGI("glGetAttribLocation(\"u_color\") = %d\n",colorLoc);
	LOGI("glGetAttribLocation(\"s_texture\") = %d\n",samplerLoc);
	LOGI("values ok");

	// Use tightly packed data
	//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	//LOGI("Particle Tex:%s",tex_name);
	int texidx=texmng-&gt;getIndex(tex_name);
	//LOGI("Particle Tex:%s   id %d",tex_name,texidx);
	if(texmng-&gt;tex_id[texidx]==-1)
	{
		int w=texmng-&gt;tex_w[texidx];
		int h=texmng-&gt;tex_h[texidx];
		glGenTextures(1, &amp;tex_id);
		tex_id = createSimpleTexture2D(tex_id, texmng-&gt;pixels[texidx],w, h, 4);
		texmng-&gt;tex_id[texidx]=tex_id;
		LOGI("Particle Tex ID %d",tex_id);
	}
	else
	{
		tex_id=texmng-&gt;getID(tex_name);
		LOGI("Already Loaded:Particle Tex ID %d",tex_id);
	}

	srand ( 0 );
	for ( int i = 0; i &lt; NUM_PARTICLES; i++ )
	{
		float *particleData =&amp;mParticleData[i * PARTICLE_SIZE];

		// Lifetime of particle
		(*particleData++) = 1.0f*( (float)(rand() % 10000) / 10000.0f );
		// End position of particle
		(*particleData++) = 30.000f*(( (float)(rand() % 10000) / 5000.0f ) - 1.0f);
		(*particleData++) = 30.000f*(( (float)(rand() % 10000) / 5000.0f ) - 1.0f);
		(*particleData++) = 30.000f*(( (float)(rand() % 10000) / 5000.0f ) - 1.0f);

		// Start position of particle
		(*particleData++) = 5.000f*(( (float)(rand() % 10000) / 40000.0f ) - 0.125f);//40000 0.125
		(*particleData++) = 5.000f*(( (float)(rand() % 10000) / 40000.0f ) - 0.125f);
		(*particleData++) = 5.000f*(( (float)(rand() % 10000) / 40000.0f ) - 0.125f);

	}

	// Initialize time to cause reset on first update
	time = 1.0f;
	LOGI("Particle init OK");

}</pre>
<p>Note the startPosition and endPosition: the explosion particles start at startPosition and are heading to the endPosition. So to make it real, startPosition should be limited in a smaller space than the endPosition. In every rendering loop, we move the particle to the endPostion a little bit. </p>
<p>The particle size is related to it's existing time :</p>
<pre class="brush:cpp">
gl_PointSize =sin( v_lifetime*v_lifetime *3.1416 )
</pre>
<p>Why sine here? Simply because explosion particles are small at begin, bigger in it's middle age and small again when it's going to fade.</p>
<p>Now turn to the update method of a particle:</p>
<pre class="brush:cpp">
void Particle::Update(float timeDelta)
{
	time+=0.01f*timeDelta;

	if ( time >= 1.0f )
	{
		time = 0.0f;
	}

}
</pre>
<p>It's quite easy, a simple particle effect doesn't need complex updating computing, here I just add a time delta to the particle's existing time. You may override this to achieve more flexible effects.</p>
<p>Rendering:</p>
<pre class="brush:cpp">
void Particle::Render(ESMatrix &#038;mvp)
{
	checkGlError("Render");
	glUseProgram ( gProgram );
	checkGlError("glUseProgram");
	glUniformMatrix4fv( mvpLoc, 1, GL_FALSE, (GLfloat*) &#038;mvp.m[0][0] );
	glUniform1f ( timeLoc, time );
	checkGlError("glUniformMatrix4fv");
	glEnableVertexAttribArray ( lifetimeLoc );
	glEnableVertexAttribArray ( endPositionLoc );
	glEnableVertexAttribArray ( startPositionLoc );
	checkGlError("glEnableVertexAttribArray");
	glUniform1i ( samplerLoc, 0 );
	checkGlError("samplerLoc");
	// Load the vertex attributes
	glVertexAttribPointer ( lifetimeLoc, 1, GL_FLOAT,
							GL_FALSE, PARTICLE_SIZE * sizeof(GLfloat),
							&#038;mParticleData[0] );
	checkGlError("lifetimeLoc");
	glVertexAttribPointer ( endPositionLoc, 3, GL_FLOAT,
							GL_FALSE, PARTICLE_SIZE * sizeof(GLfloat),
							&#038;mParticleData[1] );
	checkGlError("endPositionLoc");
	glVertexAttribPointer ( startPositionLoc, 3, GL_FLOAT,
							GL_FALSE, PARTICLE_SIZE * sizeof(GLfloat),
							&#038;mParticleData[4] );
	checkGlError("startPositionLoc");

	// Blend particles
	glEnable ( GL_BLEND );
	glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	glDisable(GL_DEPTH_TEST);
	// Bind the texture
	glActiveTexture ( GL_TEXTURE0 );
	int texidx=texmng->getIndex(tex_name);
	glBindTexture(GL_TEXTURE_2D, texmng->tex_id[texidx]);
	checkGlError("Particle glBindTexture");

	// Set the sampler texture unit to 0

	glDrawArrays( GL_POINTS, 0, NUM_PARTICLES*time*time );

	glDisable(GL_BLEND);
}
</pre>
<p>Why glDisable(GL_DEPTH_TEST)?<br />
Particles are transparent, if didn't glDisable(GL_DEPTH_TEST), the explosion looks bad. When rendering transparent object, we need disable z-testing and render all these object from far to near.</p>
]]></content:encoded>
			<wfw:commentRss>http://androgeek.info/?feed=rss2&#038;p=331</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Happy Fruit 3D now available in Android Market</title>
		<link>http://androgeek.info/?p=307</link>
		<comments>http://androgeek.info/?p=307#comments</comments>
		<pubDate>Tue, 08 Feb 2011 02:49:57 +0000</pubDate>
		<dc:creator>Bill Hsu</dc:creator>
				<category><![CDATA[Android APPs]]></category>
		<category><![CDATA[Android News]]></category>
		<category><![CDATA[available]]></category>
		<category><![CDATA[Happy Fruit 3D]]></category>

		<guid isPermaLink="false">http://androgeek.info/?p=307</guid>
		<description><![CDATA[Happy Fruit 3D is a 3D game developed by AndroGeek. Different kinds of fruits are falling down from the tree！Hurry up! You need to catch them with your basket! Control your basket by tilting your phone(put your phone horizontally before start). It's fun and challenging, enjoy yourself! See at Android Market:http://market.android.com/details?id=com.billhsu.fruit3d APP SCREENSHOTS: QR code: [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://market.android.com/details?id=com.billhsu.fruit3d"><img class="size-full wp-image-308 aligncenter" title="FeatureGraphic" src="http://androgeek.info/wp-content/uploads/2011/02/FeatureGraphic.png" alt="" width="574" height="280" /></a></p>
<p>Happy Fruit 3D is a 3D game developed by AndroGeek.<br />
Different kinds of fruits are falling down from the tree！Hurry up! You need to catch them with your basket!<br />
Control your basket by tilting your phone(put your phone horizontally before start).<br />
It's fun and challenging, enjoy yourself!</p>
<p>See at Android Market:<a href="http://market.android.com/details?id=com.billhsu.fruit3d">http://market.android.com/details?id=com.billhsu.fruit3d</a></p>
<p>APP SCREENSHOTS:</p>
<p><a href="http://market.android.com/details?id=com.billhsu.fruit3d"><img class="alignnone size-medium wp-image-309" src="http://androgeek.info/wp-content/uploads/2011/02/device-300x168.png" alt="" width="300" height="168" /></a><a href="http://market.android.com/details?id=com.billhsu.fruit3d"><img class="alignnone size-medium wp-image-310" src="http://androgeek.info/wp-content/uploads/2011/02/device2-300x168.png" alt="" width="300" height="168" /></a></p>
<p>QR code:</p>
<p><a href="market://search?q=pname:com.billhsu.fruit3d"><img class="alignnone size-full wp-image-311" src="http://androgeek.info/wp-content/uploads/2011/02/1554871-1297086482080.png" alt="" width="164" height="164" /></a></p>
<p>REQUIRES ANDROID:2.1 and up;</p>
<p>CATEGORY:Arcade &amp; Action;</p>
<p>SIZE:5.1M;<br />
<span id="more-307"></span><br />
PRICE:$0.99</p>
<p>Demo Video:<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/_sJw5SEBybg?hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/_sJw5SEBybg?hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div id="_mcePaste">ハッピーフルーツ(Happy Fruit 3D)は果物を受け取る３ｄゲームです。</div>
<p>いろんな果物は木の上から落ちて、情況は緊急で、あなたは農民のおじさんに代わって、それらをしっかり受け取らなければなりません！</p>
<p>携帯電話を傾くことによってかごをコントロールすることができます（始まる時携帯電話を平面に保たせてください）</p>
<p>ゲームはとてもすばらしくて、ぜひ試してみてください！</p>
<div>開心水果(Happy Fruit 3D)是一個接水果的3D遊戲。</div>
<div id="_mcePaste">不同的水果正在從樹上掉下來，情況緊急，你需要幫助農民伯伯借接住它們！</div>
<div id="_mcePaste">通過傾斜手機來控制籃子（開始時請平放手機）。</div>
<div id="_mcePaste">遊戲很精彩，快來試試看吧！</div>
<p>開心水果(Happy Fruit 3D)是一個接水果的3D遊戲。不同的水果正在從樹上掉下來，情況緊急，你需要幫助農民伯伯借接住它們！通過傾斜手機來控制籃子（開始時請平放手機）。遊戲很精彩，快來試試看吧！</p>
]]></content:encoded>
			<wfw:commentRss>http://androgeek.info/?feed=rss2&#038;p=307</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrated development of Android NDK C/C++ software under Visual Studio</title>
		<link>http://androgeek.info/?p=303</link>
		<comments>http://androgeek.info/?p=303#comments</comments>
		<pubDate>Sun, 06 Feb 2011 01:22:08 +0000</pubDate>
		<dc:creator>Bill Hsu</dc:creator>
				<category><![CDATA[Android Programming]]></category>
		<category><![CDATA[NDK]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[CPlusPlus]]></category>
		<category><![CDATA[VisualStudio]]></category>

		<guid isPermaLink="false">http://androgeek.info/?p=303</guid>
		<description><![CDATA[Introduction vs-android (by Gavin) is intended to provide a collection of scripts and utilities to support integrated development of Android NDK C/C++ software under Microsoft Visual Studio. Currently vs-android only works under Visual Studio 2010. Earlier versions lack the MSBuild integration with the C/C++ compilation systems. The only required component is the Android NDK. Neither Cygwin, [...]]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>vs-android (by Gavin) is intended to provide a collection of scripts and utilities to support integrated development of Android NDK C/C++ software under Microsoft Visual Studio.</p>
<p>Currently vs-android only works under Visual Studio 2010. Earlier versions lack the MSBuild integration with the C/C++ compilation systems.</p>
<p>The only required component is the Android NDK. Neither Cygwin, Java, nor the full Android SDK are needed to compile and link C/C++ code.</p>
<h1>Features</h1>
<ul>
<li>Compile and link Android C/C++ projects within Visual Studio.</li>
<li>Integrated development, no makefiles. Works as another 'Platform' type.</li>
<li>Android settings co-exist within the same VS projects as other platforms.</li>
<li>Supports static library projects, and links them in if marked as project dependencies.</li>
<li>Intellisense and 'External Dependencies' correctly pull in Android NDK headers.</li>
<li>Cygwin install is not required.</li>
<li>Around twice as fast as using ndk-build under Cygwin. For full rebuilds, and incremental changes.</li>
<li>Ctrl-F7: compile single file functions, has no dependency checking wait.</li>
<li>Supports invoking ant after linking, such that you end up with a packaged ready-to-deploy .apk file.</li>
</ul>
<p>You can download it from here:<br />
<a href="http://code.google.com/p/vs-android/" target="_blank">http://code.google.com/p/vs-android/</a><br />
Really a good news for NDK developers !</p>
]]></content:encoded>
			<wfw:commentRss>http://androgeek.info/?feed=rss2&#038;p=303</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting the System tick count</title>
		<link>http://androgeek.info/?p=299</link>
		<comments>http://androgeek.info/?p=299#comments</comments>
		<pubDate>Sun, 30 Jan 2011 14:50:12 +0000</pubDate>
		<dc:creator>Bill Hsu</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[NDK]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[clock_gettime]]></category>
		<category><![CDATA[tick]]></category>

		<guid isPermaLink="false">http://androgeek.info/?p=299</guid>
		<description><![CDATA[There two many ways to get system tick count in Linux(same in android) :gettimeofday() and clock_gettime(). In the game Fruit3D ,I used gettimeofday() to get time deltas to calculate objects'  movements, but I'm not really pleased with the performance. Here is the code I used then: static long getTime(void) { struct timeval now; gettimeofday(&#38;now, NULL); [...]]]></description>
			<content:encoded><![CDATA[<p>There two many ways to get system tick count in Linux(same in android) :gettimeofday() and clock_gettime().</p>
<p>In the game Fruit3D ,I used gettimeofday() to get time deltas to calculate objects'  movements, but I'm not really pleased with the performance. Here is the code I used then:</p>
<pre class="brush:cpp">static long getTime(void)
{
    struct timeval  now;
    gettimeofday(&amp;now, NULL);
    return (long)(now.tv_sec*1000 + now.tv_usec/1000);
}</pre>
<p>Recently I read a mail list, some guys talked about</p>
<pre class="brush:cpp">int clock_gettime(clockid_t clk_id, struct timespect *tp);</pre>
<p>clock_gettime is nanosecond accuracy, so it's a good choice for game timing.<br />
I rewrite my getTime() as below and Fruit3D runs better now:</p>
<pre class="brush:cpp">
static long _getTime(void)
{
	struct timespec now;
	clock_gettime(CLOCK_MONOTONIC, &#038;now);
	return now.tv_sec*1000000 + now.tv_nsec/1000;

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://androgeek.info/?feed=rss2&#038;p=299</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android NDK r5b now available for download</title>
		<link>http://androgeek.info/?p=296</link>
		<comments>http://androgeek.info/?p=296#comments</comments>
		<pubDate>Thu, 27 Jan 2011 03:14:06 +0000</pubDate>
		<dc:creator>Bill Hsu</dc:creator>
				<category><![CDATA[NDK]]></category>
		<category><![CDATA[r5b]]></category>

		<guid isPermaLink="false">http://androgeek.info/?p=296</guid>
		<description><![CDATA[This release of the NDK does not include any new features compared to r5. The r5b release addresses the following problems in the r5 release: The r5 binaries required glibc 2.11, but the r5b binaries are generated with a special toolchain that targets glibc 2.7 or higher instead. The Linux toolchain binaries now run on [...]]]></description>
			<content:encoded><![CDATA[<p>This release of the NDK does not include any new features compared to r5. The r5b release addresses the following problems in the r5 release:</p>
<ul>
<li>The r5 binaries required glibc 2.11, but the r5b binaries are generated with a special toolchain that targets glibc 2.7 or higher instead. The Linux toolchain binaries now run on Ubuntu 8.04 or higher.</li>
<li>Fixes a compiler bug in the arm-linux-androideabi-4.4.3 toolchain. The previous binary generated invalid thumb instruction sequences when dealing with signed chars.</li>
<li>Adds missing documentation for the "gnustl_static" value for APP_STL, that allows you to link against a static library version of GNU libstdc++.</li>
<li>The following <code>ndk-build</code> issues are fixed:
<ul>
<li>A bug that created inconsistent dependency files when a compilation error occured on Windows. This prevented a proper build after the error was fixed in the source code.</li>
<li>A Cygwin-specific bug where using very short paths for the Android NDK installation or the project path led to the generation of invalid dependency files. This made incremental builds impossible.</li>
<li>A typo that prevented the cpufeatures library from working correctly with the new NDK toolchain.</li>
<li>Builds in Cygwin are faster by avoiding calls to <code>cygpath -m</code> from GNU Make for every source or object file, which caused problems with very large source trees. In case this doesn't work properly, define <code>NDK_USE_CYGPATH=1</code> in your environment to use <code>cygpath -m</code> again.</li>
<li>The Cygwin installation now notifies the user of invalid installation paths that contain spaces. Previously, an invalid path would output an error that complained about an incorrect version of GNU Make, even if the right one was installed.</li>
</ul>
</li>
<li>Fixed a typo that prevented the <code>NDK_MODULE_PATH</code> environment variable from working properly when it contained multiple directories separated with a colon.</li>
<li>The <code>prebuilt-common.sh</code> script contains fixes to check the compiler for 64-bit generated machine code, instead of relying on the host tag, which allows the 32-bit toolchain to rebuild properly on Snow Leopard. The toolchain rebuild scripts now also support using a 32-bit host toolchain.</li>
<li>A missing declaration for <code>INET_ADDRSTRLEN</code> was added to <code>&lt;netinet/in.h&gt;</code>.<span id="more-296"></span></li>
<li>Missing declarations for <code>IN6_IS_ADDR_MC_NODELOCAL</code> and <code>IN6_IS_ADDR_MC_GLOBAL</code> were added to <code>&lt;netinet/in6.h&gt;</code>.</li>
<li>'asm' was replaced with '__asm__' in <code>&lt;asm/byteorder.h&gt;</code> to allow compilation with <code>-std=c99</code>.</li>
</ul>
<table>
<tbody>
<tr>
<th>Platform</th>
<th>Package</th>
<th>Size</th>
<th>MD5 Checksum</th>
</tr>
<tr>
<td>Windows</td>
<td><a href="http://dl.google.com/android/ndk/android-ndk-r5b-windows.zip">android-ndk-r5b-windows.zip</a></td>
<td>61299831 bytes</td>
<td>87745ada305ab639399161ab4faf684c</td>
</tr>
<tr>
<td>Mac OS X (intel)</td>
<td><a href="http://dl.google.com/android/ndk/android-ndk-r5b-darwin-x86.tar.bz2">android-ndk-r5b-darwin-x86.tar.bz2</a></td>
<td>50210863 bytes</td>
<td>019a14622a377b3727ec789af6707037</td>
</tr>
<tr>
<td>Linux 32/64-bit (x86)</td>
<td><a href="http://dl.google.com/android/ndk/android-ndk-r5b-linux-x86.tar.bz2">android-ndk-r5b-linux-x86.tar.bz2</a></td>
<td>44138539 bytes</td>
<td>4c0045ddc2bfd657be9d5177d0e0b7e7</td>
</tr>
</tbody>
</table>
<p>See http://developer.android.com/sdk/ndk/index.html</p>
]]></content:encoded>
			<wfw:commentRss>http://androgeek.info/?feed=rss2&#038;p=296</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Motorola Rolls Out Three Tegra Powered Devices</title>
		<link>http://androgeek.info/?p=289</link>
		<comments>http://androgeek.info/?p=289#comments</comments>
		<pubDate>Fri, 07 Jan 2011 02:05:29 +0000</pubDate>
		<dc:creator>Bill Hsu</dc:creator>
				<category><![CDATA[Android News]]></category>
		<category><![CDATA[Motorola]]></category>
		<category><![CDATA[tegra]]></category>
		<category><![CDATA[xoom]]></category>

		<guid isPermaLink="false">http://androgeek.info/?p=289</guid>
		<description><![CDATA[Motorola rolled out three Tegra 2 powered devices at their press day event, including a phone, a phone that docks into a laptop shell, and the first Android 3.0 tablet computer to hit Verizon Wireless. Via nVidia Blog]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Motorola rolled out three Tegra 2 powered devices at their press day event, including a phone, a phone that docks into a laptop shell, and the first Android 3.0 tablet computer to hit Verizon Wireless.</p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-290" title="xoom-300x274" src="http://androgeek.info/wp-content/uploads/2011/01/xoom-300x274.jpg" alt="" width="300" height="274" /></p>
<p style="text-align: left;">
<p><span id="more-289"></span><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="390" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://www.youtube.com/v/eMQP2rJ0Nl8&amp;hl=en_US&amp;feature=player_embedded&amp;version=3" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="390" src="http://www.youtube.com/v/eMQP2rJ0Nl8&amp;hl=en_US&amp;feature=player_embedded&amp;version=3" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Via <a href="http://blogs.nvidia.com/2011/01/motorola-rolls-out-three-tegra-powered-devices/" target="_blank">nVidia Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://androgeek.info/?feed=rss2&#038;p=289</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Load png from assets in NDK</title>
		<link>http://androgeek.info/?p=275</link>
		<comments>http://androgeek.info/?p=275#comments</comments>
		<pubDate>Fri, 31 Dec 2010 07:08:12 +0000</pubDate>
		<dc:creator>Bill Hsu</dc:creator>
				<category><![CDATA[NDK]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[assets]]></category>
		<category><![CDATA[png]]></category>

		<guid isPermaLink="false">http://androgeek.info/?p=275</guid>
		<description><![CDATA[Previously, I first extra my texture files to /data and then load them from native c++ code. But it's not a good way cause that is a waste to user's space. We can load file directly from APK file. APK is some like a ZIP file. So we need libzip to help us reading resources [...]]]></description>
			<content:encoded><![CDATA[<p>Previously, I first extra my texture files to /data and then load them from native c++ code. But it's not a good way cause that is a waste to user's space. We can load file directly from APK file.</p>
<p>APK is some like a ZIP file. So we need libzip to help us reading resources from the APK file.</p>
<p>Luckily, I found someone from <a href="http://www.anddev.org/ndk_opengl_-_loading_resources_and_assets_from_native_code-t11978.html" target="_blank">anddev </a> had packed libzip and libpng for android NDK,  you can download it from <a href="http://www.anddev.org/resources/source/1912" target="_blank">here</a>.</p>
<p>We need to add libpng and libzip to Application.mk:</p>
<p>APP_ABI := armeabi armeabi-v7a<br />
APP_PROJECT_PATH := $(call my-dir)/project<br />
APP_MODULES      := libpng libzip YOU_PROJECT_NAME</p>
<p>Add these to Android.mk<br />
LOCAL_LDLIBS+=-L$(SYSROOT)/usr/lib -ldl<br />
LOCAL_LDLIBS+=-L$(SYSROOT)/usr/lib -lz</p>
<p>Here is a snippet for loading apk file, if it works, it will list all files contained in the apk.</p>
<pre class="brush:cpp">	static void loadAPK (const char* apkPath) {
	LOGI("Loading APK %s", apkPath);
	APKArchive = zip_open(apkPath, 0, NULL);
	if (APKArchive == NULL) {
		LOGE("Error loading APK");
	return;
  }

	//Just for debug, print APK contents
	int numFiles = zip_get_num_files(APKArchive);
	for (int i=0; i&lt;numFiles; i++) {
		const char* name = zip_get_name(APKArchive, i, 0);
		if (name == NULL) {
		LOGE("Error reading zip file name at index %i : %s", zip_strerror(APKArchive));
		return;
    }
	LOGI("File %i : %s\n", i, name);
  }
}</pre>
<p>There is something to say about apkPath, it is where your apk is. You can generate it in Java and pass it to native code.<br />
<span id="more-275"></span></p>
<pre class="brush:java">String apkFilePath = null;
ApplicationInfo appInfo = null;
PackageManager packMgmr = this.getPackageManager();
try {
	    appInfo = packMgmr.getApplicationInfo("com.yourpackage", 0);
    } catch (NameNotFoundException e) {
 e.printStackTrace();
throw new RuntimeException("Unable to locate assets, aborting...");
    }
apkFilePath = appInfo.sourceDir;
 jni.init(apkFilePath);//pass it to NDK</pre>
<p>Now it's time to load PNGs!</p>
<pre class="brush:cpp">int TexMng::LoadPNG(char* filename,bool _alpha)
{
	LOGI("Loading %s",filename);

	for(int i=0;i&lt;nTex;++i)
	{
		if(strcmp(tex_name[i],filename)==0)
		{
			LOGI("Already Loaded");
			return -1;
		}

	}

	if(nTex&gt;=MAX_TEXS)
	{
		LOGI("Too many textures!");
		return -1;
	}

  file = zip_fopen(APKArchive, filename, 0);
  if (!file) {
    LOGE("Error opening %s from APK", filename);
    return TEXTURE_LOAD_ERROR;
  }

  //header for testing if it is a png
  png_byte header[8];

  //read the header
  zip_fread(file, header, 8);

  //test if png
  int is_png = !png_sig_cmp(header, 0, 8);
  if (!is_png) {
    zip_fclose(file);
    LOGE("Not a png file : %s", filename);
    return TEXTURE_LOAD_ERROR;
  }

  //create png struct
  png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
      NULL, NULL);
  if (!png_ptr) {
    zip_fclose(file);
    LOGE("Unable to create png struct : %s", filename);
    return (TEXTURE_LOAD_ERROR);
  }

  //create png info struct
  png_infop info_ptr = png_create_info_struct(png_ptr);
  if (!info_ptr) {
    png_destroy_read_struct(&amp;png_ptr, (png_infopp) NULL, (png_infopp) NULL);
    LOGE("Unable to create png info : %s", filename);
    zip_fclose(file);
    return (TEXTURE_LOAD_ERROR);
  }

  //create png info struct
  png_infop end_info = png_create_info_struct(png_ptr);
  if (!end_info) {
    png_destroy_read_struct(&amp;png_ptr, &amp;info_ptr, (png_infopp) NULL);
    LOGE("Unable to create png end info : %s", filename);
    zip_fclose(file);
    return (TEXTURE_LOAD_ERROR);
  }

  //png error stuff, not sure libpng man suggests this.
  if (setjmp(png_jmpbuf(png_ptr))) {
    zip_fclose(file);
    LOGE("Error during setjmp : %s", filename);
    png_destroy_read_struct(&amp;png_ptr, &amp;info_ptr, &amp;end_info);
    return (TEXTURE_LOAD_ERROR);
  }

  //init png reading
  //png_init_io(png_ptr, fp);
  png_set_read_fn(png_ptr, NULL, png_zip_read);

  //let libpng know you already read the first 8 bytes
  png_set_sig_bytes(png_ptr, 8);

  // read all the info up to the image data
  png_read_info(png_ptr, info_ptr);

  //variables to pass to get info
  int bit_depth, color_type;
  png_uint_32 twidth, theight;

  // get info about png
  png_get_IHDR(png_ptr, info_ptr, &amp;twidth, &amp;theight, &amp;bit_depth, &amp;color_type,
      NULL, NULL, NULL);

  //update width and height based on png info
  tex_w[nTex] = twidth;
  tex_h[nTex] = theight;

  // Update the png info struct.
  png_read_update_info(png_ptr, info_ptr);

  // Row size in bytes.
  int rowbytes = png_get_rowbytes(png_ptr, info_ptr);

  // Allocate the image_data as a big block, to be given to opengl
  png_byte *image_data = new png_byte[rowbytes * theight];
  if (!image_data) {
    //clean up memory and close stuff
    png_destroy_read_struct(&amp;png_ptr, &amp;info_ptr, &amp;end_info);
    LOGE("Unable to allocate image_data while loading %s ", filename);
    zip_fclose(file);
    return TEXTURE_LOAD_ERROR;
  }

  //row_pointers is for pointing to image_data for reading the png with libpng
  png_bytep *row_pointers = new png_bytep[theight];
  if (!row_pointers) {
    //clean up memory and close stuff
    png_destroy_read_struct(&amp;png_ptr, &amp;info_ptr, &amp;end_info);
    delete[] image_data;
    LOGE("Unable to allocate row_pointer while loading %s ", filename);
    zip_fclose(file);
    return TEXTURE_LOAD_ERROR;
  }
  // set the individual row_pointers to point at the correct offsets of image_data
  for (int i = 0; i &lt; theight; ++i)
    row_pointers[theight - 1 - i] = image_data + i * rowbytes;

  //read the png into image_data through row_pointers
  png_read_image(png_ptr, row_pointers);

  alpha[nTex]=_alpha;
  pixels[nTex]=image_data;
  strcpy(tex_name[nTex],filename);
  ++nTex;
  png_destroy_read_struct(&amp;png_ptr, &amp;info_ptr, &amp;end_info);
  //delete[] image_data;
  delete[] row_pointers;
  zip_fclose(file);

  return nTex;

}</pre>
]]></content:encoded>
			<wfw:commentRss>http://androgeek.info/?feed=rss2&#038;p=275</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

