<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-627201247416879277</id><updated>2024-02-18T23:35:26.963-08:00</updated><category term="OpenGL ES"/><category term="Xcode 4"/><category term="iOS 5"/><category term="Gestures"/><category term="Color Picking"/><category term="Textures"/><title type='text'>head noodles</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.headnoodles.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/627201247416879277/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://www.headnoodles.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04188436224275642399</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-627201247416879277.post-3124386412810908238</id><published>2012-03-02T20:06:00.000-08:00</published><updated>2012-03-07T18:07:29.703-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Color Picking"/><category scheme="http://www.blogger.com/atom/ns#" term="Gestures"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS 5"/><category scheme="http://www.blogger.com/atom/ns#" term="OpenGL ES"/><category scheme="http://www.blogger.com/atom/ns#" term="Xcode 4"/><title type='text'>Picky, Part II</title><content type='html'>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
  &lt;meta http-equiv=&quot;Content-Style-Type&quot; content=&quot;text/css&quot;&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;meta name=&quot;Generator&quot; content=&quot;Cocoa HTML Writer&quot;&gt;
  &lt;meta name=&quot;CocoaVersion&quot; content=&quot;1138.32&quot;&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
    p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; min-height: 17.0px}
    p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
    p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; min-height: 22.0px}
    p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c800a3}
    p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}
    p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}
    p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px}
    p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #430084}
    p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #418289}
    p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008b00}
    span.s1 {color: #000000}
    span.s2 {color: #c800a3}
    span.s3 {color: #2f00dd}
    span.s4 {font: 14.0px Menlo}
    span.s5 {font: 11.0px Menlo}
    span.s6 {color: #7822ac}
    span.s7 {color: #418289}
    span.s8 {color: #430084}
    span.s9 {color: #265a5f}
    span.s10 {color: #e00000}
    span.Apple-tab-span {white-space:pre}
  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p class=&quot;p1&quot;&gt;This is a continuation of my last post, where I set up color picking for the red GLKit cube.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;In this post I&#39;m setting up color picking for the blue 2.0 shader cube.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;I&#39;m starting off right where I left off, with the changes I made in my last post already made.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;I&#39;m using the exact same strategy as last time.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Namely, re-rendering the scene off screen in response to a user tap, but with lighting turned off and a unique color set.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;The implementation is a little more involved since we have to communicate with the shader, but on the other hand, we can use a lot of the same work that we have already done.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Just as a reminder, when we left off, we had the red cube hooked up to the color picker so it got smaller whenever it was clicked on.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDyd8U0gTtLpxshazw6cLigPmm1EXIUif9cxRmptmCcRSlzohBo-kPxZx1A8xMHXF6a4fNgklL10ESH9BPHheMmxWqQ4tyjC1EnidmU2w_AFuoP0FlVC_BkU1K9TWcdEwjOtAd6-ElJPwL/s1600/Screen+Shot+2012-03-02+at+5.15.29+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; width=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDyd8U0gTtLpxshazw6cLigPmm1EXIUif9cxRmptmCcRSlzohBo-kPxZx1A8xMHXF6a4fNgklL10ESH9BPHheMmxWqQ4tyjC1EnidmU2w_AFuoP0FlVC_BkU1K9TWcdEwjOtAd6-ElJPwL/s320/Screen+Shot+2012-03-02+at+5.15.29+PM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step One:&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Modify the vertex shader&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;The vertex shader cannot have a hard coded diffuse light color anymore, since we have to change it based on whether we&#39;re rendering it for the screen or for picking.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;We also need to be able to turn lighting on or off.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;We can accomplish both of those tasks by setting up uniform variables.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Modify the Shader.vsh file so it looks like this:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;attribute&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;vec4&lt;span class=&quot;s1&quot;&gt; position;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;attribute&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;vec3&lt;span class=&quot;s1&quot;&gt; normal;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;s2&quot;&gt;varying&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;lowp&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;vec4&lt;/span&gt; colorVarying;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;s2&quot;&gt;uniform&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;mat4&lt;/span&gt; modelViewProjectionMatrix;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;s2&quot;&gt;uniform&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;mat3&lt;/span&gt; normalMatrix;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;uniform&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;vec4&lt;span class=&quot;s1&quot;&gt; color;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;uniform&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;bool&lt;span class=&quot;s1&quot;&gt; lit;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;s2&quot;&gt;void&lt;/span&gt; main()&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;{&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;if&lt;/span&gt; (lit)&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;{&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;vec3&lt;/span&gt; eyeNormal = normalize(normalMatrix * normal);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;vec3&lt;/span&gt; lightPosition = &lt;span class=&quot;s2&quot;&gt;vec3&lt;/span&gt;(&lt;span class=&quot;s3&quot;&gt;0.0&lt;/span&gt;, &lt;span class=&quot;s3&quot;&gt;0.0&lt;/span&gt;, &lt;span class=&quot;s3&quot;&gt;1.0&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;float&lt;/span&gt; nDotVP = max(&lt;span class=&quot;s3&quot;&gt;0.0&lt;/span&gt;, dot(eyeNormal, normalize(lightPosition)));&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;                 &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;        &lt;/span&gt;colorVarying = color * nDotVP;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;}&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;else&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;{&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;        &lt;/span&gt;colorVarying = color;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;}&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;gl_Position = modelViewProjectionMatrix * position;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;}&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;The first thing we had to do was declare the uniform variables &lt;span class=&quot;s4&quot;&gt;color&lt;/span&gt; and &lt;span class=&quot;s4&quot;&gt;lit&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;The uniform keyword simply means these values remain the same for all the vertices passed to the shader during the function call.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Inside the main function, we wrapped the existing lighting code inside an if statement.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;I&#39;d really rather not have control logic inside my shader, but for this example, maybe it&#39;s ok.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Notice how the vec4 &lt;span class=&quot;s4&quot;&gt;diffuseColor&lt;/span&gt; declaration went away.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Now we&#39;re using the uniform &lt;span class=&quot;s4&quot;&gt;color&lt;/span&gt; variable in its place.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Finally, if &lt;span class=&quot;s4&quot;&gt;lit&lt;/span&gt; is set to false, we simply assign &lt;span class=&quot;s4&quot;&gt;colorVarying &lt;/span&gt;equal to&lt;span class=&quot;s4&quot;&gt; color.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p8&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p8&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step Two:&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Connect the uniforms in the view controller code&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Now that we have the vertex shader set up, we need to pass it correct values.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;This involves creating and configuring the two uniform variables in our view controller.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Start by adding two new members to the uniform enum near the top of the ViewController.m file.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;When you&#39;re done, it should look like this:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;enum&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;{&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;UNIFORM_MODELVIEWPROJECTION_MATRIX,&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;UNIFORM_NORMAL_MATRIX,&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;UNIFORM_COLOR,&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;UNIFORM_LIT,&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;NUM_UNIFORMS&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;};&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Next, declare two new variables in the ViewController interface section.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;I put mine right below the &lt;span class=&quot;s4&quot;&gt;_normalMatrix&lt;/span&gt; declaration.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GLKVector4&lt;/span&gt; _color;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GLboolean&lt;/span&gt; _lit;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Next, initialize the two variables you just declared in the setupGL function.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;I put mine at the end after my &lt;span class=&quot;s4&quot;&gt;_scale&lt;/span&gt; initialization from the last post.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;I also initialized the color to the same diffuse color value that used to be hard coded in the vertex shader.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;_color&lt;/span&gt; = &lt;span class=&quot;s8&quot;&gt;GLKVector4Make&lt;/span&gt;(&lt;span class=&quot;s3&quot;&gt;0.4f&lt;/span&gt;, &lt;span class=&quot;s3&quot;&gt;0.4f&lt;/span&gt;, &lt;span class=&quot;s3&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s3&quot;&gt;1.0f&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;_lit&lt;/span&gt; = &lt;span class=&quot;s2&quot;&gt;true&lt;/span&gt;;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Now, in the &lt;span class=&quot;s4&quot;&gt;loadShaders&lt;/span&gt; function, add the code to get the locations of the two new uniforms we added:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p9&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;uniforms&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;UNIFORM_COLOR&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;] = &lt;/span&gt;glGetUniformLocation&lt;span class=&quot;s1&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;_program&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s10&quot;&gt;&quot;color&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p9&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;uniforms&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;UNIFORM_LIT&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;] = &lt;/span&gt;glGetUniformLocation&lt;span class=&quot;s1&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;_program&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s10&quot;&gt;&quot;lit&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;This code goes right after the two &lt;span class=&quot;s4&quot;&gt;glGetUniformLocation&lt;/span&gt; calls that already exist near the end of the function. &lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;We are simply getting the uniform IDs from OpenGL and storing them in our uniforms array for later use.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Finally, in the renderGL function we wrote in the last post, add the following code right below the two &lt;span class=&quot;s4&quot;&gt;glUniformMatrix*&lt;/span&gt; calls that are already there.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;glUniform4fv&lt;/span&gt;(&lt;span class=&quot;s7&quot;&gt;uniforms&lt;/span&gt;[&lt;span class=&quot;s9&quot;&gt;UNIFORM_COLOR&lt;/span&gt;], &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;s7&quot;&gt;_color&lt;/span&gt;.&lt;span class=&quot;s6&quot;&gt;v&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;glUniform1i&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;(&lt;/span&gt;uniforms&lt;span class=&quot;s1&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;UNIFORM_LIT&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;], &lt;/span&gt;_lit&lt;span class=&quot;s1&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;This is the code that actually assigns the values we put in &lt;span class=&quot;s4&quot;&gt;_color&lt;/span&gt; and &lt;span class=&quot;s4&quot;&gt;_lit&lt;/span&gt; with the uniform variables we declare and use in the vertex shader.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;As a sanity check, it&#39;s a good idea to run your program in the simulator at this point.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;It should behave the same as it did at the beginning of this post.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step Three:&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Picking&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Now that we&#39;ve added the ability to change the blue cube&#39;s color, we need to take advantage of it.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Go down to the action handler we created in the last post.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Add the following code right before the call to &lt;span class=&quot;s4&quot;&gt;[self renderGL]&lt;/span&gt;:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p11&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// set the shader uniform color and disable lighting&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GLKVector4&lt;/span&gt; oldColor = &lt;span class=&quot;s7&quot;&gt;_color&lt;/span&gt;;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;_color&lt;/span&gt; = &lt;span class=&quot;s8&quot;&gt;GLKVector4Make&lt;/span&gt;(&lt;span class=&quot;s3&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s3&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s3&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s3&quot;&gt;1.0f&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;_lit&lt;/span&gt; = &lt;span class=&quot;s2&quot;&gt;false&lt;/span&gt;;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Conceptually, we&#39;re doing the exact same thing we did we the red cube: we&#39;re changing the color and we&#39;re turning off lighting.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;The only difference here is we need to store the old color so we can change it back when we&#39;re done.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;If you run the program now in the simulator you should see the blue cube turn bright red when you click on the screen:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg95rXIIO77xTyd2Rmh2xN1G4br0oTNvsgydRIxwRHbWr4kcUeyY3jUopn8bjWyy6Tuex5Wg4xqQAhTbczhp_t-n2wOrWZlhvlQRAW8QG01JrFfWkn5ti0FLBn7ZXQEv_U1f5ItNiQrTLXi/s1600/Screen+Shot+2012-03-02+at+10.02.43+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; width=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg95rXIIO77xTyd2Rmh2xN1G4br0oTNvsgydRIxwRHbWr4kcUeyY3jUopn8bjWyy6Tuex5Wg4xqQAhTbczhp_t-n2wOrWZlhvlQRAW8QG01JrFfWkn5ti0FLBn7ZXQEv_U1f5ItNiQrTLXi/s320/Screen+Shot+2012-03-02+at+10.02.43+PM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Now let&#39;s go ahead and change the color and lighting state back to the way it was.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;You can add this code right after the &lt;span class=&quot;s4&quot;&gt;[self renderGL] &lt;/span&gt;call:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p11&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// change the shader color and lighting back to normal&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;_color&lt;/span&gt; = oldColor;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;_lit&lt;/span&gt; = &lt;span class=&quot;s2&quot;&gt;true&lt;/span&gt;;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Run the program in the simulator again.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;The blue cube should remain visually unchanged, but the console output should indicate a bright red color when you click on the blue cube:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;b&gt;2012-03-02 22:43:57.792 Picky[7308:10103] 255, 0, 0, 255&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step Four:&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Reaction!&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Just as before, I set the blue cube up to get smaller when you click on it.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;To see it happen in your program, just follow the steps from the last post.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;First, create a new variable right next to your &lt;span class=&quot;s4&quot;&gt;_scale&lt;/span&gt; variable from last time:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;float&lt;/span&gt; _shadeScale;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Next, initialize the variable to 1 in the &lt;span class=&quot;s4&quot;&gt;setupGL&lt;/span&gt; function:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;_shadeScale&lt;span class=&quot;s1&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;1.0f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Next, add another scaling transformation to the &lt;span class=&quot;s4&quot;&gt;update&lt;/span&gt; function.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;This one goes right after the GLKMatrix4Rotate function call in the ES2 model view matrix section:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;modelViewMatrix = &lt;span class=&quot;s8&quot;&gt;GLKMatrix4Scale&lt;/span&gt;(modelViewMatrix, &lt;span class=&quot;s7&quot;&gt;_shadeScale&lt;/span&gt;, &lt;span class=&quot;s7&quot;&gt;_shadeScale&lt;/span&gt;, &lt;span class=&quot;s7&quot;&gt;_shadeScale&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Finally, in your tap action function, add an &lt;span class=&quot;s4&quot;&gt;else if&lt;/span&gt; statement to your previous &lt;span class=&quot;s4&quot;&gt;if&lt;/span&gt; statement to check for the bright red color and modify the &lt;span class=&quot;s4&quot;&gt;_shadeScale&lt;/span&gt; variable:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;if&lt;/span&gt; (pixel[&lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;] == &lt;span class=&quot;s3&quot;&gt;255&lt;/span&gt; &amp;amp;&amp;amp; pixel[&lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;] == &lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; pixel[&lt;span class=&quot;s3&quot;&gt;2&lt;/span&gt;] == &lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; pixel[&lt;span class=&quot;s3&quot;&gt;3&lt;/span&gt;] == &lt;span class=&quot;s3&quot;&gt;255&lt;/span&gt;)&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;        &lt;/span&gt;&lt;/span&gt;_shadeScale&lt;span class=&quot;s1&quot;&gt; = &lt;/span&gt;_shadeScale&lt;span class=&quot;s1&quot;&gt; / &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;1.5f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Now run the program in the simulator.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Clicking on either cube causes that cube to shrink.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg78jKTKZflbT3YL2J7AY8pShXUdMH7cFOQMWHdIo8JcilJqY_5aztUdCyLbe5p0eRmVhnRkoSJTQ0_E8-VJ9r2rsuM6oLwqF5md8-dMBJe_TVBMMXjW1xSvNYXbUw3zbxpMRDcjiJvGPGC/s1600/Screen+Shot+2012-03-02+at+10.06.43+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; width=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg78jKTKZflbT3YL2J7AY8pShXUdMH7cFOQMWHdIo8JcilJqY_5aztUdCyLbe5p0eRmVhnRkoSJTQ0_E8-VJ9r2rsuM6oLwqF5md8-dMBJe_TVBMMXjW1xSvNYXbUw3zbxpMRDcjiJvGPGC/s320/Screen+Shot+2012-03-02+at+10.06.43+PM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step Five:&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Troubleshooting&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Using shader uniform variables is a multistep process, which means it&#39;s easy to get something wrong.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;In this section I purposely introduce various bugs to repo some common error states.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;In the vertex shader file, I replaced all instances of the &lt;span class=&quot;s4&quot;&gt;color &lt;/span&gt;variable with &lt;span class=&quot;s4&quot;&gt;_color&lt;/span&gt;.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;This compiled and ran with no shader compile errors in the log, but since the ViewController.m file still refers to it as &quot;color&quot; in this line in &lt;span class=&quot;s4&quot;&gt;loadShaders&lt;/span&gt;, we never actually succeed in passing the color to the shader, and so the cube appears black.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p9&quot;&gt;&lt;span class=&quot;s7&quot;&gt;uniforms&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;UNIFORM_COLOR&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;] = &lt;/span&gt;glGetUniformLocation&lt;span class=&quot;s1&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;_program&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s10&quot;&gt;&quot;color&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;When I stepped through this line of code in the debugger, I saw that the &lt;span class=&quot;s4&quot;&gt;glGetUniformLocation&lt;/span&gt; call returned -1, indicating an error.&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;When I commented out the declaration of the color variable in the Shader.vsh file, but left references to it, I got the following messages in the error log:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;//uniform vec4 color;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;b&gt;2012-03-07 20:18:43.563 Picky[568:10103] Shader compile log:&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;b&gt;ERROR: 0:28: Use of undeclared identifier &#39;color&#39;&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;b&gt;ERROR: 0:32: Use of undeclared identifier &#39;color&#39;&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;b&gt;2012-03-07 20:18:43.570 Picky[568:10103] Failed to compile vertex shader&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;With this compile error, the blue cube does not show up at all.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;The &lt;span class=&quot;s4&quot;&gt;loadShaders&lt;/span&gt; function returns when it detects a shader compile error, and does not even get to the set of &lt;span class=&quot;s4&quot;&gt;glGetUniformLocation&lt;/span&gt; calls.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Another way to get a black cube is to mess up the call to glUniform4fv in the renderGL function.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Here&#39;s how it&#39;s supposed to look:&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;s8&quot;&gt;glUniform4fv&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;(&lt;/span&gt;uniforms&lt;span class=&quot;s1&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;UNIFORM_COLOR&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;], &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;, &lt;/span&gt;_color&lt;span class=&quot;s1&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;The v at the end of the function name indicates that we are passing a vector.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;The f indicates that the vector contains float values.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;The 4 indicates that it is 4 dimensional.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Using 3 instead of 4 results in a black cube. &lt;span class=&quot;Apple-converted-space&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;The first parameter is the id we use to refer to the shader uniform.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;We got this id from OpenGL when we loaded the shaders.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;If we pass in an incorrect id, we get a black cube.&lt;span class=&quot;Apple-converted-space&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;The second parameter is the number of vectors we are sending.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;It is not the number of bytes or the dimensions in the vector, so &#39;1&#39; is the correct value here.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Any other value gets you a black cube. &lt;span class=&quot;Apple-converted-space&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Calling glGetError() after any one of these incorrect function calls returns error code 1282, which means invalid operation.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Conclusion&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;As I said in my previous post, color picking is fine for such a simple scene, but for more complex scenes, other algorithms such as ray-casting may be more effective.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;As always, please let me know if you find any mistakes in my code, or if you know of a better or easier way to solve this problem.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Also, use this code at your own risk.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.headnoodles.com/feeds/3124386412810908238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.headnoodles.com/2012/03/picky-part-ii.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/627201247416879277/posts/default/3124386412810908238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/627201247416879277/posts/default/3124386412810908238'/><link rel='alternate' type='text/html' href='http://www.headnoodles.com/2012/03/picky-part-ii.html' title='Picky, Part II'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04188436224275642399</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDyd8U0gTtLpxshazw6cLigPmm1EXIUif9cxRmptmCcRSlzohBo-kPxZx1A8xMHXF6a4fNgklL10ESH9BPHheMmxWqQ4tyjC1EnidmU2w_AFuoP0FlVC_BkU1K9TWcdEwjOtAd6-ElJPwL/s72-c/Screen+Shot+2012-03-02+at+5.15.29+PM.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-627201247416879277.post-2528423117969849373</id><published>2012-03-02T16:00:00.000-08:00</published><updated>2012-03-02T16:05:34.007-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Color Picking"/><category scheme="http://www.blogger.com/atom/ns#" term="Gestures"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS 5"/><category scheme="http://www.blogger.com/atom/ns#" term="OpenGL ES"/><category scheme="http://www.blogger.com/atom/ns#" term="Xcode 4"/><title type='text'>Picky, Part I</title><content type='html'>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
  &lt;meta http-equiv=&quot;Content-Style-Type&quot; content=&quot;text/css&quot;&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;meta name=&quot;Generator&quot; content=&quot;Cocoa HTML Writer&quot;&gt;
  &lt;meta name=&quot;CocoaVersion&quot; content=&quot;1138.32&quot;&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
    p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; min-height: 17.0px}
    p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
    p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Times; min-height: 14.0px}
    p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}
    p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008b00}
    p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}
    p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #2f00dd}
    p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7e4623}
    p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #430084}
    p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #265a5f}
    p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Times}
    p.p13 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #7822ac}
    p.p14 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008b00; min-height: 13.0px}
    p.p15 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #418289}
    span.s1 {color: #c800a3}
    span.s2 {color: #000000}
    span.s3 {color: #7822ac}
    span.s4 {color: #2f00dd}
    span.s5 {color: #430084}
    span.s6 {color: #7e4623}
    span.s7 {color: #e00000}
    span.s8 {color: #265a5f}
    span.s9 {color: #418289}
    span.Apple-converted-space {white-space:pre}
  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p class=&quot;p1&quot;&gt;In this post, I&#39;m trying out color picking.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;In the interest of keeping these posts to a more manageable size, I am planning to just color pick the red GLKit cube.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;My next post will build on the work in this one and handle the blue 2.0 cube.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;The basic idea behind color picking is once the user has tapped somewhere, render the objects in your scene into the back buffer using a unique color for each object, then ask OpenGL to give you the color of the pixel where the user tapped.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;This color tells you what object was tapped.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;As long as you don&#39;t present the scene to the user, the user never sees the weird colors.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;This is fast and efficient, since you only render the scene an extra time whenever the user taps, but generally is good only for per-object or per-triangle picking.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Getting the exact point on a triangle that the user clicked on will probably require a different technique.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step One:&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Create a new OpenGL Game project&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;For instructions how to do this, refer to my &lt;a href=&quot;http://www.headnoodles.com/2012/02/using-textures-in-xcode-4-opengl-es-1.html&quot;&gt;texture post&lt;/a&gt;.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Once you get it set up, you can run it and see two cubes.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;The red cube is rendered using GLKit.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;The blue cube is rendered using OpenGL ES 2.0 shaders.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;In this blog I color pick the red cube.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl-ktkaAsU0bumbVn8Vy3xH59RGDTxG4NY7ZAFsRXfmkkNPz7oFvqs_j4JGEoV2xdA_cwr0ZXY_mHRNw2DbYUGRaFLuwY4i6NfV57uHF2LVTDpyUZEp0-o4Cn9AwpjVeMlNoCSsrJNiE8r/s1600/Screen+Shot+2012-02-24+at+7.33.48+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; width=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl-ktkaAsU0bumbVn8Vy3xH59RGDTxG4NY7ZAFsRXfmkkNPz7oFvqs_j4JGEoV2xdA_cwr0ZXY_mHRNw2DbYUGRaFLuwY4i6NfV57uHF2LVTDpyUZEp0-o4Cn9AwpjVeMlNoCSsrJNiE8r/s320/Screen+Shot+2012-02-24+at+7.33.48+PM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step Two: Set up a tap gesture recognizer and action function (event handler)&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Refer to my &lt;a href=&quot;http://www.headnoodles.com/2012/02/adding-gesture-control-to-xcode-opengl.html&quot;&gt;gesture post&lt;/a&gt; for step by step instructions.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step Three:&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Read the pixel the user tapped on&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Add code to the event handler so that it looks like the following:&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;- (&lt;span class=&quot;s1&quot;&gt;IBAction&lt;/span&gt;)tapThat:(&lt;span class=&quot;s1&quot;&gt;id&lt;/span&gt;)sender {&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;GLubyte&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; pixel[&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;]; &lt;span class=&quot;Apple-converted-space&quot;&gt;      &lt;/span&gt;&lt;/span&gt;// output array for the red, green, blue, and alpha pixel components&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// get the point the user tapped on&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;CGPoint&lt;/span&gt; tapPoint = [sender &lt;span class=&quot;s5&quot;&gt;locationInView&lt;/span&gt;:&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;view&lt;/span&gt;];&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// read the pixel at the tapped location.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;We use the screen height to convert&lt;span class=&quot;Apple-converted-space&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// between iOS screen coordinates, which is (0,0) at the upper left, and OpenGL&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// screen coordinates, which is (0,0) at the LOWER left.&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; height = [&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;view&lt;/span&gt; &lt;span class=&quot;s5&quot;&gt;bounds&lt;/span&gt;].&lt;span class=&quot;s3&quot;&gt;size&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;height&lt;/span&gt;;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;glReadPixels&lt;/span&gt;(tapPoint.&lt;span class=&quot;s3&quot;&gt;x&lt;/span&gt;,height - tapPoint.&lt;span class=&quot;s3&quot;&gt;y&lt;/span&gt;,&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s6&quot;&gt;GL_RGBA&lt;/span&gt;,&lt;span class=&quot;s6&quot;&gt;GL_UNSIGNED_BYTE&lt;/span&gt;,&amp;amp;pixel);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// log the results.&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;NSLog&lt;/span&gt;(&lt;span class=&quot;s7&quot;&gt;@&quot;%u, %u, %u, %u&quot;&lt;/span&gt;,pixel[&lt;span class=&quot;s4&quot;&gt;0&lt;/span&gt;],(&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt;)pixel[&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;],pixel[&lt;span class=&quot;s4&quot;&gt;2&lt;/span&gt;],pixel[&lt;span class=&quot;s4&quot;&gt;3&lt;/span&gt;]);&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;}&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;This just outputs the color of the pixel that the user tapped on to the log.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Go ahead and run the program in the simulator and start clicking around on the simulated screen.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;If you hooked everything up right you should see something like this:&lt;span class=&quot;Apple-converted-space&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:51.505 Picky[5480:10103] 84, 84, 210, 210&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:51.912 Picky[5480:10103] 81, 81, 203, 203&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:52.104 Picky[5480:10103] 89, 89, 224, 224&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:52.279 Picky[5480:10103] 94, 94, 236, 236&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:52.831 Picky[5480:10103] 202, 87, 87, 255&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:53.004 Picky[5480:10103] 194, 83, 83, 255&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:53.507 Picky[5480:10103] 147, 65, 65, 255&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:54.001 Picky[5480:10103] 185, 80, 80, 255&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:54.184 Picky[5480:10103] 192, 83, 83, 255&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:54.734 Picky[5480:10103] 77, 37, 37, 255&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:54.932 Picky[5480:10103] 109, 49, 49, 255&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:55.140 Picky[5480:10103] 138, 61, 61, 255&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 16:16:56.104 Picky[5480:10103] 100, 100, 250, 250&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;The four comma-separated numbers at the end of each line are the red, green, blue, and alpha values of the pixel the user clicked on.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Note that the data type that openGL returns is unsigned bytes, which go from 0 to 255.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;You generally send colors to OpenGL as floating point numbers between 0 and 1, so be aware that you may have to convert by dividing or multiplying by 255.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step Four: Extract the render code&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Of course, this function isn&#39;t very useful in and of itself.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;We need to add the code to render our object in a different color.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;To do this, We&#39;re going to pull out the render code into a separate function.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;We could just copy and paste the code from the view function to the tap action function, but that would be fragile, dangerous code.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;If the render functions aren&#39;t exactly the same except for the colors of the objects, we run the risk of rendering the objects in different locations when we are picking them.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;The user would click on a cube, but the action function would render it somewhere else, and our program wouldn&#39;t register the tap.&lt;span class=&quot;Apple-converted-space&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;So create a new function declaration in the interface section of your ViewController.m file:&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;- (&lt;span class=&quot;s1&quot;&gt;void&lt;/span&gt;)renderGL;&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Then create the function in the implementation section, cut and paste the render code from the view function, and call the new render function inside the view function.&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;When you are done, the view function and render function should look like this:&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;- (&lt;span class=&quot;s1&quot;&gt;void&lt;/span&gt;)glkView:(&lt;span class=&quot;s3&quot;&gt;GLKView&lt;/span&gt; *)view drawInRect:(&lt;span class=&quot;s3&quot;&gt;CGRect&lt;/span&gt;)rect&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;{&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;[&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt; &lt;span class=&quot;s8&quot;&gt;renderGL&lt;/span&gt;];&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;}&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;- (&lt;span class=&quot;s1&quot;&gt;void&lt;/span&gt;)renderGL&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;{&lt;/p&gt;
&lt;p class=&quot;p8&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;glClearColor&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;0.65f&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;0.65f&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;0.65f&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;1.0f&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p9&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;glClear&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;GL_COLOR_BUFFER_BIT&lt;span class=&quot;s2&quot;&gt; | &lt;/span&gt;GL_DEPTH_BUFFER_BIT&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;glBindVertexArrayOES&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;_vertexArray&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// Render the object with GLKit&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;prepareToDraw&lt;span class=&quot;s2&quot;&gt;];&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;glDrawArrays&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GL_TRIANGLES&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;36&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// Render the object again with ES2&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;glUseProgram&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;_program&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p11&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;glUniformMatrix4fv&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;uniforms&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[&lt;/span&gt;UNIFORM_MODELVIEWPROJECTION_MATRIX&lt;span class=&quot;s2&quot;&gt;], &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;_modelViewProjectionMatrix&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p11&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;glUniformMatrix3fv&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;uniforms&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[&lt;/span&gt;UNIFORM_NORMAL_MATRIX&lt;span class=&quot;s2&quot;&gt;], &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;_normalMatrix&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;glDrawArrays&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GL_TRIANGLES&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;36&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;}&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;As a sanity check, go ahead and run your program in the simulator to make sure it still renders correctly.&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step Five:&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Render with a different color on tap&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Now we need to call our render function from within the tap action function, but using a different color to draw our object.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Add code to your tap action function so that it looks like this:&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;- (&lt;span class=&quot;s1&quot;&gt;IBAction&lt;/span&gt;)tapThat:(&lt;span class=&quot;s1&quot;&gt;id&lt;/span&gt;)sender {&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;GLubyte&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; pixel[&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;]; &lt;span class=&quot;Apple-converted-space&quot;&gt;      &lt;/span&gt;&lt;/span&gt;// output array for the red, green, blue, and alpha pixel components&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// turn off lighting and turn on constant color for picking &lt;span class=&quot;Apple-converted-space&quot;&gt;   &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p13&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;useConstantColor&lt;span class=&quot;s2&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GL_TRUE&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p13&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;light0&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;enabled&lt;span class=&quot;s2&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GL_FALSE&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;constantColor&lt;/span&gt; = &lt;span class=&quot;s5&quot;&gt;GLKVector4Make&lt;/span&gt;(&lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// render the scene&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;[&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt; &lt;span class=&quot;s8&quot;&gt;renderGL&lt;/span&gt;];&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// set lighting and the constant color usage back to the way they were&lt;/p&gt;
&lt;p class=&quot;p13&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;useConstantColor&lt;span class=&quot;s2&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GL_FALSE&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p13&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;light0&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;enabled&lt;span class=&quot;s2&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GL_TRUE&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// get the point the user tapped on&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;CGPoint&lt;/span&gt; tapPoint = [sender &lt;span class=&quot;s5&quot;&gt;locationInView&lt;/span&gt;:&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;view&lt;/span&gt;];&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// read the pixel at the tapped location.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;We use the screen height to convert&lt;span class=&quot;Apple-converted-space&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// between iOS screen coordinates, which is (0,0) at the upper left, and OpenGL&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// screen coordinates, which is (0,0) at the LOWER left.&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; height = [&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;view&lt;/span&gt; &lt;span class=&quot;s5&quot;&gt;bounds&lt;/span&gt;].&lt;span class=&quot;s3&quot;&gt;size&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;height&lt;/span&gt;;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;glReadPixels&lt;/span&gt;(tapPoint.&lt;span class=&quot;s3&quot;&gt;x&lt;/span&gt;,height - tapPoint.&lt;span class=&quot;s3&quot;&gt;y&lt;/span&gt;,&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s6&quot;&gt;GL_RGBA&lt;/span&gt;,&lt;span class=&quot;s6&quot;&gt;GL_UNSIGNED_BYTE&lt;/span&gt;,&amp;amp;pixel);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// log the results.&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;NSLog&lt;/span&gt;(&lt;span class=&quot;s7&quot;&gt;@&quot;%u, %u, %u, %u&quot;&lt;/span&gt;,pixel[&lt;span class=&quot;s4&quot;&gt;0&lt;/span&gt;],(&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt;)pixel[&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;],pixel[&lt;span class=&quot;s4&quot;&gt;2&lt;/span&gt;],pixel[&lt;span class=&quot;s4&quot;&gt;3&lt;/span&gt;]);&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;}&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;In the code we added, we turn off lighting and turn on a constant, bright blue color.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Then we render as normal.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Afterwards, we turn the light back on and the constant color back off. &lt;span class=&quot;Apple-converted-space&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;If you run this and click on the red cube, you will see numbers representing bright blue in the console:&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;b&gt;2012-03-02 17:01:56.106 Picky[5746:10103] 0, 0, 255, 255&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;As an interesting exercise, you can comment out the two lines setting the OpenGL state back to the way it was and run the simulator.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;When you click on the screen, you&#39;ll see the object turn bright blue.&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;//self.effect.useConstantColor = GL_FALSE;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;//self.effect.light0.enabled = GL_TRUE;&lt;/p&gt;
&lt;p class=&quot;p14&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxfN-RNFMdR_RhFUQ5oTJ8J2-SMRU16CpoLbHaFOUFReny0tJP-72lBT43I-SVIZIw4exlrpnTRxnNkWuuMHjTZHjn5bvnZ0Sr7lyLQ6H6EGFga60j7SPtVnTbJrwAC5YDwmYEnGB81Sps/s1600/Screen+Shot+2012-03-02+at+5.04.01+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; width=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxfN-RNFMdR_RhFUQ5oTJ8J2-SMRU16CpoLbHaFOUFReny0tJP-72lBT43I-SVIZIw4exlrpnTRxnNkWuuMHjTZHjn5bvnZ0Sr7lyLQ6H6EGFga60j7SPtVnTbJrwAC5YDwmYEnGB81Sps/s320/Screen+Shot+2012-03-02+at+5.04.01+PM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p class=&quot;p14&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p14&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p3&quot;&gt;Step Six:&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Add a visual reaction&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Now we just need to react to the user clicking on the cube.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;For this example, I arbitrarily decided to show the click by making the cube smaller.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Presumably you will have your own application logic.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;I started by adding a scale value to the view controller .m file&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;float&lt;/span&gt; _scale;&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Next, I initialized it to 1 in the setupGL function.&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p15&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;_scale&lt;span class=&quot;s2&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Next, I added a new scale transformation to the GLKit cube in the update function.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Now it looks like this:&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;- (&lt;span class=&quot;s1&quot;&gt;void&lt;/span&gt;)update&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;{&lt;/p&gt;
&lt;p class=&quot;p13&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; aspect = &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;fabsf&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;view&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;bounds&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;size&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;width&lt;span class=&quot;s2&quot;&gt; / &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;view&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;bounds&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;size&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;height&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;GLKMatrix4&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; projectionMatrix = &lt;/span&gt;GLKMatrix4MakePerspective&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;GLKMathDegreesToRadians&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;65.0f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;), aspect, &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;0.1f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;100.0f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;transform&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;projectionMatrix&lt;/span&gt; = projectionMatrix;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;GLKMatrix4&lt;/span&gt; baseModelViewMatrix = &lt;span class=&quot;s5&quot;&gt;GLKMatrix4MakeTranslation&lt;/span&gt;(&lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s4&quot;&gt;4.0f&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;baseModelViewMatrix = &lt;span class=&quot;s5&quot;&gt;GLKMatrix4Rotate&lt;/span&gt;(baseModelViewMatrix, &lt;span class=&quot;s9&quot;&gt;_rotation&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// Compute the model view matrix for the object rendered with GLKit&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;GLKMatrix4&lt;/span&gt; modelViewMatrix = &lt;span class=&quot;s5&quot;&gt;GLKMatrix4MakeTranslation&lt;/span&gt;(&lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s4&quot;&gt;1.5f&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;modelViewMatrix = &lt;span class=&quot;s5&quot;&gt;GLKMatrix4Rotate&lt;/span&gt;(modelViewMatrix, &lt;span class=&quot;s9&quot;&gt;_rotation&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;modelViewMatrix = &lt;span class=&quot;s5&quot;&gt;GLKMatrix4Scale&lt;/span&gt;(modelViewMatrix, &lt;span class=&quot;s9&quot;&gt;_scale&lt;/span&gt;, &lt;span class=&quot;s9&quot;&gt;_scale&lt;/span&gt;, &lt;span class=&quot;s9&quot;&gt;_scale&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;modelViewMatrix = &lt;span class=&quot;s5&quot;&gt;GLKMatrix4Multiply&lt;/span&gt;(baseModelViewMatrix, modelViewMatrix);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;transform&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;modelviewMatrix&lt;/span&gt; = modelViewMatrix;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// Compute the model view matrix for the object rendered with ES2&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;modelViewMatrix = &lt;span class=&quot;s5&quot;&gt;GLKMatrix4MakeTranslation&lt;/span&gt;(&lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.5f&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;modelViewMatrix = &lt;span class=&quot;s5&quot;&gt;GLKMatrix4Rotate&lt;/span&gt;(modelViewMatrix, &lt;span class=&quot;s9&quot;&gt;_rotation&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;modelViewMatrix = &lt;span class=&quot;s5&quot;&gt;GLKMatrix4Multiply&lt;/span&gt;(baseModelViewMatrix, modelViewMatrix);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p10&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;_normalMatrix&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; = &lt;/span&gt;GLKMatrix3InvertAndTranspose&lt;span class=&quot;s2&quot;&gt;(&lt;/span&gt;GLKMatrix4GetMatrix3&lt;span class=&quot;s2&quot;&gt;(modelViewMatrix), &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;_modelViewProjectionMatrix&lt;/span&gt; = &lt;span class=&quot;s5&quot;&gt;GLKMatrix4Multiply&lt;/span&gt;(projectionMatrix, modelViewMatrix);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p13&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;_rotation&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; += &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;timeSinceLastUpdate&lt;span class=&quot;s2&quot;&gt; * &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;0.5f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;}&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Finally, I added the logic that checks to see if we clicked on our cube and change the scale.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Now the tap action function looks like this:&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;- (&lt;span class=&quot;s1&quot;&gt;IBAction&lt;/span&gt;)tapThat:(&lt;span class=&quot;s1&quot;&gt;id&lt;/span&gt;)sender {&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;GLubyte&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; pixel[&lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;]; &lt;span class=&quot;Apple-converted-space&quot;&gt;      &lt;/span&gt;&lt;/span&gt;// output array for the red, green, blue, and alpha pixel components&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// turn off lighting and turn on constant color for picking &lt;span class=&quot;Apple-converted-space&quot;&gt;   &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p13&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;useConstantColor&lt;span class=&quot;s2&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GL_TRUE&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p13&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;light0&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;enabled&lt;span class=&quot;s2&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GL_FALSE&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;constantColor&lt;/span&gt; = &lt;span class=&quot;s5&quot;&gt;GLKVector4Make&lt;/span&gt;(&lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s4&quot;&gt;1.0f&lt;/span&gt;);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// render the scene&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;[&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt; &lt;span class=&quot;s8&quot;&gt;renderGL&lt;/span&gt;];&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// set lighting and the constant color usage back to the way they were&lt;/p&gt;
&lt;p class=&quot;p13&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;useConstantColor&lt;span class=&quot;s2&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GL_FALSE&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p13&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;light0&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;enabled&lt;span class=&quot;s2&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;GL_TRUE&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// get the point the user tapped on&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;CGPoint&lt;/span&gt; tapPoint = [sender &lt;span class=&quot;s5&quot;&gt;locationInView&lt;/span&gt;:&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;view&lt;/span&gt;];&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// read the pixel at the tapped location.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;We use the screen height to convert&lt;span class=&quot;Apple-converted-space&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// between iOS screen coordinates, which is (0,0) at the upper left, and OpenGL&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// screen coordinates, which is (0,0) at the LOWER left.&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; height = [&lt;span class=&quot;s1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;view&lt;/span&gt; &lt;span class=&quot;s5&quot;&gt;bounds&lt;/span&gt;].&lt;span class=&quot;s3&quot;&gt;size&lt;/span&gt;.&lt;span class=&quot;s3&quot;&gt;height&lt;/span&gt;;&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;glReadPixels&lt;/span&gt;(tapPoint.&lt;span class=&quot;s3&quot;&gt;x&lt;/span&gt;,height - tapPoint.&lt;span class=&quot;s3&quot;&gt;y&lt;/span&gt;,&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s6&quot;&gt;GL_RGBA&lt;/span&gt;,&lt;span class=&quot;s6&quot;&gt;GL_UNSIGNED_BYTE&lt;/span&gt;,&amp;amp;pixel);&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// did we click on our cube?&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;If so, make it smaller&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;if&lt;/span&gt; (pixel[&lt;span class=&quot;s4&quot;&gt;0&lt;/span&gt;] == &lt;span class=&quot;s4&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; pixel[&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;] == &lt;span class=&quot;s4&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; pixel[&lt;span class=&quot;s4&quot;&gt;2&lt;/span&gt;] == &lt;span class=&quot;s4&quot;&gt;255&lt;/span&gt; &amp;amp;&amp;amp; pixel[&lt;span class=&quot;s4&quot;&gt;3&lt;/span&gt;] == &lt;span class=&quot;s4&quot;&gt;255&lt;/span&gt;)&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;_scale&lt;/span&gt; = &lt;span class=&quot;s9&quot;&gt;_scale&lt;/span&gt; / &lt;span class=&quot;s4&quot;&gt;1.5f&lt;/span&gt;;&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;p6&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;/span&gt;// log the results.&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;NSLog&lt;/span&gt;(&lt;span class=&quot;s7&quot;&gt;@&quot;%u, %u, %u, %u&quot;&lt;/span&gt;,pixel[&lt;span class=&quot;s4&quot;&gt;0&lt;/span&gt;],(&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt;)pixel[&lt;span class=&quot;s4&quot;&gt;1&lt;/span&gt;],pixel[&lt;span class=&quot;s4&quot;&gt;2&lt;/span&gt;],pixel[&lt;span class=&quot;s4&quot;&gt;3&lt;/span&gt;]);&lt;/p&gt;
&lt;p class=&quot;p5&quot;&gt;}&lt;/p&gt;
&lt;p class=&quot;p4&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;Go ahead and run the program in the simulator.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;If you click on the background or the blue cube, nothing happens.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Clicking on the red cube, however, makes it shrink!&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmTTF-_bguiFMtx3esVrMv_vBiZ4ZR5wh91mXYhTdrnqPcRJxI7fHUXSN3on7lOLYveJpSX_T56KAxizSgG-S5kBSmFzc9sV7LBOnRCLd2Vamygo3yiOXBTGUqwc2KnYh7FjHrRn2WfWCZ/s1600/Screen+Shot+2012-03-02+at+5.15.29+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; width=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmTTF-_bguiFMtx3esVrMv_vBiZ4ZR5wh91mXYhTdrnqPcRJxI7fHUXSN3on7lOLYveJpSX_T56KAxizSgG-S5kBSmFzc9sV7LBOnRCLd2Vamygo3yiOXBTGUqwc2KnYh7FjHrRn2WfWCZ/s320/Screen+Shot+2012-03-02+at+5.15.29+PM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;I chose this particular method of setting the color of our object because it was the simplest way I could think of that would demonstrate the technique.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;More complex scenes would require a more complex method.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;To implement per-triangle color picking, you could add a per-vertex color attribute to the vertex array, then use that color in your test.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;As I said above, my next post will add color picking to the blue 2.0 cube.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;And as always, this is code I wrote while trying to figure this stuff out.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;It is probably not suitable for use in any production environment, and I strongly advise against using it.&lt;/p&gt;
&lt;p class=&quot;p2&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot;&gt;PS -- I may be the only blogger on the internet who did not know how to automatically apply formatting to my source code in my blog, but just in case anyone else out there is as derp as I am, I found that if you copy your source from Xcode to TextEdit, then save as html, TextEdit will apply the color and font styles for you.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Then you can just paste the html into your blog editor.&lt;span class=&quot;Apple-converted-space&quot;&gt;  &lt;/span&gt;Whatever you do, don&#39;t click back to compose mode once you have pasted your HTML.  Oh, I also had to change the &#39;Apple-tab-span&#39; style to &#39;Apple-converted-space&#39; so it actually matched the style in the rest of the document.&lt;/p&gt;
&lt;p class=&quot;p7&quot;&gt;&lt;br&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.headnoodles.com/feeds/2528423117969849373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.headnoodles.com/2012/03/picky-part-i.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/627201247416879277/posts/default/2528423117969849373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/627201247416879277/posts/default/2528423117969849373'/><link rel='alternate' type='text/html' href='http://www.headnoodles.com/2012/03/picky-part-i.html' title='Picky, Part I'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04188436224275642399</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl-ktkaAsU0bumbVn8Vy3xH59RGDTxG4NY7ZAFsRXfmkkNPz7oFvqs_j4JGEoV2xdA_cwr0ZXY_mHRNw2DbYUGRaFLuwY4i6NfV57uHF2LVTDpyUZEp0-o4Cn9AwpjVeMlNoCSsrJNiE8r/s72-c/Screen+Shot+2012-02-24+at+7.33.48+PM.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-627201247416879277.post-6637955330788120746</id><published>2012-02-20T23:55:00.000-08:00</published><updated>2012-03-02T16:03:04.583-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="iOS 5"/><category scheme="http://www.blogger.com/atom/ns#" term="OpenGL ES"/><category scheme="http://www.blogger.com/atom/ns#" term="Textures"/><category scheme="http://www.blogger.com/atom/ns#" term="Xcode 4"/><title type='text'>The Texturing</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
In this post I&#39;m changing the default Xcode 4 OpenGL Game project to load a texture file and use it when drawing the two cubes.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
I started with a brand new OpenGL Game project.&amp;nbsp; See my previous post if you don&#39;t know how to create one.&amp;nbsp; If you run the program after creating the project you will see two cubes orbiting about the Y-axis.&amp;nbsp; The blue one is drawn using the vertex and fragment shaders, and the red one is drawn using Apple&#39;s fixed functionality pipeline.&amp;nbsp; Our goal is to overlay a texture on both cubes.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFE6yVfznJpJbO516qOd1YJrYSg7Ir_mYC8Pc_xIBtREjcRO0SINERTdSy3zrQK6rS66esypke8n9N7gdQ6F0sXpcJPaMUsqKeYMJtv4X3_y7jWNInxb603e9WY4WcyotHFXNEdcSSwVd2/s1600/Screen+Shot+2012-02-20+at+11.04.10+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFE6yVfznJpJbO516qOd1YJrYSg7Ir_mYC8Pc_xIBtREjcRO0SINERTdSy3zrQK6rS66esypke8n9N7gdQ6F0sXpcJPaMUsqKeYMJtv4X3_y7jWNInxb603e9WY4WcyotHFXNEdcSSwVd2/s640/Screen+Shot+2012-02-20+at+11.04.10+PM.png&quot; width=&quot;508&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
The first thing we need to do is find / create our texture and load it into our project.&amp;nbsp; For my texture, I got a screenshot of the Google blogger loading icon and used Mac Preview to crop out the rounded edges and resize it to 64 x 64 (I tried an 84 by 84 texture and it didn&#39;t work.&amp;nbsp; Apparently, in iOS textures are still required to have lengths and widths that are powers of two).&amp;nbsp; I saved it as bloogle.png on my desktop.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
To load the texture into your project just drag the file from wherever it is on your computer into the Supporting Files folder in the Project navigator in Xcode.&amp;nbsp; Make sure &quot;Copy items into destination group&#39;s folder (if needed) is checked, then click the &quot;Finish&quot; button.&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgazNuc-tqsZW9bOwawfmlouEM6EDxpoqjSq9B0SRI3PTsN6JyPyYZBe-q35vsKQhr9EgV5GmIvgyhdFHVM60J_SSOnGuwD9tzOmFGhHquNEafGVHk38sEWTKSrlGBWqJyIYkencVe5SCRw/s1600/Screen+Shot+2012-02-20+at+11.01.21+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;434&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgazNuc-tqsZW9bOwawfmlouEM6EDxpoqjSq9B0SRI3PTsN6JyPyYZBe-q35vsKQhr9EgV5GmIvgyhdFHVM60J_SSOnGuwD9tzOmFGhHquNEafGVHk38sEWTKSrlGBWqJyIYkencVe5SCRw/s640/Screen+Shot+2012-02-20+at+11.01.21+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8cNQ9rH9GN7Miy0wXutOnKL4lXpA-q60PneZOza-yLNXOsCMugx7lT2sDvlRQ6F_baDEfIMuuRgaKtLYz1L9YbAkOoiLbz5vv-3KV-rYZxsHx8H06t6t_faPQo25PsLpZVBiAW0Ej6auD/s1600/Screen+Shot+2012-02-20+at+11.02.24+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8cNQ9rH9GN7Miy0wXutOnKL4lXpA-q60PneZOza-yLNXOsCMugx7lT2sDvlRQ6F_baDEfIMuuRgaKtLYz1L9YbAkOoiLbz5vv-3KV-rYZxsHx8H06t6t_faPQo25PsLpZVBiAW0Ej6auD/s1600/Screen+Shot+2012-02-20+at+11.02.24+PM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Now the file is in the project, but we still need our program to load the image data into memory so OpenGL can use it.&amp;nbsp; To do this we will create a couple of new functions and a member variable in the view controller .m file.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
In the interface section of the view controller .m file, add the following line:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;GLKTextureInfo&lt;/span&gt; * _texture;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
This object will end up holding all the information OpenGL needs about our texture.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
In the function declarations section add the following lines:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;- (&lt;span class=&quot;s2&quot;&gt;void&lt;/span&gt;)loadTextures;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;- (&lt;span class=&quot;s2&quot;&gt;void&lt;/span&gt;)logError:(&lt;span class=&quot;s1&quot;&gt;NSError&lt;/span&gt; *) error;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
This declares our loadTextures function, which we will use to load our texture data into memory, and a logger function that will help use figure out what we are doing wrong.&amp;nbsp; I added error logging after I googled my own errors and found that a lot of other people were posting on Stack Overflow with inscrutable texture loading failures of their own.&amp;nbsp; Hopefully this will help you avoid that.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
After you add the two function declarations a warning may pop up complaining about &quot;Incomplete implementation.&quot;&amp;nbsp; We are going to address that next by implementing the two functions.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiink-h1PB9lcbhpTcuG1iP1C-Xmz8lykORfOwt4_2YcFBww31UKPIYXAVLXIwDDRvQeAZyzK-4yV8bk-0gddaIGcfm3ZtbJJyw0mghTmbA7jksa7kifxpOgikEDrwLrZBgo6J80iRLKkCV/s1600/Screen+Shot+2012-02-20+at+11.18.39+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;546&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiink-h1PB9lcbhpTcuG1iP1C-Xmz8lykORfOwt4_2YcFBww31UKPIYXAVLXIwDDRvQeAZyzK-4yV8bk-0gddaIGcfm3ZtbJJyw0mghTmbA7jksa7kifxpOgikEDrwLrZBgo6J80iRLKkCV/s640/Screen+Shot+2012-02-20+at+11.18.39+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
At the end of the view controller .m file, right above the @end statement, add the following function implementation skeletons:&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm9az0kt6EMkAFGIMo4fybHZmhQVJowJ-kyBeoxefGZeY9WekPODsBymhiFAzEF85zRqQO6kdYyKjeNfFxTUwqytVX1ok0NFJZNTPe0kZi6O6F0oYm9O-I6MXLiRPTy5xyzw6kKmdZl7K7/s1600/Screen+Shot+2012-02-20+at+11.21.58+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm9az0kt6EMkAFGIMo4fybHZmhQVJowJ-kyBeoxefGZeY9WekPODsBymhiFAzEF85zRqQO6kdYyKjeNfFxTUwqytVX1ok0NFJZNTPe0kZi6O6F0oYm9O-I6MXLiRPTy5xyzw6kKmdZl7K7/s320/Screen+Shot+2012-02-20+at+11.21.58+PM.png&quot; width=&quot;226&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p5&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;#pragma mark -&amp;nbsp; Texture Loading&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;- (&lt;span class=&quot;s2&quot;&gt;void&lt;/span&gt;)loadTextures&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;- (&lt;span class=&quot;s2&quot;&gt;void&lt;/span&gt;)logError:(&lt;span class=&quot;s1&quot;&gt;NSError&lt;/span&gt; *) error&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
The pragma mark statement makes it easy to find your functions in the bread crumb navigator at the top of the editor.&amp;nbsp; Notice how your functions have their own little section in the symbol drop down.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Now add the following statements to the loadTextures function you just created:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p6&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;NSError&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; *error = &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;; &amp;nbsp; &lt;/span&gt;// stores the error message if we mess up&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;NSDictionary&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; *options = [&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;NSDictionary&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;dictionaryWithObject&lt;span class=&quot;s3&quot;&gt;:[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;NSNumber&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;numberWithBool&lt;span class=&quot;s3&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;YES&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;]&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s4&quot;&gt;forKey&lt;/span&gt;:&lt;span class=&quot;s1&quot;&gt;GLKTextureLoaderGenerateMipmaps&lt;/span&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;NSString&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; *bundlepath = [[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;NSBundle&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;mainBundle&lt;span class=&quot;s3&quot;&gt;] &lt;/span&gt;pathForResource&lt;span class=&quot;s3&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;@&quot;bloogle&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;ofType&lt;span class=&quot;s3&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;@&quot;png&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s6&quot;&gt;_texture&lt;/span&gt; = [&lt;span class=&quot;s1&quot;&gt;GLKTextureLoader&lt;/span&gt; &lt;span class=&quot;s4&quot;&gt;textureWithContentsOfFile&lt;/span&gt;:bundlepath &lt;span class=&quot;s4&quot;&gt;options&lt;/span&gt;:options &lt;span class=&quot;s4&quot;&gt;error&lt;/span&gt;:&amp;amp;error];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; [&lt;span class=&quot;s2&quot;&gt;self&lt;/span&gt; &lt;span class=&quot;s7&quot;&gt;logError&lt;/span&gt;:error];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
First we declare a NSError object to hold our error message.&amp;nbsp; This isn&#39;t strictly necessary.&amp;nbsp; If you want, you can pass nil to the textureWithContentsOfFile function.&amp;nbsp; However, the error object is about the only way to get a meaningful error message out Xcode, and you can spend a lot of time banging your head against the wall without it.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Next we declare our options dictionary.&amp;nbsp; This is also not strictly needed for our purposes.&amp;nbsp; You can pass a nil value in for this as well.&amp;nbsp; But I wanted to show you how to go about creating an options dictionary in case you didn&#39;t know how.&amp;nbsp; This options dictionary tells the texture loader to automatically create mipmaps for the texture.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Next, we get the path of our image resource.&amp;nbsp; You can&#39;t just use &quot;bloogle.png&quot;.&amp;nbsp; Also note the lack of a period in the parameters we pass to this function.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Finally we generate the texture.&amp;nbsp; This one function call is equivalent to quite a few OpenGL calls.&amp;nbsp; It&#39;s responsible for loading the image data, passing the image data into OpenGL, getting a texture id back, and setting a number of OpenGL parameters for the texture.&amp;nbsp; Refer to any good OpenGL reference manual to get an idea of the things you don&#39;t have to do here.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwaO7BDGEMx2Qz64eQrQcA3p5VwQXYxTYDKrlZNWI9VnuMN5OqsjajvICNwApMEvBQxh605vsNhBIiic5_LCQAVgT1_m0dspR5RyppXKprCvF64cj-E9ZAcwAoA5UKzsjIbEwPy48knhfb/s1600/Screen+Shot+2012-02-20+at+11.45.14+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;490&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwaO7BDGEMx2Qz64eQrQcA3p5VwQXYxTYDKrlZNWI9VnuMN5OqsjajvICNwApMEvBQxh605vsNhBIiic5_LCQAVgT1_m0dspR5RyppXKprCvF64cj-E9ZAcwAoA5UKzsjIbEwPy48knhfb/s640/Screen+Shot+2012-02-20+at+11.45.14+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
After we (attempt to) generate the texture we pass the error to our logging function.&amp;nbsp; If something went wrong, the logging function will output something meaningful to the console.&amp;nbsp; To make this happen add the following statements to the logError function:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s2&quot;&gt;if&lt;/span&gt; (error)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;NSString&lt;/span&gt; * domain = [error &lt;span class=&quot;s4&quot;&gt;domain&lt;/span&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p8&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;NSLog&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;@&quot;Error loading texture: %@.&amp;nbsp; Domain: %@&quot;&lt;span class=&quot;s3&quot;&gt;, [error &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;localizedDescription&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;],domain);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;NSDictionary&lt;/span&gt; * userInfo = [error &lt;span class=&quot;s4&quot;&gt;userInfo&lt;/span&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p9&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; (domain == &lt;/span&gt;GLKTextureLoaderErrorDomain&lt;span class=&quot;s3&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s2&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;s2&quot;&gt;nil&lt;/span&gt; != [userInfo &lt;span class=&quot;s4&quot;&gt;objectForKey&lt;/span&gt;:&lt;span class=&quot;s1&quot;&gt;GLKTextureLoaderErrorKey&lt;/span&gt;])&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s4&quot;&gt;NSLog&lt;/span&gt;(&lt;span class=&quot;s5&quot;&gt;@&quot;%@&quot;&lt;/span&gt;, [userInfo &lt;span class=&quot;s4&quot;&gt;objectForKey&lt;/span&gt;:&lt;span class=&quot;s1&quot;&gt;GLKTextureLoaderErrorKey&lt;/span&gt;]);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s2&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;s2&quot;&gt;nil&lt;/span&gt; != [userInfo &lt;span class=&quot;s4&quot;&gt;objectForKey&lt;/span&gt;:&lt;span class=&quot;s1&quot;&gt;GLKTextureLoaderGLErrorKey&lt;/span&gt;])&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s4&quot;&gt;NSLog&lt;/span&gt;(&lt;span class=&quot;s5&quot;&gt;@&quot;%@&quot;&lt;/span&gt;, [userInfo &lt;span class=&quot;s4&quot;&gt;objectForKey&lt;/span&gt;:&lt;span class=&quot;s1&quot;&gt;GLKTextureLoaderGLErrorKey&lt;/span&gt;]);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
The outer if statement checks to see if there was an error at all.&amp;nbsp; If everything went ok, our error object should still be nil.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
If there was an error, the first thing we do get the error domain.&amp;nbsp; Each part of the the iOS framework has its own error domain, and each domain has a different set of error codes.&amp;nbsp; To find out what an error code means, you must know what domain the code is coming from.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Next we output the domain and a high level description of the error to the console.&amp;nbsp; Other than the error number, the description tends to be vague and worthless.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Depending on the error domain, you may be able to pull a more helpful message out of the error object.&amp;nbsp; &amp;nbsp; The next lines get a userInfo dictionary out of the error object, which may more information.&amp;nbsp; If the domain is from the GLKTextureLoader itself, we try to pull two additional error messages out of the dictionary and output them to the console.&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBI1DH4P1togPDO2VdHELU5EKw_G6dxRxOVURkFtrvVPZzodfoXzNSRVCpCrpYyQcrjlTEA3dhnP7uVFgN5vDoby-y8HHNs6cCu46Q2pYkCT93IwTJuVzhRSjBJlyoYkr4JTwqi0ZlJioj/s1600/Screen+Shot+2012-02-20+at+11.46.19+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;490&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBI1DH4P1togPDO2VdHELU5EKw_G6dxRxOVURkFtrvVPZzodfoXzNSRVCpCrpYyQcrjlTEA3dhnP7uVFgN5vDoby-y8HHNs6cCu46Q2pYkCT93IwTJuVzhRSjBJlyoYkr4JTwqi0ZlJioj/s640/Screen+Shot+2012-02-20+at+11.46.19+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
I&#39;ll show you how to induce some of these error messages in a second, but first lets get our program working correctly.&amp;nbsp; Add the following line of code to the setupGL function, right below the call to loadShaders:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p10&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;loadTextures&lt;span class=&quot;s3&quot;&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p10&quot;&gt;
&lt;span class=&quot;s3&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnXsLAUQlgG8I7p9G0hPjyiOkXzlBofntQdkG21BExve5t9vaJkKAIxYbwdBZ5cFiOZTQi3HVkRxpXkSIer6CRYloLa_zwZnyvZdkPaIZpaW0G5EGHip_FZmc-Fgb74VtfaaifxXDbpP9l/s1600/Screen+Shot+2012-02-20+at+11.52.42+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;490&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnXsLAUQlgG8I7p9G0hPjyiOkXzlBofntQdkG21BExve5t9vaJkKAIxYbwdBZ5cFiOZTQi3HVkRxpXkSIer6CRYloLa_zwZnyvZdkPaIZpaW0G5EGHip_FZmc-Fgb74VtfaaifxXDbpP9l/s640/Screen+Shot+2012-02-20+at+11.52.42+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p11&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
If you run the project now you shouldn&#39;t see any error messages in the console, which is good, except it&#39;s not testing our error logging function.&amp;nbsp; To induce an error, change the textureWithContentsOfFile function call so that we are passing in the filename of texture directly instead of using the bundle path:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s6&quot;&gt;_texture&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; = [&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;GLKTextureLoader&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;textureWithContentsOfFile&lt;span class=&quot;s3&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;@&quot;bloogle&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;options&lt;span class=&quot;s3&quot;&gt;:options &lt;/span&gt;error&lt;span class=&quot;s3&quot;&gt;:&amp;amp;error];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span class=&quot;s3&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeoKdvd6WmQmdvaPNEc5sLDFn9LiKm3mPK9knrKV5gYgiUYwfM6_qVPWjnVGCuEPnG9gPoY4t-VOoZt2GZrdKh66SOHtDplWeIppNcS_PFfgHOIGS3JmGRApSl1RYoNX9JMJMU1uGovkqB/s1600/Screen+Shot+2012-02-21+at+12.04.07+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeoKdvd6WmQmdvaPNEc5sLDFn9LiKm3mPK9knrKV5gYgiUYwfM6_qVPWjnVGCuEPnG9gPoY4t-VOoZt2GZrdKh66SOHtDplWeIppNcS_PFfgHOIGS3JmGRApSl1RYoNX9JMJMU1uGovkqB/s640/Screen+Shot+2012-02-21+at+12.04.07+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Now when we run the program we get the following error in our console:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;b&gt;2012-02-21 00:04:22.839 TheTexturing[7689:10103] Error loading texture: The operation couldn’t be completed. (Cocoa error 260.).&amp;nbsp; Domain: NSCocoaErrorDomain&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;b&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
This is a generic unhelpful message from the NSCocoaErrorDomain.&amp;nbsp; If you know how to get a useful message out of this error programically let me know.&amp;nbsp; I ended up hunting down Apple&#39;s &lt;a href=&quot;https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html&quot;&gt;documentation&lt;/a&gt;&amp;nbsp;which told me that error code 260 in the NSCocoaErrorDomain was a &quot;NSFileReadNoSuchFileError&quot; which makes sense since we futzed with the filename to get the error.&amp;nbsp; Don&#39;t forget to change the function call back to the way it was before continuing.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Another way to induce an error is to change the loadTexture call in setupGL so that it is before the setCurrentContext call. &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBPMaSLNEkI2B0YJolny_RhCGQ2X1jCPaR_zA1rBZTnbr0jqYfSO4G2FRlnMCsVGXH4Ur75zifZOypT_kUpj6zOkomi2FPa0V9cfvtgVuU-RgPBYXD6bGecVJGUBLZG6ibSsDqDhogLuqY/s1600/Screen+Shot+2012-02-20+at+11.55.47+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;490&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBPMaSLNEkI2B0YJolny_RhCGQ2X1jCPaR_zA1rBZTnbr0jqYfSO4G2FRlnMCsVGXH4Ur75zifZOypT_kUpj6zOkomi2FPa0V9cfvtgVuU-RgPBYXD6bGecVJGUBLZG6ibSsDqDhogLuqY/s640/Screen+Shot+2012-02-20+at+11.55.47+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
When you run the program now, you should get the following errors in the console:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;b&gt;2012-02-20 23:56:30.378 TheTexturing[7631:10103] Error loading texture: The operation couldn’t be completed. (GLKTextureLoaderErrorDomain error 17.).&amp;nbsp; Domain: GLKTextureLoaderErrorDomain&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;b&gt;2012-02-20 23:56:30.383 TheTexturing[7631:10103] Invalid EAGL context&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
The first error is our generic unhelpful error.&amp;nbsp; But since it&#39;s from the GLKTextureLoaderErrorDomain we also get a slightly more helpful message informing us that our EAGL context is invalid.&amp;nbsp; This is because we called our load texture function before we set the context.&amp;nbsp; Move the load texture function call back to where it was to make this error go away.&amp;nbsp; The complete list of error codes for the GLKTextureLoaderErrorDomain can be found in Apple&#39;s &lt;a href=&quot;https://developer.apple.com/library/ios/#DOCUMENTATION/GLkit/Reference/GLKTextureLoader_ClassRef/Reference/Reference.html#//apple_ref/doc/constant_group/Texture_Loading_Options&quot;&gt;documentation&lt;/a&gt;.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Now that we&#39;ve loaded the image data into a texture, we need to tell OpenGL how to use that texture.&amp;nbsp; First, we will apply the texture to the red fixed function cube.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
The first thing we need to do is add texture coordinates to the vertex data near the top of our view controller .m file.&amp;nbsp; Find the declaration of the gCubeVertexData array and change it like so:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;GLfloat&lt;/span&gt; gCubeVertexData[] =&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p6&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;// Data layout for each line below is:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p6&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;// positionX, positionY, positionZ, &amp;nbsp; &amp;nbsp; normalX, normalY, normalZ, texCoordS, texCoordT&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;1&lt;/span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;0.5f&lt;/span&gt;,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, &lt;span class=&quot;s8&quot;&gt;0.0f&lt;/span&gt;, -&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;, &amp;nbsp; &lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: x-small;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
A brief explanation of this array:&amp;nbsp; Each line describes a single vertex.&amp;nbsp; The first three numbers are the X,Y,Z position of the vertex.&amp;nbsp; The second three numbers describe a normal vector that points away from the face of the cube that this vertex is part of.&amp;nbsp; Normal vectors are used in lighting calculations.&amp;nbsp; OpenGL uses the dot product of the normal vector and the vector from the light source to the vertex to find the angle between them.&amp;nbsp; If the angle is very small, the light is shining directly on the geometry and it appears very bright.&amp;nbsp; As the angle increases, the light gets dimmer.&lt;br /&gt;
&lt;br /&gt;
The two numbers we added to each line are the texture coordinates for the vertex.&amp;nbsp; These map the image data to the face of the geometry.&amp;nbsp; For texture coordinates, 0,0 is the upper left corner of the image, and 1,1 is the lower right.&amp;nbsp; Note that the up-down coordinate gets higher as you go down the texture, which is opposite of the geometry coordinate system. &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Each group of six lines in the array represent one face of the cube.&amp;nbsp; Each face is made up of two triangles.&amp;nbsp; Notice that this array only holds information for a single cube.&amp;nbsp; This data is loaded once, then used twice to draw two cubes on the screen.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
If you&#39;re adding the texture coordinates one at a time like I did, don&#39;t forget to add a comma after the last normal vector.&amp;nbsp; Also don&#39;t forget to remove the size of the array from the square brackets.&amp;nbsp; It is unnecessary and will break your code if you add elements to the array without updating it.&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJs7jkipzt91wWSdSHbhC1P3Vu3LVXsQv6zBs6Xh1RC11h0qDfcQfG5gG8T23rs8W2sMN4i48U7YouV2L8gOt8rHgDNoCBTc9CANUoP2OPStMHdrgw-egXrL8q4Srj7NnFIWfnGPmPlWma/s1600/Screen+Shot+2012-02-21+at+12.37.31+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJs7jkipzt91wWSdSHbhC1P3Vu3LVXsQv6zBs6Xh1RC11h0qDfcQfG5gG8T23rs8W2sMN4i48U7YouV2L8gOt8rHgDNoCBTc9CANUoP2OPStMHdrgw-egXrL8q4Srj7NnFIWfnGPmPlWma/s640/Screen+Shot+2012-02-21+at+12.37.31+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
After changing vertex data array, we need to go back down to the setupGL function and make some changes.&amp;nbsp; First find the line that sets the light0.diffuseColor and change the 0.4s to 1.0s.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p9&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s2&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;light0&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;diffuseColor&lt;span class=&quot;s3&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;GLKVector4Make&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;1.0f&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
This line is setting the color of the light source for the fixed functionality cube.&amp;nbsp; The four numbers represent the red, green, blue, and alpha (or opacity) values of the light.&amp;nbsp; OpenGL tends to specify these values from 0 to 1.&amp;nbsp; If you work with HTML at all, you may be more familiar with the hexadecimal representation of color, from 00 to FF.&amp;nbsp; This is changing the light shining on the cube from red to white.&amp;nbsp; This is so it looks normal when the texture is applied.&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhch4ccEx8i7uJgvK5ZavZ1aQDScHC5GA3FPP_f9iStgWqZ9HYQoLmbFRZnPwjcZ3aasy6pJ3Ej8tGcDS3UK05kXvd1oZqqoPv2Ppxf_n7PzykNC2vgpfDN6hbwiW23_Jzwk0PBUZj-8fay/s1600/Screen+Shot+2012-02-21+at+12.39.23+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhch4ccEx8i7uJgvK5ZavZ1aQDScHC5GA3FPP_f9iStgWqZ9HYQoLmbFRZnPwjcZ3aasy6pJ3Ej8tGcDS3UK05kXvd1oZqqoPv2Ppxf_n7PzykNC2vgpfDN6hbwiW23_Jzwk0PBUZj-8fay/s640/Screen+Shot+2012-02-21+at+12.39.23+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Next, add the following lines of code directly under code you just changed:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p9&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;texture2d0&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;enabled&lt;span class=&quot;s3&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;GL_TRUE&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;texture2d0&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;envMode&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; = &lt;/span&gt;GLKTextureEnvModeModulate&lt;span class=&quot;s3&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;texture2d0&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; = &lt;/span&gt;GLKTextureTarget2D&lt;span class=&quot;s3&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p9&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;effect&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;texture2d0&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;s3&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;_texture&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;s3&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
The first line enables the texture we loaded.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
The second line describes how OpenGL will apply the texture.&amp;nbsp; Modulate mixes the texture color with the light color.&amp;nbsp; If we had chosen Replace, we would end up with a flat, perfectly bright cube that is not impacted by light at all.&lt;br /&gt;
&lt;br /&gt;
The third line and fourth line sets the active texture to the one we loaded earlier.&amp;nbsp; I believe (but I could be wrong) that the third and fourth line is roughly the same as calling glBindTexture(GL_TEXTURE_2D, _texture.name).&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWH14bVkOo08vkV2ITtRyBYcsmRTwDDaqoIHWFUpZLiU4ce_rcEK7XfNjY0CPfo_vSZzwn4SoBWdvyGFJmFU0skQ9RV4k6spdtGs_k-8VptbyRJobwMtgqeLnnH-s8cX1NPi2ER6TqYErz/s1600/Screen+Shot+2012-02-21+at+12.51.05+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWH14bVkOo08vkV2ITtRyBYcsmRTwDDaqoIHWFUpZLiU4ce_rcEK7XfNjY0CPfo_vSZzwn4SoBWdvyGFJmFU0skQ9RV4k6spdtGs_k-8VptbyRJobwMtgqeLnnH-s8cX1NPi2ER6TqYErz/s640/Screen+Shot+2012-02-21+at+12.51.05+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Now we need to change the pointers to the vertex array that we pass OpenGL.&amp;nbsp; Change the calls the VertexArrib* functions like so:&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;glVertexAttribPointer&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;GLKVertexAttribPosition&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;GL_FLOAT&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;GL_FALSE&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;BUFFER_OFFSET&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;glEnableVertexAttribArray&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;GLKVertexAttribNormal&lt;span class=&quot;s3&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;glVertexAttribPointer&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;GLKVertexAttribNormal&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;GL_FLOAT&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;GL_FALSE&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;BUFFER_OFFSET&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;glEnableVertexAttribArray&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;GLKVertexAttribTexCoord0&lt;span class=&quot;s3&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;glVertexAttribPointer&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;GLKVertexAttribTexCoord0&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;GL_FLOAT&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;GL_FALSE&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s9&quot;&gt;BUFFER_OFFSET&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
The glVertexAttribPointer functions are telling OpenGL where to find the position, normal, and texture coordinate information in the array we pass in.&lt;br /&gt;
&lt;br /&gt;
The first parameter is an enum value that we use to refer to different information in our vertex array. &amp;nbsp;By passing in these values here, we can use them later to refer to when working with OpenGL to refer to the position, normal, or texture coordinate information.&amp;nbsp;The second parameter is how many dimensions to look for.&amp;nbsp; The third is the type of the array.&amp;nbsp; The fourth is whether the data is normalized.&amp;nbsp; A normalized vector has a length of one. &amp;nbsp;The fifth parameter is the number of bytes to skip when reading the information for each vertex from the array.&amp;nbsp; You can also think of this as the number of bytes in a single line in the array above ((3 position coordinates + 3 normal coordinates + 2 texture coordinates) * 4 bytes per coordinate).&amp;nbsp; The last parameter is where in the array to start reading (in bytes).&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz5W6b4sgEqD0byZR3kwm522hodLTP8qBjDDSRapB5ISYzcsNAh5AfjeXFlAF5cX8nRS89soTSwNfaBvO4FRW6QJ59q9Xp1gRVAUZVo4pB1p4aR_WS6WrIXG0Qqu-P0tE1snC2bZV5vd8Q/s1600/Screen+Shot+2012-02-21+at+1.03.46+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz5W6b4sgEqD0byZR3kwm522hodLTP8qBjDDSRapB5ISYzcsNAh5AfjeXFlAF5cX8nRS89soTSwNfaBvO4FRW6QJ59q9Xp1gRVAUZVo4pB1p4aR_WS6WrIXG0Qqu-P0tE1snC2bZV5vd8Q/s640/Screen+Shot+2012-02-21+at+1.03.46+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
After making these changes, run the program.&amp;nbsp; The red cube should now be texturized!&amp;nbsp; Note that the shading from the light source is still applied.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg558-W5KkobtkwaY9kDqC5gqiFJHmlkTuLz9PLqQsLjDkzMQmm_B_vWvCeAPHMse-eMix4FjOtdSR6CzKuO6j3joXVBb1_V4fukeKp8ayLZ6Bh0QlZ13nmFx5ZtXNfxuclICtfGovYnxvI/s1600/Screen+Shot+2012-02-21+at+1.04.55+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg558-W5KkobtkwaY9kDqC5gqiFJHmlkTuLz9PLqQsLjDkzMQmm_B_vWvCeAPHMse-eMix4FjOtdSR6CzKuO6j3joXVBb1_V4fukeKp8ayLZ6Bh0QlZ13nmFx5ZtXNfxuclICtfGovYnxvI/s640/Screen+Shot+2012-02-21+at+1.04.55+AM.png&quot; width=&quot;508&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Even though we&#39;ve only changed one cube we are well over half way done.&amp;nbsp; Most of the work to load the texture information into OpenGL applies to both types of rendering.&amp;nbsp; Now all we have to do is set up the shaders to use the information we have provided.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Let&#39;s start by going to the Shader.vsh file and changing it to take advantage of our texture data.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
First, add a new attribute declaration below the position and normal attributes:&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;attribute vec2 texcoord0;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Attributes are values that we pass to the shader from our program on a per vertex basis.&amp;nbsp; In our case, the attributes are contained in the vertex array that we added texture coordinates to.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Next, add a new varying variable declaration below the colorVarying declaration:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;varying mediump vec2 texcoord_varying;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
These varying values will be interpolated and passed to the fragment shader.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Next, change the diffuseColor vector so that it is white instead of blue.&amp;nbsp; This is changing the blue light to white for exactly the same reason we changed the red light to white earlier.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;vec4 diffuseColor = vec4(1.0, 1.0, 1.0, 1.0);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Finally, add a line that assigns the texcoord value the vertex shader receives from the program&amp;nbsp; to the texcood_varying value that it passes to the fragment shader.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;texcoord_varying = texcoord0;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
That&#39;s all we have to do to the vertex shader.&amp;nbsp; It should now look like the screen shot:&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_SHJxeilLzJhP3byQZ-vfKVBsu7BmN3Zz3aubRorM8dW6rgfrEQwaDJOgFnRwYh5dG3mWCc5PKEwablPO8of9fsehaV8uULEtG_Z1X2GOmn1ggqaycMskNrhtWbeejtBEZzbnVY8_mGOd/s1600/Screen+Shot+2012-02-21+at+1.30.44+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_SHJxeilLzJhP3byQZ-vfKVBsu7BmN3Zz3aubRorM8dW6rgfrEQwaDJOgFnRwYh5dG3mWCc5PKEwablPO8of9fsehaV8uULEtG_Z1X2GOmn1ggqaycMskNrhtWbeejtBEZzbnVY8_mGOd/s640/Screen+Shot+2012-02-21+at+1.30.44+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Now lets go to the Shader.fsh file and modify the fragment shader.&amp;nbsp; Even though it&#39;s doing the actual work of specifying each pixel&#39;s color, it is much smaller.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
First, add a declaration for a varying variable to match the one in the vertex shader:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;varying mediump vec2 texcoord_varying;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Next, add a uniform sampler declaration.&amp;nbsp; This is the actual image data for our texture:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;uniform sampler2D texture;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Finally, change the gl_FragColor assignment in the main function like so:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;gl_FragColor = texture2D(texture, texcoord_varying) * colorVarying;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
The texture2D function uses the interpolated texture coordinate to pull a color from a image data.&amp;nbsp; We then multiply it by the colorVarying attribute which contains the lighting value as calculated in the vertex shader.&amp;nbsp; If the light is shining directly on the face, then this has the effect of multiplying the texture color by one, which does not change it at all.&amp;nbsp; If the light is shining on the face at an angle, this multiplies the texture color by some number between one and zero, making it darker.&amp;nbsp; This is why each face of the cube gets darker as it rotates away from the light source.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Now we are done modifying the fragment shader.&amp;nbsp; It should look like the screen shot below:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi81TJfvZAuRVM1FpjQYFL_IA-7AWMKLdZ0NdUginYplMz8gq3sOxR9f0M0Ay31Ol-nSvB_Tzpq0xXS4SnjxQUx4bNc6eJvQkOmH5QAZiI1mvqDnwFg_KpkbxQkWma3VTHBrAPF0XNeoEyc/s1600/Screen+Shot+2012-02-21+at+1.28.17+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi81TJfvZAuRVM1FpjQYFL_IA-7AWMKLdZ0NdUginYplMz8gq3sOxR9f0M0Ay31Ol-nSvB_Tzpq0xXS4SnjxQUx4bNc6eJvQkOmH5QAZiI1mvqDnwFg_KpkbxQkWma3VTHBrAPF0XNeoEyc/s640/Screen+Shot+2012-02-21+at+1.28.17+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Now that we&#39;ve modified the shaders to take advantage of the texture data, we need to connect the new variables we declared to their counterparts in our view controller.&amp;nbsp; Start by adding the following line to the enum at the very top of the view controller .m file:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;UNIFORM_TEXTURE_SAMPLER,&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Be sure to add this above the NUM_UNIFORMS entry, so that it is still incremented correctly.&amp;nbsp; This enum represents the set of identifiers that we use to refer to the variables in the shaders.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlta7fuWwR8Pqg7vueVyrq8SHbcYzfyTIrd35iGvj8FpYllaAiFhokkHAAtoqNKIxx08P-C2o581NXb_1HiCVgz6AJYlLLVm59J0Sxdkd4vaXimveDSK3TgXwhfuAJa0BEEEInmggvzrwX/s1600/Screen+Shot+2012-02-21+at+1.10.35+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlta7fuWwR8Pqg7vueVyrq8SHbcYzfyTIrd35iGvj8FpYllaAiFhokkHAAtoqNKIxx08P-C2o581NXb_1HiCVgz6AJYlLLVm59J0Sxdkd4vaXimveDSK3TgXwhfuAJa0BEEEInmggvzrwX/s640/Screen+Shot+2012-02-21+at+1.10.35+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Next go to the loadShaders function and add the following call to glBindAttributeLocation below the two that are already there.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p7&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;glBindAttribLocation&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;_program&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;GLKVertexAttribTexCoord0&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;texcoord0&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
As the function name implies, this associates the texcoord0 variable in the vertex shader with the data referred to by the GLKVertexAttribTexCoord0 constant.&amp;nbsp; Whenever we need to refer to the shader variable we can use this constant. &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV5Fs3Is36JbMwOzSRpJ_MuWNWUdD4rdTh8g2rFYwE9TpnB2TXh8E5x45N2f6QTjEdXhW07QHXOuZ254w2WKkpjUgRcy6-PMlHY5nlDFM47tLdeFlF0R-QYepBBffhsnHyz66iP-KRh4nd/s1600/Screen+Shot+2012-02-21+at+1.35.36+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV5Fs3Is36JbMwOzSRpJ_MuWNWUdD4rdTh8g2rFYwE9TpnB2TXh8E5x45N2f6QTjEdXhW07QHXOuZ254w2WKkpjUgRcy6-PMlHY5nlDFM47tLdeFlF0R-QYepBBffhsnHyz66iP-KRh4nd/s640/Screen+Shot+2012-02-21+at+1.35.36+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
If you look carefully you&#39;ll notice that the BindAttribute function call we added does not match the two that are already there.&amp;nbsp; The other two function calls use members of an enum that is declared at the top of the file.&amp;nbsp; You may be wondering why we didn&#39;t add a member to this enum and pass it to the glBindAttributeLocation function.&amp;nbsp; It took me a while to realize it, but that enum is actually completely pointless, misleading, and a trap for the unwary programmer. &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
OpenGL works by assigning identifiers to resources.&amp;nbsp; When you give OpenGL a vertex array, you also give it an identifier to use to refer to that array.&amp;nbsp; In the glEnableVertexAttribArray and glVertexAttribPointer calls in the setupGL function, we pass in GLKVertexAttribPosition, GLKVertexAttribNormal, and GLKVertexAttribTexCoord0 constants to refer to the array&#39;s position, normal, and texture coordinate information.&amp;nbsp; Now it just so happens that GLKVertexAttribPosition and GLKVertexAttribNormal are equal to 0 and 1 respectively.&amp;nbsp; So when the anonymous author of OpenGL Game project later uses ATTRIB_VERTEX and ATTRIB_NORMAL, which are also equal to 0 and 1, to bind these resources to the shader attributes, everything works out ok.&amp;nbsp; But this is just a happy coincidence due to the similar ordering of these values within their respective enum declarations.&amp;nbsp; Adding an ATTRIB_TEXCOORD member to our enum would give it a value of 2 (assuming you follow standard practice and insert it above the NUM_ATTRIBUTES member.)&amp;nbsp; Unfortunately the GLKVertexAttribtexCoord0 constant we used to refer to the texture coordinate data earlier has a value of 3.&amp;nbsp; So if we follow the example given us in the OpenGL Game project we would end up with broken code.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Anywho, after you add the glBindAttribLocation call, go down a little further in the loadShaders function and add an additional uniform assignment:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p10&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s6&quot;&gt;uniforms&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;[&lt;/span&gt;UNIFORM_TEXTURE_SAMPLER&lt;span class=&quot;s3&quot;&gt;] = &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;glGetUniformLocation&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;_program&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;texture&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
This follows the typical OpenGL pattern of assigning an unsigned integer identifier to a OpenGL resource.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASnHETWJHIEMlQ-FrDzRS9_HMHuo8PDNT-xuszEbIFB86y_7RWfv7JfJv-LaAcZ4WzDnlVWVZ9BxA7lMzp84rwv7GcjdKV4hkHKvU3ELjluAs0bBCI4KPGaSIJIkEzTQu3R1qZz1jftDn/s1600/Screen+Shot+2012-02-21+at+2.03.14+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASnHETWJHIEMlQ-FrDzRS9_HMHuo8PDNT-xuszEbIFB86y_7RWfv7JfJv-LaAcZ4WzDnlVWVZ9BxA7lMzp84rwv7GcjdKV4hkHKvU3ELjluAs0bBCI4KPGaSIJIkEzTQu3R1qZz1jftDn/s640/Screen+Shot+2012-02-21+at+2.03.14+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Finally go to the drawInRect function and add the code to bind the texture sampler with the image data:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p10&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s4&quot;&gt;glUniform1i&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s6&quot;&gt;uniforms&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;[&lt;/span&gt;UNIFORM_TEXTURE_SAMPLER&lt;span class=&quot;s3&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;s8&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
While I was modifying the drawInRect function, I took a moment to change the ClearColor from gray to white:&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p12&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;s4&quot;&gt;glClearColor&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;(&lt;/span&gt;1.0f&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;1.0f&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;1.0f&lt;span class=&quot;s3&quot;&gt;, &lt;/span&gt;1.0f&lt;span class=&quot;s3&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
This is by no means necessary, I just think the gray background looks really ugly.&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgovrAtIdYCCy-rJuRjYq02xmKP0P5tZRL5xGGCHPDjzeXTp76h5ApOPUxU-zkj_nY6rgMJLNstfxq2G89jmptcERlwTnBuWhbwTwnuqU4wFRElF5lbWp7As4Pt7TgVki9_vA_UhUxdMchC/s1600/Screen+Shot+2012-02-21+at+2.10.40+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgovrAtIdYCCy-rJuRjYq02xmKP0P5tZRL5xGGCHPDjzeXTp76h5ApOPUxU-zkj_nY6rgMJLNstfxq2G89jmptcERlwTnBuWhbwTwnuqU4wFRElF5lbWp7As4Pt7TgVki9_vA_UhUxdMchC/s640/Screen+Shot+2012-02-21+at+2.10.40+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
Running the program now gives you two cubes, both textured and lit:&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSKsKRt1zTkQdwcllkbxWhAWEXuEMLvJY2SJ6DjsPkj2NYMMoYadLTDOUy1JoZFcK6A9ZeyvTVGDbuc6JMhj32nnuhSQd8ntCH6Bee6wLEsW9E4BPx2dl1Vkvhm4MqdzZnY81pH71DOmKr/s1600/Screen+Shot+2012-02-21+at+2.42.03+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSKsKRt1zTkQdwcllkbxWhAWEXuEMLvJY2SJ6DjsPkj2NYMMoYadLTDOUy1JoZFcK6A9ZeyvTVGDbuc6JMhj32nnuhSQd8ntCH6Bee6wLEsW9E4BPx2dl1Vkvhm4MqdzZnY81pH71DOmKr/s640/Screen+Shot+2012-02-21+at+2.42.03+AM.png&quot; width=&quot;508&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
As I have said before, I am chronicling my blind, fumbling efforts with iOS programming in the hopes that other people may avoid my mistakes (at least the ones I&#39;m aware of.)&amp;nbsp; Use this code with extreme caution. &amp;nbsp;I feel confident that it still contains errors. &amp;nbsp;If you happen to notice one, please let me know.&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.headnoodles.com/feeds/6637955330788120746/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.headnoodles.com/2012/02/using-textures-in-xcode-4-opengl-es-1.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/627201247416879277/posts/default/6637955330788120746'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/627201247416879277/posts/default/6637955330788120746'/><link rel='alternate' type='text/html' href='http://www.headnoodles.com/2012/02/using-textures-in-xcode-4-opengl-es-1.html' title='The Texturing'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04188436224275642399</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFE6yVfznJpJbO516qOd1YJrYSg7Ir_mYC8Pc_xIBtREjcRO0SINERTdSy3zrQK6rS66esypke8n9N7gdQ6F0sXpcJPaMUsqKeYMJtv4X3_y7jWNInxb603e9WY4WcyotHFXNEdcSSwVd2/s72-c/Screen+Shot+2012-02-20+at+11.04.10+PM.png" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-627201247416879277.post-4462617947755514632</id><published>2012-02-20T13:12:00.000-08:00</published><updated>2012-03-02T16:03:24.587-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Gestures"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS 5"/><category scheme="http://www.blogger.com/atom/ns#" term="OpenGL ES"/><category scheme="http://www.blogger.com/atom/ns#" term="Xcode 4"/><title type='text'>Rude Gestures</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
In this post I&#39;m changing the default OpenGL Game project to rotate based on user gestures instead of automatically. &amp;nbsp;This is actually super easy to do once you know how, but if you&#39;re like me and you don&#39;t know much about Objective C or Xcode, there are a couple of annoying gotchas. &amp;nbsp;I&#39;m assuming you are running a Mac with Lion and already have downloaded Xcode and the iOS software development kit. &amp;nbsp;If not you can find both in the Mac app store.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
To create the project, open Xcode, and choose File-&amp;gt;New-&amp;gt;New Project... from the Xcode menu bar. &amp;nbsp;Choose iOS Application on the upper left, and the OpenGL Game option in the middle of the window, then press the Next button.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCM7NjPo2siaUb551MuqUII_CSJNhdm27RNl9sWeG1YzQFQ_7Qfnsca_6LP7r4VvhnCkPcTZJUoHHam-7_7As7U0m1waWg_6v9lVx5ZsHmkj57gf6lCQPQlCyG5P1yj3dvDogMOoRsPvVR/s1600/Screen+Shot+2012-02-20+at+4.11.06+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;428&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCM7NjPo2siaUb551MuqUII_CSJNhdm27RNl9sWeG1YzQFQ_7Qfnsca_6LP7r4VvhnCkPcTZJUoHHam-7_7As7U0m1waWg_6v9lVx5ZsHmkj57gf6lCQPQlCyG5P1yj3dvDogMOoRsPvVR/s640/Screen+Shot+2012-02-20+at+4.11.06+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
On the next screen, name your project whatever you want. &amp;nbsp;I have no idea how to use an Xcode storyboard, so I leave that un-checked, but I like the idea of automatic reference counting.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCz_zjihMvovVYoeEg7Rx7z9UtcsSzBUnB7UeO0UTebiRljZV63GjyBdciOJnh2RZ09DFgc0DrZ93rpa118KnOeni-eX6-MI2o8mFK3Tr89Tb_bjNFyjvsiOH0toFy3n-BL24qprGmA0tZ/s1600/Screen+Shot+2012-02-20+at+4.11.47+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;432&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCz_zjihMvovVYoeEg7Rx7z9UtcsSzBUnB7UeO0UTebiRljZV63GjyBdciOJnh2RZ09DFgc0DrZ93rpa118KnOeni-eX6-MI2o8mFK3Tr89Tb_bjNFyjvsiOH0toFy3n-BL24qprGmA0tZ/s640/Screen+Shot+2012-02-20+at+4.11.47+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
You should end with a new OpenGL project with the project file opened on the screen. &amp;nbsp;I recommend taking a snapshot of your project now, so if you mess anything up you can revert. &amp;nbsp;Go to File-&amp;gt;Create Snapshot... in the menu bar and follow the instructions.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbWgyfWjT54Zzdo8hNS4AtGtEtTa1Fbq5XIihgWlP2iJMWpAtApy0LsrDkyEh951XvPOxRl50v_QT_rppI3yLWJ9mnDDov7cQjDwgPnYy5H3T_0A4gid5_yETtX-n0xafhyphenhyphenBywAtipYXgS/s1600/Screen+Shot+2012-02-20+at+4.14.15+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;380&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbWgyfWjT54Zzdo8hNS4AtGtEtTa1Fbq5XIihgWlP2iJMWpAtApy0LsrDkyEh951XvPOxRl50v_QT_rppI3yLWJ9mnDDov7cQjDwgPnYy5H3T_0A4gid5_yETtX-n0xafhyphenhyphenBywAtipYXgS/s640/Screen+Shot+2012-02-20+at+4.14.15+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;&lt;/div&gt;
You can run the project (Command-R) and see two cubes rotating around each other. &amp;nbsp;One is rendered using GLKit, which among other things is Apple&#39;s re-implementation of the OpenGL ES 1.x fixed functionality render pipeline, and the other is rendered using the OpenGL ES 2.0 vertex and fragment shaders.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyFVFJvngK4VrhOvI4tYZtYpXPDSssUzLJjwi_hsqR7_eWbQAJMhfuuAjcALXKK-J2arLJ7g_6nx7NkoKU5OWfyM-QmoIsZbKUFVlRkQlRG4RyeNbsjILyY0xbICh4yka-kOT1hu4R6IUF/s1600/Screen+Shot+2012-02-20+at+4.28.44+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyFVFJvngK4VrhOvI4tYZtYpXPDSssUzLJjwi_hsqR7_eWbQAJMhfuuAjcALXKK-J2arLJ7g_6nx7NkoKU5OWfyM-QmoIsZbKUFVlRkQlRG4RyeNbsjILyY0xbICh4yka-kOT1hu4R6IUF/s640/Screen+Shot+2012-02-20+at+4.28.44+AM.png&quot; width=&quot;508&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now to add gesture support we need to go to the interface builder and edit the nib file. &amp;nbsp;The Project navigator should be opened on the left side of the screen, showing a tree view of the files and folders that make up your project. &amp;nbsp;If it&#39;s not opened, you can show it by pressing Command-1 on the keyboard. &amp;nbsp;Once it&#39;s opened select the file with the .xib extension by single clicking on it. &amp;nbsp;You will see a big blank view. &amp;nbsp;Find the tap gesture recognizer in the object library in the lower right of the window. &amp;nbsp;You can filter for it by typing &quot;gesture&quot; in the little text box at the very bottom of the window.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRf6bHmxa1aqv6EekwNmJENOpa5H5Zlvz-w-2fWOwm_1fdtTy6r4bM1g9DgkXHFIykQM8lx0vlWN4CDSEh9DEtFDY8hs3XtyCxY7vPDj5SQbMMEW-XEX-_mWRqGdt4isaQ46DDTkez62b7/s1600/Screen+Shot+2012-02-20+at+4.15.12+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;379&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRf6bHmxa1aqv6EekwNmJENOpa5H5Zlvz-w-2fWOwm_1fdtTy6r4bM1g9DgkXHFIykQM8lx0vlWN4CDSEh9DEtFDY8hs3XtyCxY7vPDj5SQbMMEW-XEX-_mWRqGdt4isaQ46DDTkez62b7/s640/Screen+Shot+2012-02-20+at+4.15.12+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now drag the tap gesture recognizer from the object library to the blank view in the middle of the screen. &amp;nbsp;It&#39;s possible to drag the recognizer other places, such as the list of objects to the right of the view, but those are bad, wrong places that will cause the tap gesture recognizer to silently fail. &amp;nbsp;I say again, drag the tap gesture recognizer to the blank white area in the middle of your window, and nowhere else. &amp;nbsp;Once you drag it over, it will appear in the list of objects in the nib file. &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now we need to add an action to our view controller. &amp;nbsp;Activate the assistant editor by pressing option-command-enter on your keyboard, or by clicking the little tuxedo button in the upper right of the window. &amp;nbsp;The view controller .h file should appear in a new pane on the right side of the window.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhAgEhswrvhEWy3LkCp5XcK7IAHikrZARjk0vq1Vv9hFfIETrwkB14wNT2EJ_aO9eAB58brkd_TRKLRPqin4e2a8SV-jytYd6M42YGykEwd-Rk7he1bVw6pz6fJeHlQV_nw8ZYeHW5zVgK/s1600/Screen+Shot+2012-02-20+at+3.45.00+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;380&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhAgEhswrvhEWy3LkCp5XcK7IAHikrZARjk0vq1Vv9hFfIETrwkB14wNT2EJ_aO9eAB58brkd_TRKLRPqin4e2a8SV-jytYd6M42YGykEwd-Rk7he1bVw6pz6fJeHlQV_nw8ZYeHW5zVgK/s640/Screen+Shot+2012-02-20+at+3.45.00+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now right click and drag from the tap gesture recognizer in the list of objects in the nib file (NOT from the object library) to the area in the view controller .h file between @interface and @end. &amp;nbsp;In the little context dialog box that pops up, select an Action connection and name it something meaningful. &amp;nbsp;I changed the type to UIPanGestureRecognizer, but I&#39;m not sure it makes a difference.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxQ-RTGR_TXb7US5gu-GSHW70TlM0F13avodOi03s-NYnroySjmtYD_QuBi0c52-eg6vn7mQOvky7alM4-fDz4oTOeP5VP_VqzhoO0y7JBkA3p7hVHrETyilfX1WlYsM_-PKycAYJEjjxf/s1600/Screen+Shot+2012-02-20+at+4.18.13+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;78&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxQ-RTGR_TXb7US5gu-GSHW70TlM0F13avodOi03s-NYnroySjmtYD_QuBi0c52-eg6vn7mQOvky7alM4-fDz4oTOeP5VP_VqzhoO0y7JBkA3p7hVHrETyilfX1WlYsM_-PKycAYJEjjxf/s320/Screen+Shot+2012-02-20+at+4.18.13+AM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Once you hit the Connect button you will see a new IBAction declaration, which is basically analogous to an event handler. &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinOZMzt7Nt-0g26pZtGdzUJUvV93actvBYudmC1sLORRFsvTavj9Y-Gkg6uMZz6-FCe_5lqM8PdnTqBFbr7HIleFIBSzZW9kjUZ6KuMmltRB6Gwi26vqloZeM6hyphenhyphen03pmrXxvGukVCtG6hw/s1600/Screen+Shot+2012-02-20+at+3.39.00+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;380&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinOZMzt7Nt-0g26pZtGdzUJUvV93actvBYudmC1sLORRFsvTavj9Y-Gkg6uMZz6-FCe_5lqM8PdnTqBFbr7HIleFIBSzZW9kjUZ6KuMmltRB6Gwi26vqloZeM6hyphenhyphen03pmrXxvGukVCtG6hw/s640/Screen+Shot+2012-02-20+at+3.39.00+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;
The skeleton of its implementation was also automatically added to the view controller .m file, and that&#39;s the file we are going to edit next.&lt;/div&gt;
&lt;div class=&quot;&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Get rid of the assistant editor by pressing command-enter on your keyboard or by going to the View-&amp;gt;Standard Editor-&amp;gt;Show Standard Editor menu option in the menu bar. &amp;nbsp;Then select the view controller .m file in the project navigator to the left of your window. &amp;nbsp;The first thing we want to do is comment out the last line in the update function which increments the rotation value. &amp;nbsp;The update function is called by the framework before every frame and it&#39;s this line that causes the cubes to automatically rotate around each other.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXYXenI4dMH9WJmenhQxCGYmey8KgdKeyedvaUacGBqLcg5UyLwdXAHsOR6pWDkkCMuP27oJALpspOxZjL-cU0fFcBw2hOfksqjK8nXz9za10BsQMB2tqrPlb6xCJE24-HC4F1-CdsEOiy/s1600/Screen+Shot+2012-02-20+at+4.23.30+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;380&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXYXenI4dMH9WJmenhQxCGYmey8KgdKeyedvaUacGBqLcg5UyLwdXAHsOR6pWDkkCMuP27oJALpspOxZjL-cU0fFcBw2hOfksqjK8nXz9za10BsQMB2tqrPlb6xCJE24-HC4F1-CdsEOiy/s640/Screen+Shot+2012-02-20+at+4.23.30+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now we need to update the rotation value ourselves, in the new pan gesture event handler that Xcode added for us at the bottom of the view controller file. &amp;nbsp;Add these two lines to the empty function:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;s1&quot;&gt;CGPoint&lt;/span&gt; translation = [sender &lt;span class=&quot;s2&quot;&gt;translationInView&lt;/span&gt;:&lt;span class=&quot;s3&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;s1&quot;&gt;view&lt;/span&gt;];&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s4&quot;&gt;_rotation&lt;/span&gt; = translation.&lt;span class=&quot;s1&quot;&gt;x&lt;/span&gt; / &lt;span class=&quot;s5&quot;&gt;100.0f&lt;/span&gt;;&lt;/div&gt;
&lt;br /&gt;
The first line gets the amount that the user panned in both the x and y directions. &amp;nbsp;The second line sets our rotation value equal to the amount the user slide his finger back or forth. &amp;nbsp;We divide by 100 because the rotation value is in radians. &amp;nbsp;2*pi radians (a little over 6) is&amp;nbsp;equivalent&amp;nbsp;to a full 360 degree rotation, so if every frame the user drags their finger 4 or 5 pixels the cubes will rotate almost all the way around. &amp;nbsp;We want to slow that down so it looks better and is easier to control.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5M-VLL3jwqy3ykpmDVWBLwnFy5gzuiHBQYe4zQNxAO7wfQbiVqOoijAHfXbbNKVfX0VcUB9qivyQNxW3SlqPXOi2hgiH9BoXmXlvXl5FDafXNmq_bvmmhs07MJZHnEBYYOmK_Q-m3ETCc/s1600/Screen+Shot+2012-02-20+at+4.28.19+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;379&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5M-VLL3jwqy3ykpmDVWBLwnFy5gzuiHBQYe4zQNxAO7wfQbiVqOoijAHfXbbNKVfX0VcUB9qivyQNxW3SlqPXOi2hgiH9BoXmXlvXl5FDafXNmq_bvmmhs07MJZHnEBYYOmK_Q-m3ETCc/s640/Screen+Shot+2012-02-20+at+4.28.19+AM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&amp;nbsp;Now run the project again. &amp;nbsp;When the simulator comes up the cubes will be stationary until you click and drag your mouse or trackpad across the screen. &amp;nbsp;Then you make the cubes rotate back and forth.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyFVFJvngK4VrhOvI4tYZtYpXPDSssUzLJjwi_hsqR7_eWbQAJMhfuuAjcALXKK-J2arLJ7g_6nx7NkoKU5OWfyM-QmoIsZbKUFVlRkQlRG4RyeNbsjILyY0xbICh4yka-kOT1hu4R6IUF/s1600/Screen+Shot+2012-02-20+at+4.28.44+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyFVFJvngK4VrhOvI4tYZtYpXPDSssUzLJjwi_hsqR7_eWbQAJMhfuuAjcALXKK-J2arLJ7g_6nx7NkoKU5OWfyM-QmoIsZbKUFVlRkQlRG4RyeNbsjILyY0xbICh4yka-kOT1hu4R6IUF/s640/Screen+Shot+2012-02-20+at+4.28.44+AM.png&quot; width=&quot;508&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
This post is very much the chronicle of me fumbling around in the dark with Xcode and iOS development. I&#39;m writing this in the hopes of helping other people avoid the same pitfalls and blind alleys I stumbled on. &amp;nbsp;If you find any mistakes or know of a safer, saner, or more interesting way to do this, please let me know.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
PS - One of the many cool things I learned how to do while writing this was how to take screenshots on the Mac. &amp;nbsp;Pressing Command-Shift-4 allows you to select an area of your screen to which will automatically appear as an image on your desktop. &amp;nbsp;Pressing Command-Shift-4, then the space bar will allow you to click on a window to take a screenshot of the entire window.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.headnoodles.com/feeds/4462617947755514632/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.headnoodles.com/2012/02/adding-gesture-control-to-xcode-opengl.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/627201247416879277/posts/default/4462617947755514632'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/627201247416879277/posts/default/4462617947755514632'/><link rel='alternate' type='text/html' href='http://www.headnoodles.com/2012/02/adding-gesture-control-to-xcode-opengl.html' title='Rude Gestures'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04188436224275642399</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCM7NjPo2siaUb551MuqUII_CSJNhdm27RNl9sWeG1YzQFQ_7Qfnsca_6LP7r4VvhnCkPcTZJUoHHam-7_7As7U0m1waWg_6v9lVx5ZsHmkj57gf6lCQPQlCyG5P1yj3dvDogMOoRsPvVR/s72-c/Screen+Shot+2012-02-20+at+4.11.06+AM.png" height="72" width="72"/><thr:total>0</thr:total></entry></feed>