<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
 	<channel>
		<title>Learning iPhone's OpenGL ES | Forays Into iPhone OpenGL ES | Serg Koren</title>
		<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/</link>
		<description></description>
		<language>en</language>
		<lastBuildDate>Tue, 04 Aug 2009 09:52:22 -0400</lastBuildDate>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<generator>Sandvox Pro 1.6.3</generator>
		<item>
			<title>Pointers</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/pointers.html</link>
			<description>
&lt;div&gt;&lt;p&gt;
I guess I'm at a crossroads here.  The stuff I've presented should be enough to kick-start you into OpenGL ES on the iPhone.  There is lots more to learn, however.  The problem is that I don't want to take on examples that have already been done elsewhere.   There are a ton of OpenGL and nowadays OpenGL ES on iPhone sites.  Even the Wikipedia has mini-tutorial like pages on OpenGL coding.  Also, I'm deep into real work and my own iPhone app development.  So the crossroads is, where do I go from here with this blog.  I never intended it to be a full-time blog, just one that would share my own learning experiences.  However, I don't want to drop it completely. &lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;I've had some interest and questions from a few people as part of this series.   I thank you for the support !&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;So, I'll leave it up to you.  What would you like to see me tackle in terms of OpenGL ES.  Something manageable, please.  Email me and let me know what you think.  If I get any responses I'll tackle them as my time permits.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;In any event, here are some other good online sources for OpenGL  information:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://gpwiki.org/index.php/OpenGL:Tutorials:Tutorial_Framework:First_Polygon&quot;&gt;Wikipedia &lt;/a&gt; - just search for OpenGL ES topics&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://gpwiki.org/index.php/OpenGL:Tutorials:Tutorial_Framework:First_Polygon&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://www.khronos.org/opengles/documentation/opengles1_0/html/index.html&quot;&gt;Open GL ES Reference Manual &lt;/a&gt; - good reference source for when you want the details.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://nehe.gamedev.net/&quot;&gt;NeHe Productions&lt;/a&gt; - news, great tutorials, game coding&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://developer.apple.com&quot;&gt;Apple&lt;/a&gt; - sample code, tools, etc.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://icodeblog.com/&quot;&gt;iCodeBlog&lt;/a&gt; - good getting-started iPhone tutorials, some OpenGL ES stuff&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://maniacdev.com/2009/04/8-great-resources-for-learning-iphone-opengl-es/&quot;&gt;ManiacDev&lt;/a&gt; - other pointers.  Good source.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;So that's it for this time around. Let me know what you would like to see.  Otherwise, thanks again, and see you next time.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;/div&gt;
			</description>
			<pubDate>Tue, 04 Aug 2009 09:32:29 -0400</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/pointers.html</guid>
		</item>
		<item>
			<title>Part VI - GL Paint Dissected - EAGLView.m</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_vi_-_gl_paint_dissecte.html</link>
			<description>
&lt;div&gt;&lt;p&gt;
Last installment I went through the header file for the EAGLView. We saw that it was actually fairly straightforward with the addition of a delegate declarations, a depth buffer and some utility functions to convert coordinates.  Let's dive into the implementation and see how these are used.&lt;/p&gt;
&lt;p&gt;The first thing we see are the property synthesizers followed by a class method:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;@implementation&lt;span style=&quot;color: black;&quot;&gt; EAGLView&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@synthesize&lt;/span&gt; delegate=&lt;span style=&quot;color: #3f6e74;&quot;&gt;_delegate&lt;/span&gt;, autoresizesSurface=&lt;span style=&quot;color: #3f6e74;&quot;&gt;_autoresize&lt;/span&gt;, surfaceSize=&lt;span style=&quot;color: #3f6e74;&quot;&gt;_size&lt;/span&gt;, framebuffer = &lt;span style=&quot;color: #3f6e74;&quot;&gt;_framebuffer&lt;/span&gt;, pixelFormat = &lt;span style=&quot;color: #3f6e74;&quot;&gt;_format&lt;/span&gt;, depthFormat = &lt;span style=&quot;color: #3f6e74;&quot;&gt;_depthFormat&lt;/span&gt;, context = &lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;+ (&lt;span style=&quot;color: #5c2699;&quot;&gt;Class&lt;/span&gt;) layerClass&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #5c2699;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; [&lt;/span&gt;CAEAGLLayer&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;This just returns the class of the CAEAGLLayer.&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;Next:&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;BOOL&lt;/span&gt;) _createSurface&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CAEAGLLayer&lt;/span&gt;*&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;        eaglLayer = (&lt;span style=&quot;color: #5c2699;&quot;&gt;CAEAGLLayer&lt;/span&gt;*)[&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; layer];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGSize&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;newSize;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;GLuint&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;oldRenderbuffer;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;GLuint&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;oldFramebuffer;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(![&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;setCurrentContext&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]) {&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;return&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;NO&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;This method creates a surface to draw on, and returns a flag indictating whether it was created or not.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;The first attribute eagllayer points to our layer.  We then have a size and buffer pointers for rendering and our display buffer.  If we can't set a current context we return false (NO).&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;newSize = [eaglLayer &lt;span style=&quot;color: #2e0d6e;&quot;&gt;bounds&lt;/span&gt;].&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;newSize.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt; = &lt;span style=&quot;color: #2e0d6e;&quot;&gt;roundf&lt;/span&gt;(newSize.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;newSize.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt; = &lt;span style=&quot;color: #2e0d6e;&quot;&gt;roundf&lt;/span&gt;(newSize.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;Here we set the size of the layer we are creating to our bounds rectangle.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glGetIntegerv&lt;/span&gt;(&lt;span style=&quot;color: #643820;&quot;&gt;GL_RENDERBUFFER_BINDING_OES&lt;/span&gt;, (&lt;span style=&quot;color: #5c2699;&quot;&gt;GLint&lt;/span&gt; *) &amp;amp;oldRenderbuffer);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glGetIntegerv&lt;/span&gt;(&lt;span style=&quot;color: #643820;&quot;&gt;GL_FRAMEBUFFER_BINDING_OES&lt;/span&gt;, (&lt;span style=&quot;color: #5c2699;&quot;&gt;GLint&lt;/span&gt; *) &amp;amp;oldFramebuffer);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;We cast our pointers to integers using an OpenGL utility function glGetIntegerv (v stands for value).  &lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glGenRenderbuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_renderbuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glBindRenderbufferOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_RENDERBUFFER_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_renderbuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;This creates a new rendering buffer and binds to it.&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(![&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;renderbufferStorage&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_RENDERBUFFER_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;fromDrawable&lt;span style=&quot;color: black;&quot;&gt;:(&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLDrawable&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;gt;)eaglLayer]) {&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;glDeleteRenderbuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_renderbuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #643820;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glBindRenderbufferOES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_RENDERBUFFER_BINDING_OES&lt;span style=&quot;color: black;&quot;&gt;, oldRenderbuffer);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;return&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;NO&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;span style=&quot;line-height: normal; color: rgb(17, 17, 17);&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;/span&gt;}&lt;/span&gt; &lt;/font&gt;&lt;/p&gt;
&lt;/p&gt;
&lt;/p&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/tt&gt;&lt;/p&gt;
&lt;div&gt;&lt;font face=&quot;Monaco, Times, 'Times New Roman', fantasy&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=&quot;Monaco, Times, 'Times New Roman', -webkit-fantasy&quot;&gt;We then see if we can get the storage for the render buffer in our layer and if we can't we delete the renderbuffer we just created, unbind it, and return false from the method.  If we can't get the storage for the renderbuffer, we can't create our layer.  As a reminder, layers are related to the depthbuffer we saw in the declarations. &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=&quot;Monaco, Times, 'Times New Roman', -webkit-fantasy&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=&quot;Monaco, Times, 'Times New Roman', -webkit-fantasy&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glGenFramebuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_framebuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glBindFramebufferOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_FRAMEBUFFER_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_framebuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;If we can get the renderbuffer set up we then generate a framebuffer and bind the pointer.&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (&lt;/span&gt;_depthFormat&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;glGenRenderbuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_depthBuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;glBindRenderbufferOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_RENDERBUFFER_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_depthBuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glRenderbufferStorageOES&lt;/span&gt;(&lt;span style=&quot;color: #643820;&quot;&gt;GL_RENDERBUFFER_OES&lt;/span&gt;, &lt;span style=&quot;color: #3f6e74;&quot;&gt;_depthFormat&lt;/span&gt;, newSize.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;, newSize.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #643820;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glFramebufferRenderbufferOES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_FRAMEBUFFER_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_DEPTH_ATTACHMENT_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_RENDERBUFFER_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_depthBuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;If we're using a depthbuffer (see the the last installment), we generate and bind a depth buffer in the first two lines in the 'if' statement.  Next we get the framebuffer's storage, and attach the framebuffer to the renderbuffer. This essentially associates the two buffers so we can handle them together.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_size&lt;/span&gt; = newSize;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(!&lt;/span&gt;_hasBeenCurrent&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glViewport&lt;/span&gt;(&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, newSize.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;, newSize.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glScissor&lt;/span&gt;(&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, newSize.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;, newSize.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;_hasBeenCurrent&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;YES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;else&lt;span style=&quot;color: black;&quot;&gt; {&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glBindFramebufferOES&lt;/span&gt;(&lt;span style=&quot;color: #643820;&quot;&gt;GL_FRAMEBUFFER_OES&lt;/span&gt;, oldFramebuffer);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glBindRenderbufferOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_RENDERBUFFER_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, oldRenderbuffer);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;Next we save off the size of the layer, and check our one-time flag (see the last installment). If the flag is not set (first time in)  we set our viewport.  The viewport is the virtual window we are looking through onto our scene.  In this case, the viewport is the size of our layer...we see our entire layer head on.  The glScissor call creates something known as a &amp;quot;scissor box&amp;quot;.  The scissor box is more commonly known as a &amp;quot;drawing clipping rectangle&amp;quot;. Things will only be drawn in the bounds of the scissor box even if what we draw goes outside the box. &lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;If this isn't the first time, we bind the framebuffer to our &amp;quot;old&amp;quot; buffer.  In either case we bind the renderbuffer to the &amp;quot;old&amp;quot; buffer.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;/p&gt;
&lt;/tt&gt;&lt;/p&gt;
&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=&quot;Monaco, Times, 'Times New Roman', -webkit-fantasy&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Error handling here&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #26474b;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_delegate&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;didResizeEAGLSurfaceForView&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;return&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;YES&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#000000&quot;&gt;Strangely, there is a comment for error handling but there is none.  We then invoke our delegate method to inform it we've resized our surface.  At this point the surface is created and we return true.&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#000000&quot;&gt;Next, we have a complimentary method that destroys a surface (one we created above).&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) _destroySurface&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #5c2699;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;EAGLContext&lt;span style=&quot;color: black;&quot;&gt; *oldContext = [&lt;/span&gt;EAGLContext&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;currentContext&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt; (oldContext != &lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;)&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;setCurrentContext&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;_depthFormat&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;glDeleteRenderbuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_depthBuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;_depthBuffer&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glDeleteRenderbuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_renderbuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;_renderbuffer&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glDeleteFramebuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_framebuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;_framebuffer&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt; (oldContext != &lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;)&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;setCurrentContext&lt;/span&gt;:oldContext];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;The first thing that happens here is we save our current context.  IF the current context isn't our old previous context, we make the previous context current.  If we have a depthbuffer, we delete it.  We delete our render and framebuffers.  We then restore the context we saved off in the first line as the current context.&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;) initWithFrame:(&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;)frame&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #26474b;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;initWithFrame&lt;span style=&quot;color: black;&quot;&gt;:frame &lt;/span&gt;pixelFormat&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_RGB565_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;depthFormat&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;preserveBackbuffer&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;NO&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;) initWithFrame:(&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;)frame pixelFormat:(&lt;span style=&quot;color: #5c2699;&quot;&gt;GLuint&lt;/span&gt;)format &lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #26474b;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;initWithFrame&lt;span style=&quot;color: black;&quot;&gt;:frame &lt;/span&gt;pixelFormat&lt;span style=&quot;color: black;&quot;&gt;:format &lt;/span&gt;depthFormat&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;preserveBackbuffer&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;NO&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;We have some initializers here.  These allow us to create our EAGLEView using different initializers.  The next initWithFrame is a bit more complex so lets go through it.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;) initWithFrame:(&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;)frame pixelFormat:(&lt;span style=&quot;color: #5c2699;&quot;&gt;GLuint&lt;/span&gt;)format depthFormat:(&lt;span style=&quot;color: #5c2699;&quot;&gt;GLuint&lt;/span&gt;)depth preserveBackbuffer:(&lt;span style=&quot;color: #aa0d91;&quot;&gt;BOOL&lt;/span&gt;)retained&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;((&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; = [&lt;span style=&quot;color: #aa0d91;&quot;&gt;super&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;initWithFrame&lt;/span&gt;:frame])) {&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CAEAGLLayer&lt;/span&gt;*&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;eaglLayer = (&lt;span style=&quot;color: #5c2699;&quot;&gt;CAEAGLLayer&lt;/span&gt;*)[&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; layer];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;The first line here just calls one of the previous init methods passing in our layer.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;eaglLayer.drawableProperties = [&lt;span style=&quot;color: #5c2699;&quot;&gt;NSDictionary&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;dictionaryWithObjectsAndKeys&lt;/span&gt;:&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #5c2699;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;/span&gt;NSNumber&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;numberWithBool&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;YES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;], &lt;/span&gt;kEAGLDrawablePropertyRetainedBacking&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;kEAGLColorFormatRGBA8&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;kEAGLDrawablePropertyColorFormat&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;This sets up the layer's drawable properties.  The two main ones sets up the ability to save off our buffer for later use (we do this in RGBA8 (bit) form).  The &lt;span style=&quot;line-height: 19px; color: rgb(92, 38, 153);&quot;&gt;kEAGLDrawablePropertyColorFormat specifies a color object to use (nil in this case).  So we aren't using an internal color buffer.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;font color=&quot;#5C2699&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;font color=&quot;#5C2699&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_format&lt;/span&gt; = format;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;_depthFormat&lt;span style=&quot;color: black;&quot;&gt; = depth;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Save off the format and depth.&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = [[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;alloc&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;initWithAPI&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;kEAGLRenderingAPIOpenGLES1&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;(&lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt; == &lt;span style=&quot;color: #aa0d91;&quot;&gt;nil&lt;/span&gt;) {&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;[&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;release&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;return&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;nil&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;Create an EAGL context using initWithAPI:  This call initializes an EAGL context and specifies that the context conforms to OpenGL ES 1.0 calls.  If we can't get a context clean up and return.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;Finally, try creating a surface (using the method above) and return an initialized view.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #26474b;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(![&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;_createSurface&lt;span style=&quot;color: black;&quot;&gt;]) {&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;[&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;release&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;return&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;nil&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;return&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;self&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;The dealloc call cleans up our view by destroying the surface and releasing the context.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) dealloc&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #26474b;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;_destroySurface&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;_context&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;release&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;_context&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;dealloc&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;The next method:&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) layoutSubviews&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;				&lt;/span&gt;bounds = [&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;bounds&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;(&lt;span style=&quot;color: #3f6e74;&quot;&gt;_autoresize&lt;/span&gt; &amp;amp;&amp;amp; ((&lt;span style=&quot;color: #2e0d6e;&quot;&gt;roundf&lt;/span&gt;(bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;) != &lt;span style=&quot;color: #3f6e74;&quot;&gt;_size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;) || (&lt;span style=&quot;color: #2e0d6e;&quot;&gt;roundf&lt;/span&gt;(bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;) != &lt;span style=&quot;color: #3f6e74;&quot;&gt;_size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;))) {&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #26474b;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;_destroySurface&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #26474b;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;_createSurface&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;checks to see if autoresize is set and if it is the size has been changed. If it has we recreate the drawing surface in our view.&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) setAutoresizesEAGLSurface:(&lt;span style=&quot;color: #aa0d91;&quot;&gt;BOOL&lt;/span&gt;)autoresizesEAGLSurface;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_autoresize&lt;/span&gt; = autoresizesEAGLSurface;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;_autoresize&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;layoutSubviews&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;The setAutoresizesEAGLSurface controls whether the surface autoresize or not based on the flag passed in.  &lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;The next three methods are utility methods for dealing with the context:&lt;/div&gt;
&lt;div&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) setCurrentContext&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(![&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;setCurrentContext&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]) {&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #c41a16;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;printf&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&amp;quot;Failed to set current context %p in %s\n&amp;quot;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, __FUNCTION__);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;BOOL&lt;/span&gt;) isCurrentContext&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;return&lt;/span&gt; ([&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;currentContext&lt;/span&gt;] == &lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt; ? &lt;span style=&quot;color: #aa0d91;&quot;&gt;YES&lt;/span&gt; : &lt;span style=&quot;color: #aa0d91;&quot;&gt;NO&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) clearCurrentContext&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(![&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;setCurrentContext&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;])&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #c41a16;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;printf&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&amp;quot;Failed to clear current context in %s\n&amp;quot;&lt;span style=&quot;color: black;&quot;&gt;, __FUNCTION__);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;These are straightforward so I won't explain them.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;Next we have a method called swapBuffers.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) swapBuffers&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #5c2699;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;EAGLContext&lt;span style=&quot;color: black;&quot;&gt; *oldContext = [&lt;/span&gt;EAGLContext&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;currentContext&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;GLuint&lt;/span&gt; oldRenderbuffer;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;(oldContext != &lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;)&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;setCurrentContext&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;The first thing this does is save off the current context and creates a local renderBuffer pointer.  It then sees if the previous context (_context) the one we just saved.  if not we make the previous one current.&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;// CHECK_GL_ERROR();&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glGetIntegerv&lt;/span&gt;(&lt;span style=&quot;color: #643820;&quot;&gt;GL_RENDERBUFFER_BINDING_OES&lt;/span&gt;, (&lt;span style=&quot;color: #5c2699;&quot;&gt;GLint&lt;/span&gt; *) &amp;amp;oldRenderbuffer);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glBindRenderbufferOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_RENDERBUFFER_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_renderbuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;Again a comment with no code (a reminder) and we get the integer value of the old renderbuffer and save it in our local variable oldRenderbuffer.  We then bind to the previous renderbuffer (_renderbuffer).  This essentially makes the previous buffer the active one and we saved the current one--we swapped the render buffers.  This might be a little confusing with &amp;quot;previous&amp;quot; and &amp;quot;current&amp;quot; all over the place.  The key to understanding this is that in this example variables with an underscore as part of the name are &amp;quot;previous&amp;quot;ly active, whereas the names without the underscore are currently active.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(![&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;presentRenderbuffer&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_RENDERBUFFER_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;])&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #c41a16;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;printf&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&amp;quot;Failed to swap renderbuffer in %s\n&amp;quot;&lt;span style=&quot;color: black;&quot;&gt;, __FUNCTION__);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;(oldContext != &lt;span style=&quot;color: #3f6e74;&quot;&gt;_context&lt;/span&gt;)&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;setCurrentContext&lt;/span&gt;:oldContext];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;We check to see if the swap worked, and then we check our context and adjust our context accordingly.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;The final two methods are the utility methods which convert coordinates between the view and the surface systems:&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;) convertPointFromViewToSurface:(&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;)point&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;				&lt;/span&gt;bounds = [&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;bounds&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;CGPointMake&lt;/span&gt;((point.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt; - bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;origin&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt;) / bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt; * &lt;span style=&quot;color: #3f6e74;&quot;&gt;_size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;, (point.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt; - bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;origin&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;) / bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt; * &lt;span style=&quot;color: #3f6e74;&quot;&gt;_size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;) convertRectFromViewToSurface:(&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;)rect&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;				&lt;/span&gt;bounds = [&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;bounds&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;CGRectMake&lt;/span&gt;((rect.&lt;span style=&quot;color: #5c2699;&quot;&gt;origin&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt; - bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;origin&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt;) / bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt; * &lt;span style=&quot;color: #3f6e74;&quot;&gt;_size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;, (rect.&lt;span style=&quot;color: #5c2699;&quot;&gt;origin&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt; - bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;origin&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;) / bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt; * &lt;span style=&quot;color: #3f6e74;&quot;&gt;_size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;, rect.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt; / bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt; * &lt;span style=&quot;color: #3f6e74;&quot;&gt;_size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;, rect.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt; / bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt; * &lt;span style=&quot;color: #3f6e74;&quot;&gt;_size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;@end&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;These utility methods are not OpenGL so I'll let you figure them out.  &lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;Ok, that's the implementation of the view.  It just creates a view and manages the buffers and surface content.  It's all the infrastructure to the drawing logic we saw in PaintingView.m&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;That's it for the GLPaint example. We saw how to draw based on touch, how to replay stored drawing data, and how to set up the drawing environment.    &lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;Again this example is pretty basic; it's not really game-quality.  But, the example does provide some basic tools you might use in a game.&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;So what's the next installment going to cover?  I think I want to take a basic OpenGL game and take it apart to learn how a simple OpenGL game works.  I'll try to find an example to go through for next time.&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;As always if you have comments or suggestions, feel free to email or Twitter me to let me know what you think.&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;Until next time...&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;/p&gt;
&lt;/p&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;/p&gt;
&lt;/div&gt;
			</description>
			<pubDate>Tue, 07 Jul 2009 10:10:08 -0400</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_vi_-_gl_paint_dissecte.html</guid>
		</item>
		<item>
			<title>Part V - GLPaint Dissected - EAGLView.h</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_v_-_glpaint_dissected_.html</link>
			<description>
&lt;div&gt;&lt;div&gt;Before I dive into this installment, let me mention some interesting news.  Apple released iPhone 3.0 which has some news dealing with OpenGL ES.  Namely, 3.0 supports OpenGL ES 2.0  which has a lot of cool capabilities over the older OpenGL ES 1.2.  Additionally, 3.0 runs faster, and if you upgrade to an iPhone 3gs  OpenGL ES runs up to about 4x faster!  This means smoother animations and more power to animate.  That's a very significant improvement in performance and great news for game developers who use OpenGL.  You may also be wondering what this means as it relates to what we've been learning/going over.  Actually, it doesn't mean anything since OpenGL ES 2.0 uses everything 1.2 does.  So everything still works.   So lets keep going!&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
In the previous installment we went through the PaintingView and saw how the app draws and animates the opening recorded writing.  In this part I'll go into the EAGLView.  We saw the version of EAGLView that comes with the iPhone SDK template.   This version is a bit different and has been customized.  Let's start with the header file.&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@class&lt;/span&gt; EAGLView;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;//PROTOCOLS:&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@protocol&lt;/span&gt; EAGLViewDelegate &amp;lt;&lt;span style=&quot;color: #5c2699;&quot;&gt;NSObject&lt;/span&gt;&amp;gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;- (&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) didResizeEAGLSurfaceForView:(EAGLView*)view; &lt;/span&gt;//Called whenever the EAGL surface has been resized&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;@end&lt;/tt&gt;&lt;/pre&gt;
&lt;div&gt;&lt;font color=&quot;#AA0D91&quot; face=&quot;Monaco, Times, 'Times New Roman', fantasy&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color=&quot;#AA0D91&quot; face=&quot;Monaco, Times, 'Times New Roman', -webkit-fantasy&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;The first thing we run into is a protocol definition which will handle resizing our EAGLView.  We'll see under what conditions this gets called later when we get into the implementation code.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color=&quot;#AA0D91&quot; face=&quot;Monaco, Times, 'Times New Roman', -webkit-fantasy&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color=&quot;#AA0D91&quot; face=&quot;Monaco, Times, 'Times New Roman', -webkit-fantasy&quot;&gt;&lt;br /&gt;
&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color=&quot;#AA0D91&quot; face=&quot;Monaco, Times, 'Times New Roman', -webkit-fantasy&quot;&gt;&lt;pre&gt;&lt;tt&gt;//CLASS INTERFACE:&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;/*&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;The view content is basically an EAGL surface you render your OpenGL scene into.&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;*/&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@interface&lt;/span&gt; EAGLView : UIView&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;{&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;The comment pretty much explains the point of this view.  That's one nice thing about this sample is the abundance of good comments.&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;@private&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;GLuint&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;_format;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;GLuint&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;_depthFormat;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;BOOL&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;_autoresize;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;EAGLContext&lt;span style=&quot;white-space:pre;&quot;&gt;				&lt;/span&gt;*_context;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;GLuint&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;_framebuffer;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;GLuint&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;_renderbuffer;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;GLuint&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;_depthBuffer;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;CGSize&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;_size;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;BOOL&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;_hasBeenCurrent;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;&amp;lt;EAGLViewDelegate&amp;gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;_delegate;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;Here are the properties.  The main thing to note here is that we declare three separate buffers.  A framebuffer that will be the displayed image, a renderbuffer (our backbuffer) where we draw before we display, and a depthBuffer which as its name implies stores depth information.  Depth is used to determine which pixels are &amp;quot;in front of&amp;quot; other pixels.  Pixels that are &amp;quot;behind&amp;quot; other pixels don't get drawn on the screen since they are obscured by the pixels in &amp;quot;front&amp;quot;.  It's a way of optimizing the drawing of complex scenes using layers.&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;the GLuint _depthFormat is essentially will be used as a flag to determine whether we store/use the depthbuffer.&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;The boolean _hasBeenCurrent will be used as a toggle for some setup code that needs to be done once.  &lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;We then have a variable to handle our delegate.&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;Next we get to the methods:&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;- (&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) initWithFrame:(CGRect)frame; &lt;/span&gt;//These also set the current context&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;) initWithFrame:(CGRect)frame pixelFormat:(GLuint)format;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;) initWithFrame:(CGRect)frame pixelFormat:(GLuint)format depthFormat:(GLuint)depth preserveBackbuffer:(&lt;span style=&quot;color: #aa0d91;&quot;&gt;BOOL&lt;/span&gt;)retained;&lt;/tt&gt;&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;These are just custom initializers that allow us to initialize this view different ways.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;We then have some property declarations:&lt;/div&gt;
&lt;div&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@property&lt;/span&gt;(&lt;span style=&quot;color: #aa0d91;&quot;&gt;readonly&lt;/span&gt;) GLuint framebuffer;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@property&lt;/span&gt;(&lt;span style=&quot;color: #aa0d91;&quot;&gt;readonly&lt;/span&gt;) GLuint pixelFormat;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@property&lt;/span&gt;(&lt;span style=&quot;color: #aa0d91;&quot;&gt;readonly&lt;/span&gt;) GLuint depthFormat;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@property&lt;/span&gt;(&lt;span style=&quot;color: #aa0d91;&quot;&gt;readonly&lt;/span&gt;) EAGLContext *context;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;The next few methods appear to deal with resizing the view (and related somehow to the delegate). We'll see how when we dive into the implementation.&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@property&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;BOOL&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; autoresizesSurface; &lt;/span&gt;//NO by default - Set to YES to have the EAGL surface automatically resized when the view bounds change, otherwise the EAGL surface contents is rendered scaled&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;@property&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;readonly&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;nonatomic&lt;span style=&quot;color: black;&quot;&gt;) CGSize surfaceSize;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@property&lt;/span&gt;(&lt;span style=&quot;color: #aa0d91;&quot;&gt;assign&lt;/span&gt;) &lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;&amp;lt;EAGLViewDelegate&amp;gt; delegate;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;We then have some custom getter-setters for the context which won't be handled via a property.&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) setCurrentContext;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;BOOL&lt;/span&gt;) isCurrentContext;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) clearCurrentContext;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;Our main animation method comes next:&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;- (&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) swapBuffers; &lt;/span&gt;//This also checks the current OpenGL error and logs an error if needed&lt;/tt&gt;&lt;/p&gt;
&lt;div&gt;&lt;font color=&quot;#007400&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;Finally, we have some utility methods that allow us to convert from iPhone to OpenGL ES coordinates.&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (CGPoint) convertPointFromViewToSurface:(CGPoint)point;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (CGRect) convertRectFromViewToSurface:(CGRect)rect;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #aa0d91;&quot;&gt;&lt;tt&gt;@end&lt;/tt&gt;&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;/div&gt;
&lt;p /&gt;
&lt;/tt&gt;&lt;p /&gt;
&lt;pre&gt;&lt;tt&gt;&lt;font color=&quot;#111111&quot; face=&quot;Georgia&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;That wasn't too bad.  We covered a lot of common details in earlier installments, so you may want to review those to refresh your recollection.  Next time we'll start on the actual implementation of this EAGLView.  It has some new things but its a fairly short file overall.&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
			</description>
			<pubDate>Tue, 23 Jun 2009 10:06:37 -0400</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_v_-_glpaint_dissected_.html</guid>
		</item>
		<item>
			<title>Part IV - GLPaint Dissected - PaintingView</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_iv_-_glpaint_dissected.html</link>
			<description>
&lt;div&gt;&lt;p&gt;
In the last installment I started taking PaintingView.m apart.  We saw a lot of setup and how the brush shape is defined from an image.  We also learned a bit about blending colors as they are drawn.  This time around, I'll finish up PaingtingView.m.&lt;/p&gt;
&lt;p&gt;Picking up from where we left off.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;pre&gt;&lt;tt&gt;// Erases the screen&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) erase&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;{&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Clear the buffer&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glClear&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_COLOR_BUFFER_BIT&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;font-family: -webkit-monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Display the buffer&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;swapBuffers&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;As the comment indicates this is used to clear the screen. The first thing that this does is call glClear passing in GL_COLOR_BUFFER_BIT which is an OpenGL flag that indicates we want to clear all the buffers that are currently enabled for color drawing.  As we've gleaned, OpenGL ES uses a lot of different buffer types, there are other flags that you can pass into glClear to clear those other buffers (e.g., depth, stencil, etc.)  The next call calls our swapBuffers method which is defined in the EAGLEView.m file.  As we saw from the XCode OpenGL ES template teardown, animation involves swapping the currently displayed buffer with the one for the next frame in a loop.  So what is actually happening here in the &amp;quot;erase&amp;quot; method is that we clear the backing buffer, and swap our buffers to make the one we just cleared visible--the screen clears.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;Next we get renderLineFromPoint:toPoint:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;pre&gt;&lt;tt&gt;// Drawings a line onscreen based on where the user touches&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) renderLineFromPoint:(&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;)start toPoint:(&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;)end&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;{&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #5c2699;&quot;&gt;GLfloat&lt;/span&gt;*&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;vertexBuffer = &lt;span style=&quot;color: #aa0d91;&quot;&gt;NULL&lt;/span&gt;;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #5c2699;&quot;&gt;NSUInteger&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;vertexMax = &lt;span style=&quot;color: #1c00cf;&quot;&gt;64&lt;/span&gt;;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;NSUInteger&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;vertexCount = &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;						&lt;/span&gt;count,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;						&lt;/span&gt;i;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;font-family: -webkit-monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;T&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;his sets up a pointer to a vertex buffer, and variables to track the maximum number and current vertex count.  Remember vertexes are the &amp;quot;corners&amp;quot; of a drawing such as a square.  But why do we have corners when drawing a curve with our finger?  &amp;quot;Corner&amp;quot; is a loose definition.  &amp;quot;Vertex&amp;quot; is really just a point that connects two lines.  So a smooth curve is really just a bunch of points connected by lines (the closer the points are to each other the smoother the curve looks).  The variables &amp;quot;count&amp;quot; and &amp;quot;i&amp;quot; are probably going to be used in loops.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;Ok, so we have a pointer to a vertex buffer, but we don't have a buffer yet. Let's get one:&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Allocate vertex array buffer&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;(vertexBuffer == &lt;span style=&quot;color: #aa0d91;&quot;&gt;NULL&lt;/span&gt;)&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;vertexBuffer = &lt;span style=&quot;color: #2e0d6e;&quot;&gt;malloc&lt;/span&gt;(vertexMax * &lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt; * &lt;span style=&quot;color: #aa0d91;&quot;&gt;sizeof&lt;/span&gt;(&lt;span style=&quot;color: #5c2699;&quot;&gt;GLfloat&lt;/span&gt;));&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;This uses a basic &amp;quot;c&amp;quot; function malloc to grab a chunnk of memory based on the number of vertices (64) we want to track and the size of the storage required per vertex.&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Add points to the buffer so there are drawing points every X pixels&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;count = &lt;span style=&quot;color: #643820;&quot;&gt;MAX&lt;/span&gt;(&lt;span style=&quot;color: #2e0d6e;&quot;&gt;ceilf&lt;/span&gt;(&lt;span style=&quot;color: #2e0d6e;&quot;&gt;sqrtf&lt;/span&gt;((end.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt; - start.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt;) * (end.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt; - start.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt;) + (end.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt; - start.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;) * (end.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt; - start.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;)) / &lt;span style=&quot;color: #643820;&quot;&gt;kBrushPixelStep&lt;/span&gt;), &lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;Ok, this is pretty much just geometry.  I'm not going to go through it bit by bit, but basically this just gets the number of points on the line we will draw based on its length divided by the number of pixels between points which we defined as 3 earlier.  This uses the passed in parameters to determine the start and end points of the line we want.&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;&lt;span style=&quot;font-family: -webkit-monospace; font-size: 10px; line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;             for&lt;/span&gt;(i = &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;; i &amp;lt; count; ++i) {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;(vertexCount == vertexMax) {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;vertexMax = &lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt; * vertexMax;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;vertexBuffer = &lt;span style=&quot;color: #2e0d6e;&quot;&gt;realloc&lt;/span&gt;(vertexBuffer, vertexMax * &lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt; * &lt;span style=&quot;color: #aa0d91;&quot;&gt;sizeof&lt;/span&gt;(&lt;span style=&quot;color: #5c2699;&quot;&gt;GLfloat&lt;/span&gt;));&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;vertexBuffer[&lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt; * vertexCount + &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;] = start.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt; + (end.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt; - start.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt;) * ((&lt;span style=&quot;color: #5c2699;&quot;&gt;GLfloat&lt;/span&gt;)i / (&lt;span style=&quot;color: #5c2699;&quot;&gt;GLfloat&lt;/span&gt;)count);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;vertexBuffer[&lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt; * vertexCount + &lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;] = start.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt; + (end.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt; - start.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;) * ((&lt;span style=&quot;color: #5c2699;&quot;&gt;GLfloat&lt;/span&gt;)i / (&lt;span style=&quot;color: #5c2699;&quot;&gt;GLfloat&lt;/span&gt;)count);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;vertexCount += &lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;font-family: -webkit-monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;/pre&gt;
&lt;pre&gt;
&lt;/pre&gt;
&lt;tt&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;This loop goes through and actually builds the points into the vertex array based on the count we just calculated.  We get an interval by dividing the line based on the count and offset to the point based on the interval. Again this isn't OpenGL, just geometry at work.  OpenGL depends a lot on geometry so if you slept through those classes, you will need to brush up.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;We've just taken a line and created a bunch of points (vertices) which we will connect with lines. Let's draw the points.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;pre&gt;&lt;tt&gt;        //Render the vertex array&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glVertexPointer&lt;/span&gt;(&lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #643820;&quot;&gt;GL_FLOAT&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, vertexBuffer);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glDrawArrays&lt;/span&gt;(&lt;span style=&quot;color: #643820;&quot;&gt;GL_POINTS&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, vertexCount);&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;font-family: -webkit-monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;We feed our vertexBuffer into glVertexPointer which takes an array and converts it into an OpenGL style vertex array--we just had a &amp;quot;c&amp;quot; style array.  The first parameter &amp;quot;2&amp;quot; indicates the number of coordinates per vertex, so we just use x,y.  You can actually go to 4 which is the default--I'll leave it up to you to figure out what 4 coordinates mean.  Each coordinate is a GL_FLOAT. The 0 is again the &amp;quot;stride&amp;quot; which we explained earlier--the offsets in the area between points, so a 0 indicates there is no dead-space between points in the array.  &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;glDrawArrays is an OpenGL call that draws the array specified.  We want to draw an array of points (GL_POINTS). There are other primitives we could draw, see the OpenGL ES documentation.  The last parameter is the number of points to draw.  Once this method runs we've drawn the line, but we've drawn it offscreen on our backing buffer so the user doesn't see the drawing being built.  We now need to swap our buffers to bring the drawing to the user.&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Display the buffer&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #26474b;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;swapBuffers&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/p&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;div&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;So this method takes two points and draws a line between the two points and displays it to the user.  This is the core of the GLPaint example from the standpoint of drawing.  All we need to do is pass in two consecutive points that the user touches on the screen, in order to draw a line between those two points.  If we monitor the touches continually (in a loop say) we can continue tracing the route of the finger on the screen.  See the previous discussion on how this might work.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;Next up is:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;&lt;span style=&quot;font-family: -webkit-monospace; font-size: 10px; line-height: 16px;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;// Reads previously recorded points and draws them onscreen. This is the Shake Me message that appears when the application launches.&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) playback:(&lt;span style=&quot;color: #5c2699;&quot;&gt;NSMutableArray&lt;/span&gt;*)recordedPaths&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;{&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;As the comments shows this is used to playback the recorded data (which we discovered is stored in the Recording.data resource.  So we have enough information now to guess at how this might work without looking at the code (we'll still do that).  We need pairs of points.  We pass those pairs of pairs of points to renderLinefromPoint:toPoint: in order to draw lines.  So playback: will probably pull pairs of points from Recording.data and pass them to renderLineFromPoint:toPoint: in a loop. Let's see.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;font-family: -webkit-monospace;&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; line-height: 19.0px; font: 12.0px Courier; color: #111111;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;NSData&lt;/span&gt;*&lt;span style=&quot;white-space:pre;&quot;&gt;				&lt;/span&gt;data = [recordedPaths &lt;span style=&quot;color: #2e0d6e;&quot;&gt;objectAtIndex&lt;/span&gt;:&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;*&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;point = (&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;*)[data bytes];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;NSUInteger&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;count = [data &lt;span style=&quot;color: #2e0d6e;&quot;&gt;length&lt;/span&gt;] / &lt;span style=&quot;color: #aa0d91;&quot;&gt;sizeof&lt;/span&gt;(&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;),&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;						&lt;/span&gt;i;&lt;/tt&gt;&lt;/p&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; line-height: 19.0px; font: 12.0px Courier; color: #111111;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 19px; font: normal normal normal 12px/normal Courier;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;We set up an NSData object pointer that points to the first item in recordedPaths.  If you remember this was initialized in our initWithFrame: method to be the contents of the resource.  We get a CGPoint pointer to the raw data in our NSData and the number of points (count) in the data block.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; line-height: 19.0px; font: 12.0px Courier; color: #111111;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; line-height: 19.0px; font: 12.0px Courier; color: #111111;&quot; /&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Render the current path&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;for&lt;/span&gt;(i = &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;; i &amp;lt; count - &lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;; ++i, ++point)&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;renderLineFromPoint&lt;span style=&quot;color: black;&quot;&gt;:*point &lt;/span&gt;toPoint&lt;span style=&quot;color: black;&quot;&gt;:*(point + &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;This loop does what I just explained would happen. Go through our recorded data and draw lines between points.  The end point becomes the new start point every time through the loop.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Render the next path after a short delay &lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[recordedPaths &lt;span style=&quot;color: #2e0d6e;&quot;&gt;removeObjectAtIndex&lt;/span&gt;:&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;([recordedPaths &lt;span style=&quot;color: #2e0d6e;&quot;&gt;count&lt;/span&gt;])&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;performSelector&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@selector&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #26474b;&quot;&gt;playback&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:) &lt;/span&gt;withObject&lt;span style=&quot;color: black;&quot;&gt;:recordedPaths &lt;/span&gt;afterDelay&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0.01&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;}&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;Ok, so what does this do?  Without actually diving into how the Recording.data is organized it looks like it is organized into an array. Each element of the array corresponds to something in the &amp;quot;SHAKE ME&amp;quot; animation and we draw each &amp;quot;something&amp;quot; after a delay.  What does &amp;quot;something&amp;quot; correspond to?  A line, a letter, or a word?  How can we tell?  Well, we could dive into the debugger.  It's easier, however to change the delay of 0.01 to 1.00 and run the app to see where the delay is.  If you do that, it's pretty obvious the &amp;quot;something&amp;quot; corresponds in a line or stroke in &amp;quot;SHAKE ME&amp;quot;.  So the Recording.data is an array of letter strokes!  This should show you that you can learn a lot just by playing with the code without having to get into the nitty-gritty of the syntax or debugging.  Once you figure out what something does, then you can focus on the syntax and all the options--if you ever need them.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;The next three methods deal with handling the iPhone touches and drawing them properly.  First up:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;// Handles the start of a touch&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)touchesBegan:(&lt;span style=&quot;color: #5c2699;&quot;&gt;NSSet&lt;/span&gt; *)touches withEvent:(&lt;span style=&quot;color: #5c2699;&quot;&gt;UIEvent&lt;/span&gt; *)event&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;{&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;				&lt;/span&gt;bounds = [&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;bounds&lt;/span&gt;];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;    &lt;span style=&quot;color: #5c2699;&quot;&gt;UITouch&lt;/span&gt;*&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;touch = [[event &lt;span style=&quot;color: #2e0d6e;&quot;&gt;touchesForView&lt;/span&gt;:&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;] &lt;span style=&quot;color: #2e0d6e;&quot;&gt;anyObject&lt;/span&gt;];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;firstTouch&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;YES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Convert touch point from UIView referential to OpenGL one (upside-down flip)&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;location&lt;/span&gt; = [touch &lt;span style=&quot;color: #2e0d6e;&quot;&gt;locationInView&lt;/span&gt;:&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;location&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt; = bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt; - &lt;span style=&quot;color: #3f6e74;&quot;&gt;location&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;The interesting thing here is that the OpenGL ES coordinate system is upside-down compared to the iPhone one--so we need to flip the Y axis. So we store the first point in the touch in the proper coordinate system (OpenGL ES).&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;// Handles the continuation of a touch.&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)touchesMoved:(&lt;span style=&quot;color: #5c2699;&quot;&gt;NSSet&lt;/span&gt; *)touches withEvent:(&lt;span style=&quot;color: #5c2699;&quot;&gt;UIEvent&lt;/span&gt; *)event&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;{  &lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;   &lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;  &lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;				&lt;/span&gt;bounds = [&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;bounds&lt;/span&gt;];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;UITouch&lt;/span&gt;*&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;touch = [[event &lt;span style=&quot;color: #2e0d6e;&quot;&gt;touchesForView&lt;/span&gt;:&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;] &lt;span style=&quot;color: #2e0d6e;&quot;&gt;anyObject&lt;/span&gt;];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Convert touch point from UIView referential to OpenGL one (upside-down flip)&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (&lt;/span&gt;firstTouch&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;firstTouch&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;NO&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;previousLocation&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = [touch &lt;/span&gt;previousLocationInView&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;previousLocation&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = bounds.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; - &lt;/span&gt;previousLocation&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;} &lt;span style=&quot;color: #aa0d91;&quot;&gt;else&lt;/span&gt; {&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;location&lt;/span&gt; = [touch &lt;span style=&quot;color: #2e0d6e;&quot;&gt;locationInView&lt;/span&gt;:&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;    &lt;span style=&quot;color: #3f6e74;&quot;&gt;location&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt; = bounds.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt; - &lt;span style=&quot;color: #3f6e74;&quot;&gt;location&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;previousLocation&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = [touch &lt;/span&gt;previousLocationInView&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;previousLocation&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = bounds.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; - &lt;/span&gt;previousLocation&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Render the stroke&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #26474b;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;renderLineFromPoint&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;previousLocation&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;toPoint&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;This does the same in flipping the Y axis.  It also connects the new point to the first point.  It then makes the current point the first point (again refer to the previous installment if you need a visual diagram of what is happening).  As long as the touch moves we get notified and this method gets called, which continues to draw the line connecting the start to the end point and making the end point the new start.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;Finally, we remove our finger from the screen:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;color: rgb(17, 17, 17); font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;// Handles the end of a touch event when the touch is a tap.&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)touchesEnded:(&lt;span style=&quot;color: #5c2699;&quot;&gt;NSSet&lt;/span&gt; *)touches withEvent:(&lt;span style=&quot;color: #5c2699;&quot;&gt;UIEvent&lt;/span&gt; *)event&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;{&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;				&lt;/span&gt;bounds = [&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;bounds&lt;/span&gt;];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;    &lt;span style=&quot;color: #5c2699;&quot;&gt;UITouch&lt;/span&gt;*&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;touch = [[event &lt;span style=&quot;color: #2e0d6e;&quot;&gt;touchesForView&lt;/span&gt;:&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;] &lt;span style=&quot;color: #2e0d6e;&quot;&gt;anyObject&lt;/span&gt;];&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (&lt;/span&gt;firstTouch&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;firstTouch&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;NO&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;previousLocation&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = [touch &lt;/span&gt;previousLocationInView&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;previousLocation&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = bounds.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; - &lt;/span&gt;previousLocation&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #26474b;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;renderLineFromPoint&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;previousLocation&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;toPoint&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;This pretty much just connects the first point to this point and we're done.  We have no need to make the last point the new start point.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;So, that is it.  This installment is definitely more interesting than the previous one.  This is where all the drawing happens after all the setup in the last part.  &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;Next time we'll get into the actual EAGLView that this sample uses. It's a bit different from the one we saw in the XCode template example, so it's worth going over.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(17, 17, 17);&quot;&gt;Until next time.  Again feel free to comment and email.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p /&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/p&gt;
&lt;p /&gt;
&lt;/tt&gt;&lt;p /&gt;
&lt;p /&gt;
&lt;/tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;font-family: -webkit-monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/tt&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;
			</description>
			<pubDate>Sun, 17 May 2009 11:13:09 -0400</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_iv_-_glpaint_dissected.html</guid>
		</item>
		<item>
			<title>Part III - GLPaint Dissected - PaintingView</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_iii_-_glpaint_dissecte.html</link>
			<description>
&lt;div&gt;&lt;p&gt;
In the last installment, we went through the AppController of GLPaint and saw that there was minimal OpenGL ES code in it.  This time around, I'm going to tackle the files PaintingView.h and initWithFrame in PaintingView.m  so let's dive right in.&lt;/p&gt;
&lt;p&gt;The first thing we come across is a set of defines:&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;#define kBrushOpacity&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;(&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;1.0&lt;/tt&gt;&lt;/span&gt; / &lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;3.0&lt;/tt&gt;&lt;/span&gt;)&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kBrushPixelStep&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;3&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kBrushScale&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;2&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kLuminosity&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;0.75&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kSaturation&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;1.0&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(28, 0, 207); font-size: 12px; line-height: 19px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: 19px;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;which itemize the characteristics of the &amp;quot;paint brush&amp;quot; we are using.  If you want to see what they do, try changing some of these values and rerunning the sample.&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: 19px;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: 19px;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;The actual interface comes next:&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(28, 0, 207); font-size: 12px; line-height: 19px;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@interface&lt;/span&gt; PaintingView : EAGLView&lt;/pre&gt;
&lt;tt&gt;
&lt;pre&gt;&lt;tt&gt;{&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;GLuint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;brushTexture&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;GLuint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;drawingTexture&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;GLuint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;drawingFramebuffer&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;location&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;previousLocation&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;Boolean&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;firstTouch&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;@property&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;nonatomic&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;readwrite&lt;span style=&quot;color: black;&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;@property&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;nonatomic&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;readwrite&lt;span style=&quot;color: black;&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGPoint&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;previousLocation&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) erase;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;@end&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;As you can see, this is a subclass of EAGLView which we went over in the first set of walkthroughs. The PaintingView here, intruduces a set of properties, the first three are OpenGL ES related.  The first two define brushTexture, and drawingTexture as GLuints (again, this is an OpenGL ES-specific data type, namely an unsigned integer.)  This probably has to do with the &amp;quot;fuzziness&amp;quot; you see when drawing in GLPaint.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;The next two are iPhone CoreGraphics (CG) point definitions.  These aren't OpenGL ES.  When you draw on the screen you have to draw by keeping track of the points your &amp;quot;touch&amp;quot; passes over in the view.  Specifically, we need to keep track of the last point, and the current point. We draw a line between the two points.  We then set the last point to be the current point and as the finger moves, it writes to a new point.  We then connect these two points, and continue as long as the finger is touching the screen.  I'm betting that's what these two properties are used for.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;img src=&quot;http://www.VisualNewt.com/OpenGL/_Media/touches.jpeg&quot; alt=&quot;touches&quot; /&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;We have the property declarations for these properties, and finally a single method to erase the display.  That's it for PaintingView.h&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;The .m file starts normally with the synthesis of the declared properties:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;&lt;span style=&quot;font-family: -webkit-monospace; font-size: 10px; line-height: 16px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;tt&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;@implementation PaintingView&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@synthesize&lt;/span&gt;  location;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@synthesize&lt;/span&gt;  previousLocation;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;The first method is initWithFrame&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;) initWithFrame:(&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;)frame&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;{&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;NSMutableArray&lt;/span&gt;*&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;recordedPaths;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGImageRef&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;brushImage;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGContextRef&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;brushContext;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;GLubyte&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;*brushData;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;size_t&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;width, height;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;This declares some local properties.  The first property is interesting.  It's a mutable array called &amp;quot;recordedPaths&amp;quot;.  I bet this will keep track of the points we move through (see image above) or the opening animation--we'll see which in a moment.. The brush image which is declared as a CGImageRef, and then a brush context.  These are again CoreGraphics objects.  &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;This is followed by brushData which is an OpenGL ES unishined byte.  At this point, I'm not sure what this is used for yet.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;We then get some dimensions for managing the width and height--of what?  Again, we don't have enough to guess at. So let's look at the code and find out.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;The first line is an &amp;quot;if&amp;quot; statement:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = [&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;initWithFrame&lt;span style=&quot;color: black;&quot;&gt;:frame &lt;/span&gt;pixelFormat&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_RGB565_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;depthFormat&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;preserveBackbuffer&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;YES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;])) {&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;setCurrentContext&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;What this does is call our parent's initWithFrame and passes in a specific pixel format: &lt;/span&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;GL_RGB565_OES.  Doing a little digging this turns out to be a constant that allows your Open GL ES program to deal with textures (rather than solid colors). Textures are managed and stored in their own separate memory areas known as &amp;quot;texture memory&amp;quot; by Open GL. We then make our PaintingView the current drawing context.&lt;span style=&quot;font-family: -webkit-monospace; font-size: 10px; line-height: 16px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0); font-family: Monaco; font-size: 12px; line-height: normal;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Courier; font-size: 10px; color: rgb(92, 38, 153);&quot;&gt;	 &lt;span style=&quot;color: rgb(0, 116, 0); font-family: Monaco; font-size: 12px; line-height: normal; white-space: normal;&quot;&gt;// Create a texture from an image&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// First create a UIImage object from the data in a image file, and then extract the Core Graphics image&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;brushImage = [&lt;span style=&quot;color: #5c2699;&quot;&gt;UIImage&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;imageNamed&lt;/span&gt;:&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;Particle.png&amp;quot;&lt;/span&gt;].CGImage;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Get the width and height of the image&lt;span style=&quot;color: rgb(17, 17, 17);&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(17, 17, 17);&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;width = &lt;span style=&quot;color: #2e0d6e;&quot;&gt;CGImageGetWidth&lt;/span&gt;(brushImage);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;height = &lt;span style=&quot;color: #2e0d6e;&quot;&gt;CGImageGetHeight&lt;/span&gt;(brushImage);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;This block of code pulls the &amp;quot;Particle.png&amp;quot; image from our resources and makes it our brush image.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint2/Particle.png&quot; alt=&quot;ShakeMe&quot; /&gt;&lt;/p&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;But when you run the program your brush doesn't look like this, what's happening?  Well it appears the program doesn't use the Particle.png as a brush but rather as a texture to draw with.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;Note the next comment:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;// Texture dimensions must be a power of 2. If you write an application that allows users to supply an image,&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;// you'll want to add code that checks the dimensions and takes appropriate action if they are not a power of 2.&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;So what are the width and height? Run the app in the debugger and you see that width = height = 64, which is a power of 2.  What happens if it's not?  Change width or height and run it again and see!  If width is set to 65 we get:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint2/width.png&quot; alt=&quot;ShakeMe&quot; /&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;Is this wrong?  Does it crash? No. The comment is just a warning that the results you get may not be perfect unless the dimensions are a power of 2.  Maybe you want this effect.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 12px; line-height: 19px;&quot;&gt;The next block does a lot.:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;// Make sure the image exists&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;(brushImage) {&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;// Allocate  memory needed for the bitmap context&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;brushData = (&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;GLubyte&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt; *) &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;malloc&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;(width * height * &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;// Use  the bitmatp creation function provided by the Core Graphics framework. &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;brushContext = &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;CGBitmapContextCreate&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;(brushData, width, width, &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;8&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;, width * &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;CGImageGetColorSpace&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;(brushImage), &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;kCGImageAlphaPremultipliedLast&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;// After you create the context, you can draw the  image to the context.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;CGContextDrawImage&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;(brushContext, &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;CGRectMake&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;0.0&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;0.0&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;CGFloat&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;)width, (&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;CGFloat&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;)height), brushImage);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;// You don't need the context at this point, so you need to release it to avoid memory leaks.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;CGContextRelease&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;(brushContext);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;If the image exists we draw the image to a temporary context that we set up in these lines.  Now we get to some OpenGL ES.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;// Use OpenGL ES to generate a name for the texture.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;			&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;glGenTextures&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;brushTexture&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;glGenTextures is an OpenGL ES call that creates a texture name and returns it in the brushTexture variable.  The 1 parameter says generate one name.  Again, the way we do things in OpenGL is we create a name and then we bind/attach the actual thing to the generated name. Just so you know, the name that's returned is not really a name, but a unique integer.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Bind the texture name. &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glBindTexture&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_TEXTURE_2D&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;brushTexture&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;This associates our name with a 2D texture.  The other option is GL_TEXTURE_1D. Once you execute the bind command, you can work with the texture.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Specify a 2D texture image, providing the a pointer to the image data in memory&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glTexImage2D&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_TEXTURE_2D&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_RGBA&lt;span style=&quot;color: black;&quot;&gt;, width, height, &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_RGBA&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_UNSIGNED_BYTE&lt;span style=&quot;color: black;&quot;&gt;, brushData);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;The next call to &lt;/span&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;glTexImage2D actually takes a portion our brush data (Particle.png drawn in our context) and makes it a drawable texture.  That is, we don't have to use our whole image as a texture.   The first parameter specifies the type of texture (2D), 0 indicates base image data (this deals with something known as &amp;quot;mipmaps&amp;quot; which we may discuss in a future blog entry), GL_RGBA indicates the number of color components (R,G,B, and alpha).  The width and height indicate the width and height of the texture image.  Both of these are supported up to 64 textels (texture pixels) each.  The second 0 indicates we don't want a border, and the second GL_RGBA states the format of the image data (which can be different than the number of color components.) GL_UNSIGNED_BYTE indicates the size of the pixel data--each pixel in the image is an unsigned byte.  And finally, brushData is a pointer to our texture image to use.  &lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Release  the image data; it's no longer needed         &lt;span style=&quot;color: #2e0d6e;&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;       free&lt;/span&gt;(brushData);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;We release our source texture data. Our texture is set up.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;        // Set the texture parameters to use a minifying filter and a linear filer (weighted average)&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glTexParameteri&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_TEXTURE_2D&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_TEXTURE_MIN_FILTER&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_LINEAR&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;You can think of &lt;/span&gt;&lt;span style=&quot;line-height: normal; white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;glTexParameteri as a call that determines how your texture is applied to various surfaces.  Here we set it up to work in our view.  The first parameter is just to specify this is a 2D texture, the second GL_TEXTURE_MIN_FILTER specifies that we want to specify how to map a texture pixel (textel) from our texture map onto an area larger than a single pixel.  This is known as minifying filter.  The actual rule for minifying is GL_LINEAR.  GL_LINEAR takes the weighted average of the 4 closest textels from the texture and uses that to map the pixel.  So, this allows OpenGL ES to interpolate a pixel that needs to be mapped.  &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Enable use of the texture&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glEnable&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_TEXTURE_2D&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;We then enable (make active) the texture so we can use it.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Set a blending function to use&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glBlendFunc&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_SRC_ALPHA&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_ONE&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(17, 17, 17);&quot;&gt;glBlendFunc sets up how we the texture map is blended onto the target view.  GL_SRC_ALPHA  says we want to use the alpha component of the source (the texture) to override the alpha of the destination (the view).  The second parameter GL_ONE says use the color components of the destination.  The first parameter therefore deals with how the source is blended, the second how the destination is blended.
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Enable blending&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glEnable&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_BLEND&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;We then enable blending when we draw. To see how this works, draw a red line, then a green line that crosses it, and then a blue one that crosses the two.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint2/RGB.png&quot; alt=&quot;ShakeMe&quot; /&gt;&lt;/p&gt;
&lt;pre&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;You end up with white due to the blending. If you draw slowly, you'll also get white, if you draw fast you get a purer color due to less blending taking place.&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;The next block takes care of actually setting up most of the OpenGL state to use.&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Set up OpenGL states&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glDisable&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_DITHER&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glMatrixMode&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_PROJECTION&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glOrthof&lt;/span&gt;(&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, frame.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, frame.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;, -&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glMatrixMode&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_MODELVIEW&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glEnable&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_TEXTURE_2D&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glEnableClientState&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_VERTEX_ARRAY&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glEnable&lt;/span&gt;(&lt;span style=&quot;color: #643820;&quot;&gt;GL_BLEND&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        g&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;lBlendFunc&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_SRC_ALPHA&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_ONE&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glEnable&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_POINT_SPRITE_OES&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glTexEnvf&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_POINT_SPRITE_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_COORD_REPLACE_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_TRUE&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glPointSize&lt;/span&gt;(width / &lt;span style=&quot;color: #643820;&quot;&gt;kBrushScale&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;Some of these I've already gone over so I won't explain them again.  Check the previous installments for more information.  &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;The new calls here are to disable dithering.  What happens if you comment this out?&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;glMatrixMode specifies that the glOrthof call will work on the GL_PROJECTION matrix (remember the matrix discussion?) rather than on the texture matrix, etc.  The second glMatrixMode says that the remainder of the calls will work on the modelview.  We enable texturing, and the vertex array (remember our square?) via the call to glEnableClientState. We enable blending set up a blending function to use, &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;The next two lines:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(41, 21, 107);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: #29156b;&quot;&gt;        glEnable&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_POINT_SPRITE_OES&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;tt&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #29156b;&quot;&gt;glTexEnvf&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_POINT_SPRITE_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_COORD_REPLACE_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_TRUE&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;use OpenGL's particle system to create a sprite (think of a graphical sprite as a rubber stamp, except that once you use the stamp, you can move the image around.)  The particle system is used to deal with things like explosions, stars, etc. That is, things that look like points.  The second line is similar to the previous &lt;/span&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;glTexParameteri call except that this one deals with setting up the texturing environment as a whole.  The first parameter says we want to deal with the sprite's environment, the second parameter indicates the actual parameter in the environment we want to modify, and GL_TRUE is the value of GL_COORD_REPLACE_OES.  So what does GL_COORD_REPLACE_OES do?  It replaces the part of the view being drawn (mapped) with our particle.  If you set this to GL_FALSE nothing will be drawn.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: normal; white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: 19px; white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;The final line in this block sets the particle size to draw to 32:&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(41, 21, 107); font-family: Courier; font-size: 12px; line-height: 19px; white-space: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(41, 21, 107); font-family: Courier; font-size: 12px; line-height: 19px; white-space: normal;&quot;&gt; &lt;span style=&quot;line-height: normal;&quot;&gt;glPointSize&lt;span style=&quot;color: #111111;&quot;&gt;(width / &lt;/span&gt;&lt;span style=&quot;color: #5e3923;&quot;&gt;kBrushScale&lt;/span&gt;&lt;span style=&quot;color: #111111;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Courier; font-size: 12px; line-height: 19px; white-space: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: 19px; white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;Essentially, this sets the size of the brush that will be drawn with.  &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: 19px; white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: 19px; white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;Next is some interesting stuff:&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;line-height: 19px; white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Courier; font-size: 12px; line-height: 19px; white-space: normal;&quot;&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;//Make sure to start with a cleared buffer&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; &lt;span style=&quot;color: #26474b;&quot;&gt;erase&lt;/span&gt;];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;//Playback recorded path, which is &amp;quot;Shake Me&amp;quot;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;recordedPaths = [&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;NSMutableArray&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;arrayWithContentsOfFile&lt;span style=&quot;color: black;&quot;&gt;:[[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;NSBundle&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;mainBundle&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;pathForResource&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;Recording&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;ofType&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;data&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;([recordedPaths &lt;span style=&quot;color: #2e0d6e;&quot;&gt;count&lt;/span&gt;])&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;performSelector&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@selector&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #26474b;&quot;&gt;playback&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:) &lt;/span&gt;withObject&lt;span style=&quot;color: black;&quot;&gt;:recordedPaths &lt;/span&gt;afterDelay&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0.2&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;return&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;self&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;We clear our view, and then get the data block we looked at in the previous installment &amp;quot;Recording&amp;quot;.  This is the data that draws &amp;quot;Shake Me&amp;quot; on the screen when it first launches.  If there is data to be played back, we invoke the method &amp;quot;playback:&amp;quot; passing it the recorded data to play back.  We then come to the end of initWithFrame.  &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;So what have we learned? We've learned about how to load an image as a texture, how to set up the texturing environment, and also how to use the particle system to define a particle as a point &amp;quot;sprite&amp;quot; as a brush. &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;One thing that is pretty evident to me is that there is a lot of setup that you have to do with OpenGL to get anything to happen.  You may be wondering, is it worth it?  Yes if you want your graphics to look good, work efficiently, and across multiple platforms.  Could you do this in a simpler manner?  Probably. Something as relatively simple as GLPaint could be done easier using CoreGraphics, with less code.  But once you get to full blown applications and games, OpenGL gives you the quality you need.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;What's next?  We'll finish up our dissection of PaintingView.m and GLPaint and get into how the actual drawing code works.  Again, feel free to comment.&lt;/span&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;
&lt;/tt&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;
			</description>
			<pubDate>Fri, 24 Apr 2009 13:37:01 -0400</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_iii_-_glpaint_dissecte.html</guid>
		</item>
		<item>
			<title>Part I - GLPaint Dissected - Overview</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_i_-_glpaint_dissected_.html</link>
			<description>
&lt;div&gt;&lt;p&gt;
In the previous installment I finished going through the XCode OpenGL ES template that is used with the iPhone. &amp;nbsp;I recently received a couple of emails asking me to go into drawing background images and to dissect the GLPaint sample that you can download off the developers site. &amp;nbsp;I've decided to go into the GLPaint example. &amp;nbsp; This might help with understanding how to set a background image as well.&lt;/p&gt;
&lt;p&gt;You can download the GLPaint sample from Apple's iPhone developer site if you're registered:&amp;nbsp;http://developer.apple.com/iphone/library/navigation/SampleCode.html&lt;/p&gt;
&lt;p&gt;So what does GLPaint do? &amp;nbsp;It allows you to use your finger to draw/paint with various colors. &amp;nbsp;Shaking the iPhone will erase the image. Note that you can't shake the iPhone using the emulator in XCode. &amp;nbsp;When you first run the application it presents a screen that looks like:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint1/shakeme.jpg&quot; alt=&quot;ShakeMe&quot; /&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 9.0px 0.0px; line-height: 19.0px; font: 12.0px Georgia; color: #111111;&quot;&gt;Notice that when you run the application it actually animates drawing the &amp;quot;Shake Me!&amp;quot; screen. &amp;nbsp; Pretty cool. &amp;nbsp; &amp;nbsp;We'll try to explain how this happens.&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;You can then select a color from the palette on the bottom and draw using your finger.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint1/shakeme2.jpg&quot; alt=&quot;ShakeMe&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The other thing about this application is that it produces sounds (useful, but not really OpenGL ES related.)&lt;/p&gt;
&lt;p&gt;So lets take a look at the actual XCode project:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint1/project.jpg&quot; alt=&quot;Project&quot; /&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;Starting at the top we have a ReadMe file which you should definitely read since it helps to explain some of the other pieces. &amp;nbsp;The &amp;quot;Classes&amp;quot; group&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint1/classes.jpg&quot; alt=&quot;Project&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;has the main application controller class, and the classes responsible for doing the actual drawing and for generating the sound effects. &amp;nbsp;We won't go into the code that's in SoundEffect.h and SoundEffect.m since they have nothing to do with OpenGL ES and are pure Cocoa. &amp;nbsp;I'll leave it up to you to figure out how they work. &amp;nbsp;We'll talk about how they are used however.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;The OpenGL ES Support group contains&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint1/opengles.jpg&quot; alt=&quot;OpenGLES&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Now this is something that sounds familiar. &amp;nbsp; I find that it always helps to attack an unknown program starting with something I already feel comfortable with. &amp;nbsp;This lets us not only reenforce what we've already learned but helps us not get too overwhelmed too fast. &amp;nbsp;But in order to understand the context of these files we need to get a feel for how they are used. &amp;nbsp;So to do that we should go through the AppController first.&lt;/p&gt;
&lt;p&gt;Finally we have the Resources group&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint1/resources.jpg&quot; alt=&quot;Resources&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This has all of the graphics and sounds the program uses. &amp;nbsp;If you select each of these in turn you can see what they look like and this will help you orient yourself with how they are actually used in the application. &amp;nbsp;For example Green.png is a green square that is used as the green control on the color palette.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint1/color.jpg&quot; alt=&quot;Color&quot; /&gt;&lt;/p&gt;
&lt;p&gt;You may be wondering what the Recording.data resource is. &amp;nbsp;It looks like a property list that has gobbeldy-gook.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint1/Recording.jpg&quot; alt=&quot;Recording&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;I'm willing to bet that this is the data that is used to drive the opening animation. &amp;nbsp;We'll try to confirm this when we get into the actual code.&lt;/p&gt;
&lt;p&gt;Also note that there is no nib or xib file in this project. &amp;nbsp;That tells me that this is a good project to use as an example for creating OpenGL ES views&amp;nbsp;programmatically. &amp;nbsp;The XCode template we went through last time builds the view using IB and some code. &amp;nbsp;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;One thing you should notice is what is in the Frameworks group:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.visualnewt.com/isolated/OpenGLES/GLPaint1/frameworks.jpg&quot; alt=&quot;Frameworks&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This project uses sound so it uses the AudioToolkit as well as the OpenGLES framework. &amp;nbsp;So if you start an OpenGL ES application from scratch rather than by using the OpenGL ES template, you'll have to include the OpenGLES framework manually. &amp;nbsp;The OpenGL ES template takes care of this step for you.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;So what next? &amp;nbsp;Well there are only a couple of files we have to deal with from an OpenGL ES perspective. &amp;nbsp;The AppController, &amp;nbsp;EAGLView, and PaintingView. &amp;nbsp; Next installment we'll go through AppController which drives everything.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;&lt;/div&gt;
			</description>
			<pubDate>Sun, 29 Mar 2009 12:36:01 -0400</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_i_-_glpaint_dissected_.html</guid>
		</item>
		<item>
			<title>Part II - GLPaint Dissected - AppController</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_ii_-_glpaint_dissected.html</link>
			<description>
&lt;div&gt;&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;In the last installment, I presented an overview of the GLPaint sample program that you can download from the Apple iPhone developer site.  This time around, I'll try to go through the AppController files.  I should probably explain how I write these.  I don't pre-plan anything apart from the main file or files I'll tackle in a given installment.  I then dive into the code and walk through it for the first time.  I write my thoughts and observations as they occur to me.  That way you get pretty much my raw thought processes as I learn along with you.   I focus on the OpenGL code since I'm assuming you have at least some basic Cocoa familiarity.  So let's dive in.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Remember GLPaint allows you to &amp;quot;paint&amp;quot; using a palette and your finger.  As you move your finger around on the screen it has to be tracked. Here is the AppController.h file.&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;font: 10.0px Monaco; color: #643820;&quot;&gt;&lt;tt&gt;#import &lt;/tt&gt;&lt;/span&gt;&amp;quot;PaintingView.h&amp;quot;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;font: 10.0px Monaco; color: #643820;&quot;&gt;&lt;tt&gt;#import &lt;/tt&gt;&lt;/span&gt;&amp;quot;SoundEffect.h&amp;quot;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;//CLASS INTERFACES:&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@interface&lt;/span&gt; AppController : NSObject &amp;lt;UIAccelerometerDelegate&amp;gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;{&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;UIWindow&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;*&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;window&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;PaintingView&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;*&lt;/span&gt;drawingView&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;UIAccelerationValue&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;myAccelerometer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;SoundEffect&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;*&lt;/span&gt;erasingSound&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;SoundEffect&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;*&lt;/span&gt;selectSound&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;CFTimeInterval&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;lastTime&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;@end&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;That's the entire header of the AppController.  The only things that seem to be OpenGL ES related are the PaintingView (which I assume will be used to do the actual painting) and the CFTimeInterval lastTime, which I'm betting will be used in sampling the drawing being done.  We'll see once we dive into the implementation.  I find it useful to come up with what I think might be going on as a &amp;quot;guess&amp;quot;.  I don't spend a lot of time on it, but it tends to get me mentally oriented even if the actual code proves me wrong later on.  It's better to have a plan and change it along the way, than not to have a plan at all and get lost.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;So on to the implementation.  The first thing we encounter is a bunch of constants:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;font: 10.0px Monaco; color: #643820;&quot;&gt;&lt;tt&gt;#import &lt;/tt&gt;&lt;/span&gt;&amp;quot;AppController.h&amp;quot;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;//CONSTANTS:&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kPaletteHeight&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;30&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kPaletteSize&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;5&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kAccelerometerFrequency&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;25&lt;/tt&gt;&lt;/span&gt; &lt;span style=&quot;font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;//Hz&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kFilteringFactor&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;0.1&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kMinEraseInterval&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;0.5&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kEraseAccelerationThreshold&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;2.0&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;// Padding for margins&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kLeftMargin&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;10.0&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kTopMargin&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;10.0&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define kRightMargin&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;10.0&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt; &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;The last three are pretty straightforward.  They define a margin.  A margin for what? Well we only have two on-screen things.  The drawing view and the palette, so the margins will be used for one or both of those.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;The top section is a bit more interesting.  It has the palette size which sets our color choices.The next four are accelerometer related.  What is the accelerometer used for? If you run the program you see that shaking the iPhone will erase your drawing.  So these are settings used to detect a shake Again these aren't OpenGL ES related per se but they are interesting if you haven't done any accelerometer coding.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;The next thing about GLPaint is that it has much better internal documentation than the OpenGL ES template that we went through earlier.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;/*&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;   HSL2RGB Converts hue, saturation, luminance values to the equivalent red, green and blue values.&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;   For details on this conversion, see Fundamentals of Interactive Computer Graphics by Foley and van Dam (1982, Addison and Wesley)&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;   You can also find HSL to RGB conversion algorithms by searching the Internet.&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;tt&gt;   See also &lt;a href=&quot;http://en.wikipedia.org/wiki/HSV_color_space&quot;&gt;&lt;span style=&quot;font: 10.0px Monaco;&quot;&gt;http://en.wikipedia.org/wiki/HSV_color_space&lt;/span&gt;&lt;/a&gt; for a theoretical explanation&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt; */&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt; HSL2RGB(&lt;span style=&quot;color: #aa0d91;&quot;&gt;float&lt;/span&gt; h, &lt;span style=&quot;color: #aa0d91;&quot;&gt;float&lt;/span&gt; s, &lt;span style=&quot;color: #aa0d91;&quot;&gt;float&lt;/span&gt; l, &lt;span style=&quot;color: #aa0d91;&quot;&gt;float&lt;/span&gt;* outR, &lt;span style=&quot;color: #aa0d91;&quot;&gt;float&lt;/span&gt;* outG, &lt;span style=&quot;color: #aa0d91;&quot;&gt;float&lt;/span&gt;* outB)&lt;/tt&gt;&lt;/pre&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Monaco; line-height: normal;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;HSL2RGB seems to be a &amp;quot;standard&amp;quot; conversion that Apple pulled from a book.  No reason not to use other people's code if you don't pirate it.  This isn't OpenGL ES, just a helper/utility function.  The iPhone frameworks tend to deal with RGBA (Red, Green, Blue, Alpha) rather than hue, saturation, luminance, otherwise this function would be built into the frameworks. So why does this application use HSL rather than RGBA?  I don't know, probably because the person who wrote it came from another development environment to the iPhone or this sample is ported from some other program.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Now on to the iPhone code.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) applicationDidFinishLaunching:(&lt;span style=&quot;color: #5c2699;&quot;&gt;UIApplication&lt;/span&gt;*)application&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;{&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;rect = [[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;UIScreen&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;mainScreen&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;applicationFrame&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGFloat&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;3&lt;/span&gt;];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Create a full-screen window&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;window&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = [[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;UIWindow&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;alloc&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;initWithFrame&lt;span style=&quot;color: black;&quot;&gt;:[[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;UIScreen&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;mainScreen&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;bounds&lt;span style=&quot;color: black;&quot;&gt;]];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;window&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;setBackgroundColor&lt;span style=&quot;color: black;&quot;&gt;:[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;UIColor&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;blackColor&lt;span style=&quot;color: black;&quot;&gt;]];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&amp;quot;applicationDidFinishLaunching&amp;quot;  first sets up a rectangle that encompasses the screen minus the status bar on the top, and then three floats &amp;quot;components&amp;quot; which may be used to hold HSL values?&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;We then create a new window and set its background to black.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Create the OpenGL drawing view and add it to the window&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;drawingView&lt;/span&gt; = [[&lt;span style=&quot;color: #3f6e74;&quot;&gt;PaintingView&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;alloc&lt;/span&gt;] &lt;span style=&quot;color: #2e0d6e;&quot;&gt;initWithFrame&lt;/span&gt;:&lt;span style=&quot;color: #2e0d6e;&quot;&gt;CGRectMake&lt;/span&gt;(rect.&lt;span style=&quot;color: #5c2699;&quot;&gt;origin&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt;, rect.&lt;span style=&quot;color: #5c2699;&quot;&gt;origin&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt;, rect.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;, rect.&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;.&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;)]; &lt;span style=&quot;color: #007400;&quot;&gt;// - kPaletteHeight &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;window&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;addSubview&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;drawingView&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;This next bit of code creates our actual OpenGL ES drawing view.  So this is a drawing layer on top of our window.  Our drawing view is a subclass of &amp;quot;PaintingView&amp;quot; which we'll go over later. The comment may be confusing.  This looks like &amp;quot;test code&amp;quot;.  This is something I occasionally do.  I try some code for example (the line without the comment):&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;drawingView = [[PaintingView alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height - kPaletteHeight )];&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;And for some reason it doesn't work, either because it doesn't do what I expect it to do, or the code isn't &amp;quot;elegant&amp;quot;.  So I comment out the bit in question and rework the code elsewhere.  I leave the comment to remind me that this is what it used to be and that I changed it someplace else.  This is just a developer technique, but if you just see the comment you may be scratching your head trying to figure out what it means.  It's not a comment that explains, it's a comment that reminds the developer.  So just ignore it. &lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Create a segmented control so that the user can choose the brush color.&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;UISegmentedControl&lt;span style=&quot;color: black;&quot;&gt; *segmentedControl = [[&lt;/span&gt;UISegmentedControl&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;alloc&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;initWithItems&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;											&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;NSArray&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;arrayWithObjects&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;												&lt;/span&gt;[&lt;span style=&quot;color: #5c2699;&quot;&gt;UIImage&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;imageNamed&lt;/span&gt;:&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;Red.png&amp;quot;&lt;/span&gt;],&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;												&lt;/span&gt;[&lt;span style=&quot;color: #5c2699;&quot;&gt;UIImage&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;imageNamed&lt;/span&gt;:&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;Yellow.png&amp;quot;&lt;/span&gt;],&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;												&lt;/span&gt;[&lt;span style=&quot;color: #5c2699;&quot;&gt;UIImage&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;imageNamed&lt;/span&gt;:&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;Green.png&amp;quot;&lt;/span&gt;],&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;												&lt;/span&gt;[&lt;span style=&quot;color: #5c2699;&quot;&gt;UIImage&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;imageNamed&lt;/span&gt;:&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;Blue.png&amp;quot;&lt;/span&gt;],&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;												&lt;/span&gt;[&lt;span style=&quot;color: #5c2699;&quot;&gt;UIImage&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;imageNamed&lt;/span&gt;:&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;Purple.png&amp;quot;&lt;/span&gt;],&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;												&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;nil&lt;/span&gt;]];&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;This creates an segmented control that will be used to manage our palette color choices (our color palette).&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Compute a rectangle that is positioned correctly for the segmented control you'll use as a brush color palette&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGRect&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; frame = &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;CGRectMake&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(rect.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;origin&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; + &lt;/span&gt;kLeftMargin&lt;span style=&quot;color: black;&quot;&gt;, rect.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;height&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; - &lt;/span&gt;kPaletteHeight&lt;span style=&quot;color: black;&quot;&gt; - &lt;/span&gt;kTopMargin&lt;span style=&quot;color: black;&quot;&gt;, rect.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;width&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; - (&lt;/span&gt;kLeftMargin&lt;span style=&quot;color: black;&quot;&gt; + &lt;/span&gt;kRightMargin&lt;span style=&quot;color: black;&quot;&gt;), &lt;/span&gt;kPaletteHeight&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;segmentedControl.frame = frame;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// When the user chooses a color, the method changeBrushColor: is called.&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[segmentedControl &lt;/span&gt;addTarget&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;action&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@selector&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #26474b;&quot;&gt;changeBrushColor&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:) &lt;/span&gt;forControlEvents&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;UIControlEventValueChanged&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;segmentedControl.segmentedControlStyle = &lt;span style=&quot;color: #2e0d6e;&quot;&gt;UISegmentedControlStyleBar&lt;/span&gt;;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Make sure the color of the color complements the black background&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;segmentedControl.tintColor = [&lt;span style=&quot;color: #5c2699;&quot;&gt;UIColor&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;darkGrayColor&lt;/span&gt;];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Set the third color (index values start at 0)&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;segmentedControl.selectedSegmentIndex = &lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt;;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Add the control to the window&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;span style=&quot;color: #3f6e74;&quot;&gt;window&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;addSubview&lt;/span&gt;:segmentedControl];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Now that the control is added, you can release it&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[segmentedControl &lt;span style=&quot;color: #2e0d6e;&quot;&gt;release&lt;/span&gt;];&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;This sets up the attributes of the palette.  No OpenGL ES.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;// Define a starting color &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #26474b;&quot;&gt;HSL2RGB&lt;/span&gt;((&lt;span style=&quot;color: #5c2699;&quot;&gt;CGFloat&lt;/span&gt;) &lt;span style=&quot;color: #1c00cf;&quot;&gt;2.0&lt;/span&gt; / (&lt;span style=&quot;color: #5c2699;&quot;&gt;CGFloat&lt;/span&gt;)&lt;span style=&quot;color: #643820;&quot;&gt;kPaletteSize&lt;/span&gt;, &lt;span style=&quot;color: #643820;&quot;&gt;kSaturation&lt;/span&gt;, &lt;span style=&quot;color: #643820;&quot;&gt;kLuminosity&lt;/span&gt;, &amp;amp;components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;], &amp;amp;components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;], &amp;amp;components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt;]);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Set the color using OpenGL&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glColor4f&lt;/span&gt;(components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;], components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;], components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt;], &lt;span style=&quot;color: #643820;&quot;&gt;kBrushOpacity&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Here we get OpenGL stuff.  First we call our helper and pass in some constants that are defined in some other file and we get RGB returned in our components array.  We are getting a default color.    The glColor4f call is an OpenGL ES call.  It takes a set of r,g,b,a parameters and sets the current color.&lt;/p&gt;
&lt;p&gt;The remainder of applicationDidFinishLaunching is straightforward:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;font-family: -webkit-monospace;&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Show the window&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;window&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;makeKeyAndVisible&lt;span style=&quot;color: black;&quot;&gt;];&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Look in the Info.plist file and you'll see the status bar is hidden&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Set the style to black so it matches the background of the application&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[application &lt;/span&gt;setStatusBarStyle&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;UIStatusBarStyleBlackTranslucent&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;animated&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;NO&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Now show the status bar, but animate to the style.&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[application &lt;/span&gt;setStatusBarHidden&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;NO&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;animated&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;YES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Configure and enable the accelerometer&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;UIAccelerometer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;sharedAccelerometer&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;setUpdateInterval&lt;span style=&quot;color: black;&quot;&gt;:(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; / &lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;kAccelerometerFrequency&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;UIAccelerometer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;sharedAccelerometer&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;setDelegate&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Load the sounds&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt; &lt;span style=&quot;color: #5c2699;&quot;&gt;NSBundle&lt;/span&gt; *mainBundle = [&lt;span style=&quot;color: #5c2699;&quot;&gt;NSBundle&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;mainBundle&lt;/span&gt;];&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;erasingSound&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = [[&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;SoundEffect&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;alloc&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;initWithContentsOfFile&lt;span style=&quot;color: black;&quot;&gt;:[mainBundle &lt;/span&gt;pathForResource&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;Erase&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;ofType&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;caf&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;selectSound&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; =  [[&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;SoundEffect&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;alloc&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;initWithContentsOfFile&lt;span style=&quot;color: black;&quot;&gt;:[mainBundle &lt;/span&gt;pathForResource&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;Select&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;ofType&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #c41a16;&quot;&gt;@&amp;quot;caf&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Monaco; line-height: normal;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Monaco;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Monaco;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px;&quot;&gt;The next method dealloc is likewise easy&lt;/span&gt;:&lt;/tt&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Monaco;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Monaco;&quot;&gt;&lt;tt&gt;&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;// Release resources when they are no longer needed,&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) dealloc&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;selectSound&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;release&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;erasingSound&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;release&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;drawingView&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;release&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;window&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;release&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;dealloc&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;Next is another graphics method:&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;// Change the brush color&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)changeBrushColor:(&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;)sender&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt; &lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CGFloat&lt;/span&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;					&lt;/span&gt;components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;3&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt; &lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Play sound&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;selectSound&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #26474b;&quot;&gt;play&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Set the new brush color&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt; &lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #26474b;&quot;&gt;HSL2RGB&lt;/span&gt;((&lt;span style=&quot;color: #5c2699;&quot;&gt;CGFloat&lt;/span&gt;)[sender selectedSegmentIndex] / (&lt;span style=&quot;color: #5c2699;&quot;&gt;CGFloat&lt;/span&gt;)&lt;span style=&quot;color: #643820;&quot;&gt;kPaletteSize&lt;/span&gt;, &lt;span style=&quot;color: #643820;&quot;&gt;kSaturation&lt;/span&gt;, &lt;span style=&quot;color: #643820;&quot;&gt;kLuminosity&lt;/span&gt;, &amp;amp;components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;], &amp;amp;components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;], &amp;amp;components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt;]);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt; &lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glColor4f&lt;/span&gt;(components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;], components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;], components[&lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt;], &lt;span style=&quot;color: #643820;&quot;&gt;kBrushOpacity&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt; }&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;Whenever the user changes colors (taps the palette) we hear a sound, and we call our helper again passing in the tapped palette color ([sender selectedSegmentIndex]).  We divide this by 5 (kPaletteSize -- the number of colors on the palette).  This passes the selected color into the helper and we get RGB out again.  This becomes our current color using the glColor4f invocation again.  &lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;Finally, the last method &amp;quot;accelerometer&amp;quot; just detects an iPhone shake and erases the drawingView.  No OpenGL ES here either.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;
&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;// Called when the accelerometer detects motion; plays the erase sound and redraws the view if the motion is over a threshold.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;) accelerometer:(&lt;span style=&quot;color: #5c2699;&quot;&gt;UIAccelerometer&lt;/span&gt;*)accelerometer didAccelerate:(&lt;span style=&quot;color: #5c2699;&quot;&gt;UIAcceleration&lt;/span&gt;*)acceleration&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;{&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #5c2699;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;UIAccelerationValue&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;length,&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;x,&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;			&lt;/span&gt;y,&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		        &lt;/span&gt;z;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Use a basic high-pass filter to remove the influence of the gravity&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;myAccelerometer&lt;/span&gt;[&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;] = acceleration.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt; * &lt;span style=&quot;color: #643820;&quot;&gt;kFilteringFactor&lt;/span&gt; + &lt;span style=&quot;color: #3f6e74;&quot;&gt;myAccelerometer&lt;/span&gt;[&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;] * (&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0&lt;/span&gt; - &lt;span style=&quot;color: #643820;&quot;&gt;kFilteringFactor&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;myAccelerometer&lt;/span&gt;[&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;] = acceleration.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt; * &lt;span style=&quot;color: #643820;&quot;&gt;kFilteringFactor&lt;/span&gt; + &lt;span style=&quot;color: #3f6e74;&quot;&gt;myAccelerometer&lt;/span&gt;[&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;] * (&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0&lt;/span&gt; - &lt;span style=&quot;color: #643820;&quot;&gt;kFilteringFactor&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;myAccelerometer&lt;/span&gt;[&lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt;] = acceleration.&lt;span style=&quot;color: #5c2699;&quot;&gt;z&lt;/span&gt; * &lt;span style=&quot;color: #643820;&quot;&gt;kFilteringFactor&lt;/span&gt; + &lt;span style=&quot;color: #3f6e74;&quot;&gt;myAccelerometer&lt;/span&gt;[&lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt;] * (&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0&lt;/span&gt; - &lt;span style=&quot;color: #643820;&quot;&gt;kFilteringFactor&lt;/span&gt;);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// Compute values for the three axes of the acceleromater&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;x = acceleration.&lt;span style=&quot;color: #5c2699;&quot;&gt;x&lt;/span&gt; - &lt;span style=&quot;color: #3f6e74;&quot;&gt;myAccelerometer&lt;/span&gt;[&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;y = acceleration.&lt;span style=&quot;color: #5c2699;&quot;&gt;y&lt;/span&gt; - &lt;span style=&quot;color: #3f6e74;&quot;&gt;myAccelerometer&lt;/span&gt;[&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;z = acceleration.&lt;span style=&quot;color: #5c2699;&quot;&gt;z&lt;/span&gt; - &lt;span style=&quot;color: #3f6e74;&quot;&gt;myAccelerometer&lt;/span&gt;[&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;//Compute the intensity of the current acceleration &lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;length = &lt;span style=&quot;color: #2e0d6e;&quot;&gt;sqrt&lt;/span&gt;(x * x + y * y + z * z);&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;// If above a given threshold, play the erase sounds and erase the drawing view&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #643820;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;((length &amp;gt;= &lt;/span&gt;kEraseAccelerationThreshold&lt;span style=&quot;color: black;&quot;&gt;) &amp;amp;&amp;amp; (&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;CFAbsoluteTimeGetCurrent&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;() &amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;lastTime&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; + &lt;/span&gt;kMinEraseInterval&lt;span style=&quot;color: black;&quot;&gt;)) {&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;/span&gt;erasingSound&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #26474b;&quot;&gt;play&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3f6e74;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;[&lt;/span&gt;drawingView&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #26474b;&quot;&gt;erase&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;		&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;lastTime&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;CFAbsoluteTimeGetCurrent&lt;span style=&quot;color: black;&quot;&gt;();&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;That's it for AppController.  As you see, there is very little OpenGL ES in this code.  It amounts to using a single call &amp;quot;glColor4f&amp;quot; to select a current color.  Everything else is normal iPhone Cocoa and the one helper routine.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;line-height: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;Next time, we'll go into the PaintingView, which as we'll see has a lot of OpenGL ES in it.  It was still worth going into the AppController code since this is what really drives the rest of the code. &lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;
&lt;/pre&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;
			</description>
			<pubDate>Sat, 11 Apr 2009 09:27:38 -0400</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_ii_-_glpaint_dissected.html</guid>
		</item>
		<item>
			<title>Part V - The iPhone OpenGL ES XCode Template Dissected - The Delegate Code</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_v_-_the_iphone_opengl_.html</link>
			<description>
&lt;div&gt;&lt;p&gt;&lt;span&gt;
In the previous installment I went through the remainder of the code in the EAGLView.m file in which we dealt with the buffer management, drawing, and FBO (frame buffer object) code needed to animate our square.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In this module, I'll go through the rest of the template code, namely the delegate files gAppDelegate.h and gAppDelegate.m.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The header, gAppDelegate.h looks like:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;//&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;//  glAppDelegate.h&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;//  gl&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;//&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;//&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;font: normal normal normal 10px/normal Monaco; color: rgb(100, 56, 32);&quot;&gt;#import &lt;/span&gt;&amp;lt;UIKit/UIKit.h&amp;gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;@class&lt;/span&gt;&lt;span&gt; &lt;/span&gt;EAGLView&lt;span&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;@interface&lt;/span&gt; glAppDelegate : NSObject &amp;lt;UIApplicationDelegate&amp;gt; {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;    &lt;/span&gt;UIWindow&lt;span&gt; *&lt;/span&gt;&lt;span&gt;window&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;    &lt;/span&gt;EAGLView&lt;span&gt; *&lt;/span&gt;glView&lt;span&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;@property&lt;span&gt; (&lt;/span&gt;nonatomic&lt;span&gt;, &lt;/span&gt;retain&lt;span&gt;) &lt;/span&gt;IBOutlet&lt;span&gt; &lt;/span&gt;&lt;span&gt;UIWindow&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;span&gt;window&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;@property&lt;span&gt; (&lt;/span&gt;nonatomic&lt;span&gt;, &lt;/span&gt;retain&lt;span&gt;) &lt;/span&gt;IBOutlet&lt;span&gt; &lt;/span&gt;&lt;span&gt;EAGLView&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;span&gt;glView&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;@end&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;p style=&quot;font: normal normal normal 12px/normal Georgia;&quot;&gt;&lt;span&gt;Here we see the declaration of a single class EAGLView which has an iPhone window declared as UIWindow, and the view the template uses declared as EAGLView within it.   There are also the corresponding property declarations.   Nothing OpenGL ES specific in all of this.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Georgia;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Georgia;&quot;&gt;&lt;span&gt;The first section of glAppDelegate.m imports the EAGLView.h header for the class we covered in the previous installments.  It also has the synthesized properties for the two properties we saw in the header.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;//&lt;/pre&gt;
&lt;pre&gt;//  glAppDelegate.m&lt;/pre&gt;
&lt;pre&gt;//  gl&lt;/pre&gt;
&lt;pre&gt;//&lt;/pre&gt;
&lt;pre&gt;//&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font: normal normal normal 10px/normal Monaco; color: rgb(100, 56, 32);&quot;&gt;#import &lt;/span&gt;&amp;quot;glAppDelegate.h&amp;quot;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font: normal normal normal 10px/normal Monaco; color: rgb(100, 56, 32);&quot;&gt;#import &lt;/span&gt;&amp;quot;EAGLView.h&amp;quot;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;@implementation&lt;span&gt; glAppDelegate&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;@synthesize&lt;span&gt; window;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;@synthesize&lt;span&gt; glView;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The first method is a UIView delegate method (as are all of the methods in this class).&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)applicationDidFinishLaunching:(&lt;span style=&quot;color: #5c2699;&quot;&gt;UIApplication&lt;/span&gt; *)application {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glView&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;animationInterval&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; / &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;60.0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;glView&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;startAnimation&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: 12.0px Georgia; color: #111111;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Georgia; color: #111111;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Georgia;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;Here we see where we set the frame rate for our animation, which is set to 1/60 of a second, which translates to 60 frames-per-second (fps).  We then call the method which starts the animation.  This is all done once the application loads.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Georgia;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Georgia;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;The next method is interesting.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Georgia; color: #111111;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Georgia; color: #111111;&quot;&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)applicationWillResignActive:(&lt;span style=&quot;color: #5c2699;&quot;&gt;UIApplication&lt;/span&gt; *)application {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glView&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;animationInterval&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; / &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;5.0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;What it does is lowers the frame rate to 20fps when the application is not active.  &amp;quot;applicationWillResignActive:&amp;quot; gets invoked when a popup alert is displayed or when the iPhone is locked.  This is interesting since this application has no built-in popup overlays.  So the only type we will probably see is something like a low battery warning, or some other system alert.  So why do we change the animation?  The main reason would be to save battery power.  The faster the animation rate, the more battery power things tend to consume.  I'm assuming animation on the iPhone works the same way--otherwise there wouldn't be a reason to do anything in this method.  I'd go one step further--because this method is called when you lock your iPhone, I'd set the animation interval to 0 fps to shut down animation completely in order to minimize the battery usage while locked.  &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;Once the application becomes active again (the iPhone is unlocked or the popup alert is dismissed) we call:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)applicationDidBecomeActive:(&lt;span style=&quot;color: #5c2699;&quot;&gt;UIApplication&lt;/span&gt; *)application {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;glView&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;animationInterval&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; / &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;60.0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;which resets our frame rate back to 60fps.&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;And finally, once our application shuts down we invoke dealloc:&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)dealloc {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;window&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;release&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;glView&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;release&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;[&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;dealloc&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;@end&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;which frees our resources.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;But what about the MainWindow.xib file?   Well there's really nothing in it that is OpenGL ES-specific.  Take a look and you'll see it merely creates a delegate and wires it up to the window.  &lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;That's it!  At it's core the XCode iPhone OpenGL ES template isn't very complicated, but the difficulty comes in understanding the API and where and when to use it properly.    I hope this has  helped a bit in the high-level understanding of OpenGL ES. I know this has helped me a bit to clear away some of the fog, as I mentioned this is my first look into OpenGL or OpenGL ES.    I always find, that if you can follow the high-level logic of an application, figuring out the details of the method call interactions amounts to looking things up in the documentation and taking your time to explore a bit.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;Now that I've finished this series what is next?  Well I've received a request from someone to go through the iPhone sample Apple provides called GLPaint which uses touch and OpenGL ES to paint.  So next time, look forward to a new series based on that.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Georgia; color: #111111;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Georgia; color: #111111;&quot;&gt; &lt;/p&gt;
&lt;/tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;/div&gt;
			</description>
			<pubDate>Sun, 15 Mar 2009 10:24:02 -0400</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_v_-_the_iphone_opengl_.html</guid>
		</item>
		<item>
			<title>Part IV - The iPhone OpenGL ES XCode Template Dissected - The Remaineder</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_iv_-_the_iphone_opengl.html</link>
			<description>
&lt;div&gt;&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;
In the last installment we spent a lot of time going into the drawView method.  We learned how OpenGL ES uses various matrices to control how things are drawn as well as the things that are drawn.   We saw that the standard template in XCode has some interesting things about it, such as rotating the view around the square rather than rotating the square itself. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;In this installment we'll go through the remainder of the EAGLView.m file.  Let's get started.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;The next method after drawView is one called &amp;quot;layoutSubviews&amp;quot;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)layoutSubviews {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    [EAGLContext setCurrentContext:context];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    [&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; destroyFramebuffer];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    [&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; createFramebuffer];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    [&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; drawView];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This method overrides the standard layoutSubviews method.  It sets the current OpenGL ES context to our context, and then it calls the destroy and createFramebuffer methods that we saw are declared as private to this class.  We then invoke the drawView method we dissected last time.    Basically, we are making sure our view is initialized properly since we don't really layout any subviews here.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The next method creates the frameBuffer.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;BOOL&lt;/span&gt;)createFramebuffer {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glGenFramebuffersOES(&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;, &amp;amp;viewFramebuffer);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glGenRenderbuffersOES(&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;, &amp;amp;viewRenderbuffer);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;These two lines return a number (in this case 1) of buffer names of the appropriate type (frame and render).  This is something I'm still trying to wrap my mind around.  OpenGL ES doesn't give you a buffer object, but rather a name associated with a buffer object.  That's what these two lines do.  The next two lines:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;font-family: -webkit-monospace;&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt;    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;actually bind (associate) an actual buffer to the name returned.   I'm not sure why OpenGL requires two steps when one call could give you a name and bind it to a buffer of the appropriate time.  It seems a bit obtuse to me.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt; [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;.layer];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This method actually allocates the buffer storage for our view (context).  In all of these methods we see &amp;quot;_OES&amp;quot; which is the OpenGL ES specific versions.  So in this line GL_RENDERBUFFER_OES allocates an OpenGL ES version of a render buffer.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;  &lt;span style=&quot;color: #2e0d6e;&quot;&gt;glFramebufferRenderbufferOES&lt;/span&gt;(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This takes our renderbuffer and attaches it to our framebuffer. So we allocated the two buffers, and we associate them together.  Again, the framebuffer is memory, while the renderbuffer is the memory that actually gets drawn and related to the hardware graphics memory.  Think of this as mapping a chunk of memory that the rendering (drawing) hardware will use to hold our drawing.  More interesting, the parameter GL_COLOR_ATTACHMENT0_OES is used to attach a color texture to our rendering buffer.  In this code think of this as mapping the two buffers together and assigning a color palette to those buffers--the OES one.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glGetRenderbufferParameterivOES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_RENDERBUFFER_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_RENDERBUFFER_WIDTH_OES&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;backingWidth&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glGetRenderbufferParameterivOES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_RENDERBUFFER_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_RENDERBUFFER_HEIGHT_OES&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;backingHeight&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;  &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The backingWidth and backingHeight are actually retrieved by glGetRenderbufferParameterivOES for our renderbuffer.  Remember we used these in our viewPort method as part of the glViewport call.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;Next we get the same set of logic with a check:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (&lt;/span&gt;USE_DEPTH_BUFFER&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;/span&gt;glGenRenderbuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;depthRenderbuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;/span&gt;glBindRenderbufferOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_RENDERBUFFER_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;depthRenderbuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glRenderbufferStorageOES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_RENDERBUFFER_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_DEPTH_COMPONENT16_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;backingWidth&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;backingHeight&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glFramebufferRenderbufferOES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_FRAMEBUFFER_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_DEPTH_ATTACHMENT_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;GL_RENDERBUFFER_OES&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;depthRenderbuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    }&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;USE_DEPTH_BUFFER is set to 0 by a define up top:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;#define USE_DEPTH_BUFFER &lt;span style=&quot;font: 12.0px Monaco; color: #1c00cf;&quot;&gt;&lt;tt&gt;0&lt;/tt&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;If we rerun this with a value of 1 nothing seems to change. This snippet of code allocates a third buffer (a depthRenderbuffer) and pretty much does the same thing as the code we just went through.  So what is a depthRenderbuffer?  A depth render buffer is used to manage such things as shadows, alpha blending, etc.--basically things associated with drawing our object but not the object itself.&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;No render buffer:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;img src=&quot;webkit-fake-url://8BBDC3CE-BF60-43F5-9396-35330F27A83E/image.tiff&quot; /&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;With a depth render buffer.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(28, 0, 207); font-size: 12px;&quot;&gt;&lt;img src=&quot;webkit-fake-url://0BC9DF53-F705-4B87-8F62-E7445DC6DE87/image.tiff&quot; /&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(28, 0, 207); font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;No obvious changes in the standard XCode template.
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;Finally, this method checks for a successful creation of our buffer:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glCheckFramebufferStatusOES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;GL_FRAMEBUFFER_OES&lt;span style=&quot;color: black;&quot;&gt;) != &lt;/span&gt;GL_FRAMEBUFFER_COMPLETE_OES&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;NSLog&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;@&amp;quot;failed to make complete framebuffer object %x&amp;quot;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;glCheckFramebufferStatusOES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_FRAMEBUFFER_OES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;));&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;        &lt;span style=&quot;color: #aa0d91;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #aa0d91;&quot;&gt;NO&lt;/span&gt;;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    }&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;return&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;YES&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;glCheckFramebufferStatusOES checks the completness of the buffer's creation.  The completeness is measured based on whether all of the required attributes for a framebuffer have been defined.  This call returns information on the attributes that are wrong or missing if it doesn't return GL_FRAMEBUFFER_COMPLETE_OES.  Throughout this installment we've been talking about something I've been calling a framebuffer.  More specifically, OpenGL calls this a &amp;quot;frame buffer object&amp;quot; or FBO.  It is more than just a buffer full of memory, but that's a major part.  It represents a real object that includes the buffer as well as images, textures, colors, etc.  The glCheckFramebufferStatusOES call checks the completeness or &amp;quot;sanity&amp;quot; of the object in terms of how drawable it is.  It's a good idea to check this prior to trying to render this buffer.  If the framebuffer is created correctly we return true, otherwise false.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;So now the idea of getting a name and attaching things to it makes a bit more sense. We aren't dealing with just a buffer, but a buffer object. We get a name (basically the type of FBO we want) then we bind various properties to it one at a time.  So it's more complicated than just combining two calls into one.  The question may still be, why can't we just use setters to do all this to our FBO?  The answer comes down to the fact that OpenGL is procedural &amp;quot;c&amp;quot; and although it has this thing known as an FBO, it's not an object in the OOP sense, so we have to set its properties via multiple procedural calls.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The next method:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(94, 57, 35);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(94, 57, 35);&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)destroyFramebuffer {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;glDeleteFramebuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;viewFramebuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;viewFramebuffer&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;glDeleteRenderbuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;viewRenderbuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;viewRenderbuffer&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;depthRenderbuffer&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;/span&gt;glDeleteRenderbuffersOES&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;depthRenderbuffer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;/span&gt;depthRenderbuffer&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    }&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;is pretty straightforward.  It deletes our frame and render buffers.  It optionally destroys the depthRenderbuffer as well if our define is set.  These are all 'c' based routines so we don't need to [x release], although setting our buffers to 0 makes sure we are in a known state in case we need to check.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;Next,&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)startAnimation {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;animationTimer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = [&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;NSTimer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;scheduledTimerWithTimeInterval&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;animationInterval&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;target&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;selector&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;@selector&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #26474b;&quot;&gt;drawView&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) &lt;/span&gt;userInfo&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;repeats&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;YES&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;div&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;is pure Cocoa.  We create an NSTimer object that repeats every &amp;quot;animationInterval&amp;quot; periods (that was set to 1/60th of a second in our initWithCoder method). Every 1/60th of a second we invoke drawView to render our frame.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This method is followed by:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)stopAnimation {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;animationTimer&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;div&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This frees our timer stopping the periodic call to drawView and is invoked by the next method.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)setAnimationInterval:(&lt;span style=&quot;color: #5c2699;&quot;&gt;NSTimeInterval&lt;/span&gt;)interval {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;animationInterval&lt;span style=&quot;color: black;&quot;&gt; = interval;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (&lt;/span&gt;animationTimer&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;        [&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;stopAnimation&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;        [&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;startAnimation&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    }&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;div&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This is a simple setter method for animationInterval.  As part of setting the interval we stop and free any old timer, and create a new timer with the new interval.  So actually setting the animationInterval value in initWithCoder causes the animation to begin.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;Finally, we haver our dealloc method which stops the animation and releases our context after detaching it from our OpenGL ES environment by setting it to nil.  Again because OpenGL ES is &amp;quot;c&amp;quot; based, we need to free any memory allocated using &amp;quot;c' functions--we didn't allocate any so there is nothing to do in the dealloc of this sample application.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;void&lt;/span&gt;)dealloc {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    [&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;stopAnimation&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt; ([&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;currentContext&lt;/span&gt;] == &lt;span style=&quot;color: #3f6e74;&quot;&gt;context&lt;/span&gt;) {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;        [&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;setCurrentContext&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    }&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    [&lt;span style=&quot;color: #3f6e74;&quot;&gt;context&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;release&lt;/span&gt;];  &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    [&lt;span style=&quot;color: #aa0d91;&quot;&gt;super&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;dealloc&lt;/span&gt;];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;}&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;That takes care of the EAGLView.m file.  We've learned how to set up our buffers and verify they are correct and complete, and got our mind around FBOs.  We saw how to draw the image, and how to control the animation.  We have a couple more minor helper methods to go through that are part of the delegate. We'll tackle those next time.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/tt&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(94, 57, 35);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(94, 57, 35);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(94, 57, 35);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(94, 57, 35);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;
			</description>
			<pubDate>Sat, 28 Feb 2009 14:03:53 -0500</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_iv_-_the_iphone_opengl.html</guid>
		</item>
		<item>
			<title>Part III - The iPhone OpenGL ES XCode Template Dissected - drawView Logic</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_iii_-_the_iphone_openg.html</link>
			<description>
&lt;div&gt;&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;Back again for more.  Last time I went over the initWithCoder method that set up our canvas and drawing layer.  We learned a bit about the EAGLDrawable protocol, and acquired a context and made sure it was set to our current drawing context.  This time around we'll dig into the drawView method which does the work of actually drawing something using OpenGL ES.  Let's start.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;We get a nice comment:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;    // Replace the implementation of this method to do your own custom drawing&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;So this is the method to focus on modifying when we want to spread our OpenGL wings and draw our own stuff.  What follows the commment looks like:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;span style=&quot;color: #aa0d91;&quot;&gt;const&lt;/span&gt; GLfloat squareVertices[] = {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;        -&lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;, -&lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;        &lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;,  -&lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;        -&lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;,  &lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;        &lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;,   &lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    };&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This line is a simple example of defining the coordinates of a square using the GLfloat data type.  Again we need to make sure we use the OpenGL intrinsic datatypes when doing this.  The definition is a matrix called squareVertices. Graphics systems tend to talk about &amp;quot;matrices&amp;quot; instead of &amp;quot;arrays&amp;quot;. Each line represents the x,y coordinates of a corner of the square.  Graph it out.  But first you have to understand the coordinate system of OpenGL.  A little research shows its a standard one--no inverted axes.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;img src=&quot;http://www.VisualNewt.com/OpenGL/_Media/pastedgraphic-9.jpeg&quot; /&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;img src=&quot;http://www.VisualNewt.com/OpenGL/_Media/pastedgraphic-10.jpeg&quot; /&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;So plotting out our square, we see it's centered around (0,0) and it doesn't have a z coordinate so its a flat square.  Nice and simple.  The next line looks similar to this:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;span style=&quot;color: #aa0d91;&quot;&gt;const&lt;/span&gt; GLubyte squareColors[] = {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;        &lt;span style=&quot;color: #1c00cf;&quot;&gt;255&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;,   &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;255&lt;/span&gt;,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;        &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;,   &lt;span style=&quot;color: #1c00cf;&quot;&gt;255&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;255&lt;/span&gt;,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;        &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;,     &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;,   &lt;span style=&quot;color: rgb(28, 0, 207);&quot;&gt;0&lt;/span&gt;,   &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;        &lt;span style=&quot;color: #1c00cf;&quot;&gt;255&lt;/span&gt;,   &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;255&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;255&lt;/span&gt;,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    };&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This is like our vertex matrix except that its a matrix with 4 elements called squareColors, and is an OpenGL ES ubyte -- unsigned byte.  Why unsigned, because you can't have a negative RGBA value.  These colors represent the kEAGLColorFormatRGBA8 color format we discussed last time. Each line therefore is a red, green, blue, alpha value.  Now why are there four lines?  This isn't very obvious unless you run the program and observe the colors.  The give away is line three (0,0,0,0)--black. If you look at the spinning cube, one of its corners is black, and the other corners map to the other lines in the matrix. The colors blend toward the center of the square.  So the template provides a fairly interesting example in that it doesn't just spin a square with a solid color.  Try changing some of the values in the matrix, and rerun the application.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This is what changing the matrix to:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;const GLubyte squareColors[] = {&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;     255, 0,   0, 255,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;     255, 0,   0, 255,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;     255, 0,   0,   0,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;     255, 0, 255, 255,&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt; };&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;looks like:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;img src=&quot;http://www.VisualNewt.com/OpenGL/_Media/pastedgraphic-11.jpeg&quot; /&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The next line should be understandable from the last session:&lt;/span&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    [EAGLContext setCurrentContext:context];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;We set the current OpenGL context to our context.   This line seems superfluous in the template (commenting it out doesn't change anything).  However, it's probably a good idea to make sure your context is set within the drawView logic in case some other part of the application resets it to something else.&lt;/span&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;According to the spec the glBindFramebufferOES method allows us to bind a framebuffer to a name.  So we are binding our viewFramebuffer to something called GL_FRAMEBUFFER_OES.  It took a while for me to figure out what this is since the specification and the iPhone docs don't explain this.  GL_FRAMEBUFFER_OES is the definition of an Open GL ES (OES) framebuffer.  So on the iPhone we bind our buffer to a definition of what it means to be an Open GL ES framebuffer.  In plain old OpenGL we can bind it to other implementations of a framebuffer.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The next line:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glViewport(&lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, backingWidth, backingHeight);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This is a call to OpenGL to set up the internal coordinate system to the size and coordinate system of the physical display.  This call returns the values of backingWidth and backingHeight which depends on the implementation or the iPhone.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The next few lines are grouped together and that tells me they are related in function:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glMatrixMode(GL_PROJECTION);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glLoadIdentity();&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glOrthof(-&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;, -&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.5f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;1.5f&lt;/span&gt;, -&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glMatrixMode(GL_MODELVIEW);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glRotatef(&lt;span style=&quot;color: #1c00cf;&quot;&gt;0.0f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0.0f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0.0f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The line&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt;    glMatrixMode(GL_PROJECTION);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;sets the current matrix to a  projection matrix.  The confusing thing here may be that it doesn't refer to our squareVertices and squareColors matrices, but rather to an internal matrix.  This internal matrix determines how coordinates are transformed.  glMatrixMode can be set to these values:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• GL_MODELVIEW  which applies tranformations to something known as a modelview matrix stack.  This allows us to position the view in the scene.  That is it allows us to move the virtual viewpoint or camera around.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• GL_PROJECTION applies transformations to a projection matrix stack.  This allows us to specify how the 3D scene is mapped to our 2D display.  Think of this as looking through a window.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• GL_TEXTURE applies transformations to a texture matrix stack.  This allows us to specify how textures (skins) are applied to our objects.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;In the template we are specifying that everything we do will affect the GL_PROJECTION matrix stack which is our window onto the square.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glLoadIdentity();&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;replaces whatever matrix is in effect with an &amp;quot;identity matrix.&amp;quot;  Think of the identity matrix as the &amp;quot;default matrix&amp;quot;.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;Because we set the glMatrixMode, this identity matrix applies to the projection matrix.  This is a complicated way of saying we have reset our 2D window on our 3D image to a default window--its at a known state.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glOrthof(-&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;, -&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.5f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;1.5f&lt;/span&gt;, -&lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;takes our window (the identity matrix) and transforms it.  Before I try to explain this, let's look at the parameters.  They map as follows:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;-1.0f, 1.0f, -1.5f,  1.5f, -1.0f, 1.0f&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;left,  right, bottom,top,  near,  far      &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;These specify the positions of the planes that determine our window.  So our window is 2 units wide, 3 units high and 2 deep (think of our window as an acrylic cube that captures our scene.) The width and height 2x3 is coincidentally the same aspect ratio as the iPhone's aspect ratio--not the screen, but the entire iPhone.  &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;img src=&quot;http://www.VisualNewt.com/OpenGL/_Media/pastedgraphic-12.jpeg&quot; /&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;So what is this &amp;quot;window&amp;quot; that we're dealing with? It's really the definition of how the 3d view is seen in two dimension and how it is clipped.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The next line:&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glMatrixMode(GL_MODELVIEW);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;resets the current matrix to be the GL_MODELVIEW which as I said controls how the view (our square) is positioned.  So we are done positioning the window, we now have to position the square so it shows up in the window.  This is done by:&lt;/span&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glRotatef(&lt;span style=&quot;color: #1c00cf;&quot;&gt;0.0f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0.0f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0.0f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;glRotate rotates the view a given number of degrees (not radians) around a point.   The parameters are (angle,x,y,z).  What this does isn't very obvious at first glance.  Why would we want to rotate around z of 1.0?  Z is the axis that is perpendicular to the screen straight at you.  So we are rotating our viewport 3 degrees to the right.  That would produce a square that is tilted.  That doesn't make sense until you realize this method drawView is used to do just that--and we are animating.  So everytime this method is called, we rotate three degrees. At 60fps (see the first part of this series) multiplied by 3 degrees, we get a full rotation of the square (360 degrees) in one second. To show you what this line controls, go ahead and comment it out, or change the 3 degrees to something else and run the app again. An important thing to note about this application.  We don't rotate the actual square.  We rotate the view *AROUND THE SQUARE*.    At this point we've rotated the view, but we haven't even drawn the square yet.  When we get around to drawing the square into our view, it will appear rotated.  There is more to this app than first meets the eye!&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;So what is left to do?  We have our square (actually the view) spinning.  The next two lines are again related.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glClearColor(&lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0.5f&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0f&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glClear(GL_COLOR_BUFFER_BIT);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The first call to glClearColor specifies the clear color for the color buffer (RGBA again).  This is the background color you see behind the spinning square.  So after every frame we clear the frame to this color. That's what glClear does. The parameter GL_COLOR_BUFFER_BIT indicates we want to clear our drawing buffer (you can clear other buffers as well.)  Try commenting out each line in turn, to see the effect.  Commenting out the glClear command lets the previous frame to stay on the screen and each succeeding frame will draw on top of the old image.  This produces a circle effect.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The next lines look like they actually draw the square.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;span style=&quot;color: #2e0d6e;&quot;&gt;glVertexPointer&lt;/span&gt;(&lt;span style=&quot;color: #1c00cf;&quot;&gt;2&lt;/span&gt;, GL_FLOAT, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, squareVertices);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;glEnableClientState&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_VERTEX_ARRAY&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;span style=&quot;color: #2e0d6e;&quot;&gt;glColorPointer&lt;/span&gt;(&lt;span style=&quot;color: #1c00cf;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #643820;&quot;&gt;GL_UNSIGNED_BYTE&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, squareColors);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;glEnableClientState&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_COLOR_ARRAY&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;glVertexPointer is a call that sets up a pointer to a matrix of vertices (corners).  In this case we point to our square matrix.  The first parameter specifies how many coordinates there are per vertex; in our square there are only two, an x and a y--no z.)  The second parameter specifies the datatype that defines a vertex.  Our matrix is declared as GLfloat squareVertices, so we specify a constant GL_FLOAT that describes GLfloats.  The third parameter (set to 0), is something known as &amp;quot;stride&amp;quot;. It's the byte offset between vertices, and the default is 0.  I have no idea why this might be useful, but I think I can be safe always leaving it as 0 if I define vertex arrays similar to the way they are for the squareVertices matrix.  So we have just pointed OpenGL at our array of corners that will be used to define our square.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;glEnableClientState&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_VERTEX_ARRAY&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;Seemingly, as in other OpenGL ES calls, this one depends on different types of arrays.  glEnableClientState enables the array type passed in as a parameter as being the &amp;quot;active&amp;quot; array.  In this line, we activate the GL_VERTEX_ARRAY as being the active one.  Essentially, this enables our squareVertices are as being active, and being displayable.  So not only do we have to tell OpenGL about our vertices, we also have to tell it, that the matrix can be displayed.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    &lt;span style=&quot;color: #2e0d6e;&quot;&gt;glColorPointer&lt;/span&gt;(&lt;span style=&quot;color: #1c00cf;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #643820;&quot;&gt;GL_UNSIGNED_BYTE&lt;/span&gt;, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, squareColors);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;This is similar to the glVertexPointer call. It points OpenGL ES to our matrix of colors squareColors.  The parameters are size, which is set to 4 (R,G,B, and A),  the GLtype again which is GL_UNSIGNED_BYTE, the stride again (0), and the actual color matrix to use.  We then enable the color array as being active using:&lt;/span&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;glEnableClientState&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #643820;&quot;&gt;GL_COLOR_ARRAY&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;Try commenting these last two lines out to see what happens.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The next line&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    glDrawArrays(GL_TRIANGLE_STRIP, &lt;span style=&quot;color: #1c00cf;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: rgb(28, 0, 207);&quot;&gt;4&lt;/span&gt;);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;obviously draws using the the &amp;quot;enabled&amp;quot; arrays.  But what is this GL_TRIANGLE_STRIP?  It's a drawing primitive that draws a triangle between vertices. There are various choices, but to draw our square the template uses this triangular method.  So what does that mean or look like?&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;img src=&quot;http://www.VisualNewt.com/OpenGL/_Media/pastedgraphic-13.jpeg&quot; /&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The second parameter is 0 which is the index number of the first element to draw, while the 4 is the count of vertices to render.  If you're still confused by the notion of GL_TRIANGLE_STRIP try adding an extra vertex to our square, and change the count parameter in glDrawArrays to 5.  You should be able to see a triangle. (Just don't choose an existing vertex location.)&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The next line &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre&gt;&lt;tt&gt;    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;we've seen at the start of this method.  The only difference is we bind to the viewRenderbuffer instead of the viewFramebuffer. So we swap buffers.&lt;/span&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;    [context presentRenderbuffer:GL_RENDERBUFFER_OES];&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The presentRenderbuffer method actually displays the buffer to the iPhone display.  We see the image.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;That's the drawView method.  There's a lot going on, especially in micromanaging the various internal OpenGL ES array states.  Now that we've gone through the various calls, let's step back and review from a high level perspective.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• drawView is the method that gets called by the timer to display a single frame of our OpenGL ES scene.  This is the method you want to modify to customize your animation.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• We have to set up two matrixes; one for the object we are drawing, and another for the color set that will be used to paint the object.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• We bind OpenGL to one of our buffers (the viewFramebuffer).  The viewFramebuffer becomes the one drawing will occur in.  Drawing occurs offscreen.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• We use glViewport to set our internal coordinate system and get back our display dimensions (in OpenGL ES terms.)&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• We set our window on the scene by specifying glMatrixMode(GL_PROJECTION), loading an identity matrix, and then applying a boundary cube using glOrthof().  Our window is a cube that encloses our scene.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• In the template, we actually move the viewport by spinning it around the square, rather than spinning the square itself.  This is done via a rotation transformation to the viewport.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• We then set up a background color that will be used to erase the display prior to painting our scene.  This is done by specifying a clear color and clearing the scene.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• We finally get around to our square by setting a GL pointer to point to our square matrix.  We enable it for drawing.  We do the same thing for our color matrix.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• The object gets rendered by calling glDrawArrays.  This completes imaging the scene in our offscreen viewFramebuffer.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• We render the contents of our offscreen viewFramebuffer and the scene is blitted (flipped) onto the iPhone display.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;• We switch our binding to our viewRenderbuffer.  The next time drawView gets called, we flip back to our viewFramebuffer.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;I'm obviously simplifying a lot of stuff here, but this is to keep things understandable.  At this stage, I'm more interested in how the Open GL ES calls fit together from a high level and what they do.   Hopefully, I've been able to provide a view of the forest as well as some of the leaves on the trees.  &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;In the next installment, I'll finish up with the implementation of drawView, since its mostly smaller methods.&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;color: rgb(46, 13, 110);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/tt&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/tt&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;
			</description>
			<pubDate>Mon, 23 Feb 2009 16:44:32 -0500</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_iii_-_the_iphone_openg.html</guid>
		</item>
		<item>
			<title>Part II - The iPhone OpenGL ES XCode Template Dissected - initWithCoder Logic</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_ii_-_the_iphone_opengl.html</link>
			<description>
&lt;div&gt;&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;In the first part of this I went through the default XCode Template Header that is created when you start an iPhone OpenGL ES project.  In this session, I'll work through the code in the actual implementation of that OpenGL ES-specific UIView.  Because I don't want to be overwhelmed--or overwhelm you I'll take it one method at a time.  So in this installment I'll work on the first real method initWithCoder, but first the preliminaries.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;The main things I take away from the header is that OpenGL ES uses various buffers to do the drawing and animation, we always draw into a &amp;quot;context&amp;quot;, and we need to make sure we deal with OpenGL ES on its own terms, by using OpenGL ES datatypes rather than those of c or Objective-C, since they seem to be platform independent.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;Ok, lets dive into the implementation EAGLView.m.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;The first thing to note are the imports:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style=&quot;font: normal normal normal 10px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;#import &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;&amp;lt;QuartzCore/QuartzCore.h&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font: normal normal normal 10px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;#import &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;&amp;lt;OpenGLES/EAGLDrawable.h&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font: normal normal normal 10px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;#import &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;&amp;quot;EAGLView.h&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;color: rgb(85, 144, 83); font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;color: rgb(85, 144, 83); font-family: Georgia;&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;OpenGL ES not only requires its own header, EAGLDrawable.h, but the Quartz header as well.  If you're new to Mac or iPhone development, Quartz is the imaging (drawing) framework used by these platforms. So OpenGL ES doesn't replace the fundamental drawing capabilities of the iPhone (or Mac), but rather adds a layer of capability on top of it.  That is to say, it seems you can't create a pure OpenGL ES application.  This makes sense, since Quartz is used to handle the platform specific UI widgets and layer drawing.   And you can't really have an application without these.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;We of course also import the header we went through in the first part.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;What follows next is:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;color: rgb(196, 26, 22); font-family: Monaco;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;color: rgb(196, 26, 22); font-family: -webkit-monospace; font-size: 10px;&quot;&gt;&lt;p style=&quot;font: normal normal normal 12px/normal Monaco; color: rgb(0, 116, 0);&quot;&gt;// A class extension to declare private methods&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(170, 13, 145);&quot;&gt;@interface&lt;/span&gt; EAGLView ()&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco; color: rgb(170, 13, 145);&quot;&gt;@property&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; (&lt;/span&gt;nonatomic&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;, &lt;/span&gt;retain&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: rgb(92, 38, 153);&quot;&gt;EAGLContext&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; *context;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco; color: rgb(170, 13, 145);&quot;&gt;@property&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; (&lt;/span&gt;nonatomic&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;, &lt;/span&gt;assign&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: rgb(92, 38, 153);&quot;&gt;NSTimer&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; *animationTimer;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: rgb(170, 13, 145);&quot;&gt;BOOL&lt;/span&gt;) createFramebuffer;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;- (&lt;span style=&quot;color: rgb(170, 13, 145);&quot;&gt;void&lt;/span&gt;) destroyFramebuffer;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco; color: rgb(170, 13, 145);&quot;&gt;@end&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;As the comment points out this is the typical way of extending the interface (header) to declare private methods.  The main thing that happens here is that we declare the attributes for the OpenGL ES context, and the timer we discussed last time.  This is done using the @property command.  Two additional private methods are declare in addition to the three public methods in the header.  The two appear complimentary, in that they manage the lifecycle of a framebuffer.  This again makes sense, since it would be bad design to have one UIView try to create buffers used by another UIView.  In this template project there is only one view, but still it's a good idea to have the view manage its own buffers.  Isolation is a good thing, as is cohesion.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;Finally we get to the start of the implementation:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco; color: rgb(170, 13, 145);&quot;&gt;@implementation&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; EAGLView&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco; color: rgb(170, 13, 145);&quot;&gt;@synthesize&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; context;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(170, 13, 145);&quot;&gt;@synthesize&lt;/span&gt; animationTimer;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;color: rgb(170, 13, 145);&quot;&gt;@synthesize&lt;/span&gt; animationInterval;&lt;/tt&gt;&lt;/pre&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Monaco; font-size: 12px;&quot;&gt;&lt;tt&gt;&lt;div&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;Nothing new here really, we just synthesize the getters and setters for the properties we defined earlier.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;We next see our first true method.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;&lt;p style=&quot;font: 12.0px Monaco; color: #007400;&quot;&gt;// You must implement this method&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;+ (&lt;span style=&quot;color: #5c2699;&quot;&gt;Class&lt;/span&gt;)layerClass {&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco; color: #2e0d6e;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;white-space:pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;NSLog&lt;span style=&quot;color: black;&quot;&gt;([[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;CAEAGLLayer&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;class&lt;span style=&quot;color: black;&quot;&gt;]&lt;/span&gt;description&lt;span style=&quot;color: black;&quot;&gt;]);&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco; color: #5c2699;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; [&lt;/span&gt;CAEAGLLayer&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;}&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;This is a class method that returns the class of CAEAGLLayer.  If you remember, this is a wrapper around our drawing environment.  So what does this return?  It returns a class CAEAGLLayer.  The comment says that you &amp;quot;must implment this&amp;quot;.  What happens if you don't?  If you take out this method and try to run the application, it throws an exception:  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;*** -[CALayer setDrawableProperties:]: unrecognized selector sent to instance 0x5242b0  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;Digging through the docs tells me that CAEAGLLayer conforms to the EAGLDrawable protocol which says that our CAEAGLLayer can be used to draw on and be displayed by an EAGLContext.  We have one of those defined in our interface.  So when we draw to our context, it actually does the display on our layer.  The setDrawableProperties is part of the EAGLDrawable protocol.  By not implementing this peculiar method, we break the protocol.  I'll work on figuring out when and how it gets called later.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;Next is the init method the real meat of this article.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco; color: #007400;&quot;&gt;//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;- (&lt;span style=&quot;color: #aa0d91;&quot;&gt;id&lt;/span&gt;)initWithCoder:(&lt;span style=&quot;color: #5c2699;&quot;&gt;NSCoder&lt;/span&gt;*)coder {&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;    &lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt; ((&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; = [&lt;span style=&quot;color: #aa0d91;&quot;&gt;super&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;initWithCoder&lt;/span&gt;:coder])) {&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;  &lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;A quick peek at the xib file doesn't really show anything OpenGL specific other than the fact that the main window is a subclass of us--which makes sense.  We'll get into the xib later.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;We finally see something new:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco; color: #007400;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;   &lt;/span&gt;// Get the layer&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;        &lt;span style=&quot;color: #5c2699;&quot;&gt;CAEAGLLayer&lt;/span&gt; *eaglLayer = (&lt;span style=&quot;color: #5c2699;&quot;&gt;CAEAGLLayer&lt;/span&gt; *)&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt;.layer;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;The self.layer returns the generic UIView's CoreAnimation layer.  This is the layer that is used for drawing things on the view.  This is a drawing surface used by the iPhone. We cast this to a CAEAGLLayer, so we can deal with the drawing layer as if it were an OpenGL ES drawing layer instead of a CoreAnimation one.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt; eaglLayer.&lt;span style=&quot;color: #5c2699;&quot;&gt;opaque&lt;/span&gt; = &lt;span style=&quot;color: #aa0d91;&quot;&gt;YES&lt;/span&gt;;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;Then makes the layer opaque.  Interesting in that this is done to the underlying UIView, not to the coerced OpenGL ES layer.  This doesn't really do anything obvious in the template.  If you comment this line out and rerun the app it looks identical. You probably want to set the layer to be opaque in the event you want your view to be a subview on top of something else.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;The next line:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;    eaglLayer.drawableProperties = [&lt;span style=&quot;color: #5c2699;&quot;&gt;NSDictionary&lt;/span&gt; &lt;span style=&quot;color: #2e0d6e;&quot;&gt;dictionaryWithObjectsAndKeys&lt;/span&gt;: &lt;span style=&quot;color: rgb(92, 38, 153);&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;NSNumber&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2e0d6e;&quot;&gt;numberWithBool&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;NO&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;], &lt;/span&gt;kEAGLDrawablePropertyRetainedBacking&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;kEAGLColorFormatRGBA8&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;kEAGLDrawablePropertyColorFormat&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa0d91;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;handles the EAGLDrawable protocol by setting the drawableProperties which is a dictionary that describes the properties of the drawing surface (our layer.)&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt; This is defined as a dictionary.  So it seems OpenGL ES allows us to specify how the background looks/acts in addition to the actual thing we are drawing. That is to say, we not only have to worry about drawing a square (or something), but have to also worry about drawing the background properly by setting its drawableProperties.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;There are two pairs in this dictionary.  The first key:  kEAGLDrawablePropertyRetainedBacking is set to 'false'.  What kEAGLDrawablePropertyRetainedBacking does is determine whether the surface retains whatever is drawn on it.  The way I understand this is when you draw on the surface (layer) the image drawn is not treated as an object that can be refreshed by the surface, but rather as a phantom image that either the code has to refresh, or is subject to erasure.  A simpler way to put it is the layer won't autorefresh its contents.  The documentation states this is the preferred and default setting.  That's my interpretation--let me know if I'm mistaken.  The second key: kEAGLDrawablePropertyColorFormat is a little easier to understand.  This sets the internal color buffer for the layer.  The template sets this to: kEAGLColorFormatRGBA8 which is a 16 bit RGB with Alpha.  (This amounts to 2 to the 16th power if you didn't know--a ton of color choices.) This is the default value  In fact this is the default dictionary for drawableProperties. What is interesting, is if you comment out this line and rerun the application, the color scheme of the cube seems to change--it has more white. I'm not sure why.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;So that takes care of setting up our drawing layer.  We now need to deal with the context.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;color: rgb(46, 13, 110);&quot;&gt;&lt;span style=&quot;color: #3f6e74;&quot;&gt;context&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = [[&lt;/span&gt;&lt;span style=&quot;color: #5c2699;&quot;&gt;EAGLContext&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;alloc&lt;span style=&quot;color: black;&quot;&gt;] &lt;/span&gt;initWithAPI&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;kEAGLRenderingAPIOpenGLES1&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;So this creates our OpenGL ES drawing context, and specifies that it uses the OpenGL ES 1.0 API.   kEAGLRenderingAPIOpenGLES1 is the only option available for the iPhone as of 2.2. In a more general sense, I guess you can create an OpenGL context, and it conforms to a given OpenGL API.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;The next snippet is important.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;        &lt;span style=&quot;color: #aa0d91;&quot;&gt;if&lt;/span&gt; (!context || ![EAGLContext setCurrentContext:context]) {&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;            [&lt;span style=&quot;color: #aa0d91;&quot;&gt;self&lt;/span&gt; release];&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;            &lt;span style=&quot;color: #aa0d91;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #aa0d91;&quot;&gt;nil&lt;/span&gt;;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;        }&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;This checks to make sure we got a valid context object, and sets the current OpenGL ES context to be the context we just created.  If we can't set the context we exit.  Why is that?  Well from our dissection of the header, we found out that we can only draw into a context, so if we can't get one or set it to be the current context, we can't draw anything, so we may as well qui&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia; font-size: 14px;&quot;&gt;t.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;   &lt;br /&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;        animationInterval = &lt;span style=&quot;color: #1c00cf;&quot;&gt;1.0&lt;/span&gt; / &lt;span style=&quot;color: #1c00cf;&quot;&gt;60.0&lt;/span&gt;;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;Sets the animation interval (frame rate) to 1/60 of a second, so fps is 60.  That's very good for animation.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px; color: rgb(17, 17, 17);&quot;&gt;That's the end of the initWithCoder method.  Next time we'll tackle the drawView method.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;  &lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: 12.0px Monaco;&quot;&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;div&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;/tt&gt;&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;
			</description>
			<pubDate>Sat, 21 Feb 2009 22:20:41 -0500</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_ii_-_the_iphone_opengl.html</guid>
		</item>
		<item>
			<title>Part I - The iPhone OpenGL ES XCode Template Header Dissected</title>
			<link>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_i_-_the_iphone_opengl_.html</link>
			<description>
&lt;div&gt;&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;If you create, build and run the sample template you end up with an iPhone application that spins a multicolored square. Let's dive in and see if I can make sense of this.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;img src=&quot;http://www.VisualNewt.com/OpenGL/_Media/pastedgraphic-14.jpeg&quot; style=&quot;outline:none;&quot; /&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;The critical file is EAGLView.m, so let's take a look at how it's defined. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;&lt;span style=&quot;color: rgb(67, 148, 80);&quot;&gt;/*&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;&lt;span style=&quot;color: rgb(67, 148, 80);&quot;&gt;This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;&lt;span style=&quot;color: rgb(67, 148, 80);&quot;&gt;The view content is basically an EAGL surface you render your OpenGL scene into.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;&lt;span style=&quot;color: rgb(67, 148, 80);&quot;&gt;Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia;&quot;&gt;&lt;span style=&quot;color: rgb(67, 148, 80);&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;The comment refers to CAEAGLLayer which the iPhone docs state is the canvas in which OpenGL ES drawing occurs.  It also says that this is displayed by  CoreAnimation--my guess then is that CoreAnimation is responsible for doing at least some of the graphics &amp;quot;heavy lifting&amp;quot; for OpenGL ES.  I could be wrong, but I'm going with that until something else proves me wrong.  Does it matter?  Probably, if  I&amp;quot;m interested in performance issues, but at this stage I'm just trying to wrap my mind around what is going on.&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;AGLView.h says that this is a plain UIView. No protocols or delegates; nice and simple. All of the properties are private. The first thing we really see that is new are the two dimensions  &lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;tt&gt;&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;/* The pixel dimensions of the backbuffer */&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;GLint&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;backingWidth&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;GLint&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;backingHeight&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;Ok, the first question is, what is a &amp;quot;backbuffer&amp;quot;?  I have a little basoc animation-programming background, so I have a guess. I'm willing to guess that the backbuffer is the offscreen buffer we draw to while the actual screen view displays a completed rendering. We do this in order to not show the screen actually drawing. So we &amp;quot;blit&amp;quot; the backbuffer to the main view in order to animate a frame. &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/tt&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;
&lt;/span&gt;&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;The actual dimensions are delared as GLint. Obviously, these are integers, but why declare them as GLint?  According to the spec, GLints datatypes are not &amp;quot;c&amp;quot; datatypes, and a GLint is a 32bit integer. Does it matter from the perspective of our work?  Probably not. It's sufficient that we know we just use the GL-specific datatypes rather than the iPhone or &amp;quot;c&amp;quot; datatypes. So we've just defined variables to hold the height and width of the backbuffer.  What if we don't want to do animation?  We can probably get rid of the backbuffer if all we want to do is create a static screen using OpenGL ES.&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;The next property is defined as:  &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;    &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; color: rgb(85, 144, 83);&quot;&gt;EAGLContext&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; color: rgb(85, 144, 83);&quot;&gt; *&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; color: rgb(85, 144, 83);&quot;&gt;context&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; color: rgb(85, 144, 83);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(85, 144, 83);&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;The &amp;quot;context&amp;quot; is the environment to which we draw, and everything we draw uses a context. The iPhone docs say we have to bind/attach a framebuffer before we can actually use the context. So how is a backbuffer different from a framebuffer?  A buffer is just a glob of memory. The backbuffer is basically a framebuffer that will be displayed--think of it as the next framebuffer.  The spec says specifically that a framebuffer is related to the graphics hardware.  Do I have to worry about this?  Probably--but not from the point of learning.  I'll probably have to figure out whether/how the iPhone graphics chips deal with framebuffers if I want optimal performance, but for right now, that's just a point of interest.&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;The next bit:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;  &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;/* OpenGL names for the renderbuffer and framebuffers used to render to this view */&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;GLuint&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;viewRenderbuffer&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;, &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;viewFramebuffer&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;color: rgb(85, 144, 83); font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;uses the term &amp;quot;renderbuffer.&amp;quot;  A &amp;quot;renderbuffer&amp;quot; is just the buffer that is being drawn--it is a 2D pixel image.  Why is this important?  A quick browse of OpenGL on the web and even the EAGLView.m file shows that OpenGL uses matrices (arrays) to describe an object's vertices (points).  So a lot of OpenGL ES is based on vector graphics, not solid images.  The solid images come from rendering (drawing) a vector image and then &amp;quot;filling it in&amp;quot;.  A vector image is a based on lines and points.  But the spinning square is made up of colored pixels. It seems obvious we need to somehow convert the vector representation to a bitmap one.  The renderbuffer is the result of that transformation, is my guess.&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;img src=&quot;http://www.VisualNewt.com/OpenGL/_Media/pastedgraphic-15.jpeg&quot; style=&quot;outline:none;&quot; /&gt;  A vector graphics cube&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;img src=&quot;http://www.VisualNewt.com/OpenGL/_Media/pastedgraphic-16.jpeg&quot; alt=&quot;imgres.jpg&quot; /&gt;  A bitmap cube.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;Now that we have a &amp;quot;gut feel&amp;quot; for these buffers, the next thing to note is that they are declared as GLuints--integers again.  So these must be pointers--but they don't use the 'c' * pointer syntax? Interesting if true--I guess we'll see how these variables are used.&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;  &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;/* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;GLuint&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;depthRenderbuffer&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;color: rgb(85, 144, 83); font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;This appears to describe the bit-depth of the renderBuffer.  But the comment refers to viewFrameBuffer--confusing.  Is it one, or the other or both?  I'm willing to bet its both.  After all, following my logic (which I admit can be totally wrong since I'm learning this for the first time) both buffers get displayed on the iPhone, so its a good idea to have a consistent bit-depth for every buffer that gets displayed.  depthRenderBuffer will probably be used to hold a number that describes the max number of bits used to hold color information (maximum number of colors).&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;Finallly we have two Cocoa properties:&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;  &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;NSTimer&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt; *&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;animationTimer&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;NSTimeInterval&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;animationInterval&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span style=&quot;color: rgb(85, 144, 83); font-family: Georgia;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;Nothing fancy here, a timer and a timer interval that I bet will be used to drive the animation by triggering how fast (frequently) the frames flip.&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-size: 14px;&quot;&gt;We then have the property and method declarations:
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p style=&quot;font: normal normal normal 12px/normal Monaco;&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;  @property&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;NSTimeInterval&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;animationInterval&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; color: rgb(85, 144, 83);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;   - (&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;void&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;)startAnimation;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;   - (&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;void&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;)stopAnimation;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;   - (&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;void&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 12px; color: rgb(85, 144, 83);&quot;&gt;)drawView;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: rgb(85, 144, 83); font-family: Georgia; font-size: 12px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;Nice understandable names.&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;&lt;span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;That's it for part one.  Let me know what you think, or if I'm totally off track; I'm sure I've made some incorrect assumptions along the way, but as I said this is my attempt at learning.  You learn by making mistakes.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: Georgia; font-size: 14px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;
			</description>
			<pubDate>Sun, 15 Feb 2009 11:20:38 -0500</pubDate>
			<guid>http://www.VisualNewt.com/OpenGL/learning_iphones_opengl_es/part_i_-_the_iphone_opengl_.html</guid>
		</item>
 	</channel>
</rss>

