<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 31. OpenGL Sphere Creation</title>
	<atom:link href="http://www.swiftless.com/tutorials/opengl/sphere.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.swiftless.com/tutorials/opengl/sphere.html</link>
	<description>Game Programming and Computer Graphics Tutorials</description>
	<lastBuildDate>Wed, 01 Feb 2012 09:19:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Lukasz</title>
		<link>http://www.swiftless.com/tutorials/opengl/sphere.html/comment-page-1#comment-4104</link>
		<dc:creator>Lukasz</dc:creator>
		<pubDate>Mon, 02 Jan 2012 22:45:17 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=208#comment-4104</guid>
		<description>Impressive code! Took me just 5 minutes to compile with old version of lcc (had to switch the order of including windows.h and gl.h, a faq-ish issue), and it works great. Thanks a lot!</description>
		<content:encoded><![CDATA[<p>Impressive code! Took me just 5 minutes to compile with old version of lcc (had to switch the order of including windows.h and gl.h, a faq-ish issue), and it works great. Thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sharon</title>
		<link>http://www.swiftless.com/tutorials/opengl/sphere.html/comment-page-1#comment-3594</link>
		<dc:creator>Sharon</dc:creator>
		<pubDate>Fri, 09 Dec 2011 10:08:43 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=208#comment-3594</guid>
		<description>I have problem with the code.. 
i see alot of noises while the roitation...
myebe you know the reason</description>
		<content:encoded><![CDATA[<p>I have problem with the code..<br />
i see alot of noises while the roitation&#8230;<br />
myebe you know the reason</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dhruvil vyas</title>
		<link>http://www.swiftless.com/tutorials/opengl/sphere.html/comment-page-1#comment-3383</link>
		<dc:creator>dhruvil vyas</dc:creator>
		<pubDate>Mon, 28 Nov 2011 04:21:23 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=208#comment-3383</guid>
		<description>hey swiftless,
 thanks for your tutorial .. but now i want to calculate normals for each vertex as i want to implement proper lighting and shading effects ... can you give some light on which coordinates to calculate normal on ??</description>
		<content:encoded><![CDATA[<p>hey swiftless,<br />
 thanks for your tutorial .. but now i want to calculate normals for each vertex as i want to implement proper lighting and shading effects &#8230; can you give some light on which coordinates to calculate normal on ??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Rogers</title>
		<link>http://www.swiftless.com/tutorials/opengl/sphere.html/comment-page-1#comment-2618</link>
		<dc:creator>Steve Rogers</dc:creator>
		<pubDate>Wed, 26 Oct 2011 05:53:24 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=208#comment-2618</guid>
		<description>You&#039;re a legend. God bless you.</description>
		<content:encoded><![CDATA[<p>You&#8217;re a legend. God bless you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michael stowell</title>
		<link>http://www.swiftless.com/tutorials/opengl/sphere.html/comment-page-1#comment-2588</link>
		<dc:creator>michael stowell</dc:creator>
		<pubDate>Fri, 21 Oct 2011 06:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=208#comment-2588</guid>
		<description>I ported this to android opengl es in java, i expect there are bugs and missing function calls due to it being inherited from my mesh object, but you should be able to get the jist. 

initially it only drew half a sphere, changing 90 to 180 fixed this, but im not sure if this is correct, if anyone could correct me on this i would be very greatful!!

public class Sphere extends mesh {
	
	double PI = 3.1415926535897;
	int space = 10;
	int VertexCount = (180 / space) * (360 / space) * 4;
	
	private FloatBuffer vertexBuffer = null;
	private FloatBuffer textureBuffer = null;
	
	public Sphere(float R, float H, float K, float Z) {
		
		ByteBuffer vbb = ByteBuffer.allocateDirect(VertexCount * 3 * 4);
		vbb.order(ByteOrder.nativeOrder());
		vertexBuffer = vbb.asFloatBuffer();
		
		ByteBuffer byteBuf = ByteBuffer.allocateDirect(VertexCount * 2 * 4);
		byteBuf.order(ByteOrder.nativeOrder());
		textureBuffer = byteBuf.asFloatBuffer();
		
		int n;
		double a;
		double b;  
		n = 0;
		
		for( b = 0; b &lt;= 180 - space; b+=space){
			 for( a = 0; a &lt;= 360 - space; a+=space){
				 vertexBuffer.put((float)(R * Math.sin((a) / 180 * PI) * Math.sin((b) / 180 * PI) - H));          
				 vertexBuffer.put((float)(R * Math.cos((a) / 180 * PI) * Math.sin((b) / 180 * PI) + K));            
				 vertexBuffer.put((float)(R * Math.cos((b) / 180 * PI) - Z));
				 textureBuffer.put((float) ((a) / 360));
				 textureBuffer.put((float) ((2 * b) / 360));
				 
				 
				 vertexBuffer.put((float)(R * Math.sin((a) / 180 * PI) * Math.sin((b + space) / 180 * PI) - H));			             
				 vertexBuffer.put((float)(R * Math.cos((a) / 180 * PI) * Math.sin((b + space) / 180 * PI ) + K));
				 vertexBuffer.put((float)(R * Math.cos((b + space) / 180 * PI) - Z));    
				 textureBuffer.put((float) ((a) / 360));
				 textureBuffer.put((float) ((2 * (b + space)) / 360));
				 
				 
				 vertexBuffer.put((float)(R * Math.sin((a + space) / 180 * PI) * Math.sin((b) / 180 * PI) - H));	             
				 vertexBuffer.put((float)(R * Math.cos((a + space) / 180 * PI) * Math.sin((b) / 180 * PI) + K));	             
				 vertexBuffer.put((float)(R * Math.cos((b) / 180 * PI) - Z));
				 textureBuffer.put((float) ((a + space) / 360));
				 textureBuffer.put((float) ((2 * b) / 360));
						             			             
				 vertexBuffer.put((float)(R * Math.sin((a + space) / 180 * PI) * Math.sin((b + space) / 180 * PI) - H));		             
				 vertexBuffer.put((float)(R * Math.cos((a + space) / 180 * PI) * Math.sin((b + space) / 180 * PI) + K));             
				 vertexBuffer.put((float)(R * Math.cos((b + space) / 180 * PI) - Z));  
				 textureBuffer.put((float) ((a + space) / 360));
				 textureBuffer.put((float) ((2 * (b + space)) / 360));     
			 }
		}
		vertexBuffer.position(0);
		textureBuffer.position(0);
	}
	
	public void draw(GL10 gl) {
        gl.glFrontFace(GL10.GL_CW);
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
        
        if (m_should_load_texture) {
			loadGLTexture(gl);
			m_should_load_texture = false;
		}
        if (m_texture_id != -1 &amp;&amp; textureBuffer != null) {
			gl.glEnable(GL10.GL_TEXTURE_2D);
			// Enable the texture state
			gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

			// Point to our buffers
			gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, m_texture_id);
		}
        
        gl.glTranslatef(x, y, z);
		gl.glRotatef(rx, 1, 0, 0);
		gl.glRotatef(ry, 0, 1, 0);
		gl.glRotatef(rz, 0, 0, 1);
        
       // gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, VertexCount);
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    }

		
}</description>
		<content:encoded><![CDATA[<p>I ported this to android opengl es in java, i expect there are bugs and missing function calls due to it being inherited from my mesh object, but you should be able to get the jist. </p>
<p>initially it only drew half a sphere, changing 90 to 180 fixed this, but im not sure if this is correct, if anyone could correct me on this i would be very greatful!!</p>
<p>public class Sphere extends mesh {</p>
<p>	double PI = 3.1415926535897;<br />
	int space = 10;<br />
	int VertexCount = (180 / space) * (360 / space) * 4;</p>
<p>	private FloatBuffer vertexBuffer = null;<br />
	private FloatBuffer textureBuffer = null;</p>
<p>	public Sphere(float R, float H, float K, float Z) {</p>
<p>		ByteBuffer vbb = ByteBuffer.allocateDirect(VertexCount * 3 * 4);<br />
		vbb.order(ByteOrder.nativeOrder());<br />
		vertexBuffer = vbb.asFloatBuffer();</p>
<p>		ByteBuffer byteBuf = ByteBuffer.allocateDirect(VertexCount * 2 * 4);<br />
		byteBuf.order(ByteOrder.nativeOrder());<br />
		textureBuffer = byteBuf.asFloatBuffer();</p>
<p>		int n;<br />
		double a;<br />
		double b;<br />
		n = 0;</p>
<p>		for( b = 0; b &lt;= 180 &#8211; space; b+=space){<br />
			 for( a = 0; a &lt;= 360 &#8211; space; a+=space){<br />
				 vertexBuffer.put((float)(R * Math.sin((a) / 180 * PI) * Math.sin((b) / 180 * PI) &#8211; H));<br />
				 vertexBuffer.put((float)(R * Math.cos((a) / 180 * PI) * Math.sin((b) / 180 * PI) + K));<br />
				 vertexBuffer.put((float)(R * Math.cos((b) / 180 * PI) &#8211; Z));<br />
				 textureBuffer.put((float) ((a) / 360));<br />
				 textureBuffer.put((float) ((2 * b) / 360));</p>
<p>				 vertexBuffer.put((float)(R * Math.sin((a) / 180 * PI) * Math.sin((b + space) / 180 * PI) &#8211; H));<br />
				 vertexBuffer.put((float)(R * Math.cos((a) / 180 * PI) * Math.sin((b + space) / 180 * PI ) + K));<br />
				 vertexBuffer.put((float)(R * Math.cos((b + space) / 180 * PI) &#8211; Z));<br />
				 textureBuffer.put((float) ((a) / 360));<br />
				 textureBuffer.put((float) ((2 * (b + space)) / 360));</p>
<p>				 vertexBuffer.put((float)(R * Math.sin((a + space) / 180 * PI) * Math.sin((b) / 180 * PI) &#8211; H));<br />
				 vertexBuffer.put((float)(R * Math.cos((a + space) / 180 * PI) * Math.sin((b) / 180 * PI) + K));<br />
				 vertexBuffer.put((float)(R * Math.cos((b) / 180 * PI) &#8211; Z));<br />
				 textureBuffer.put((float) ((a + space) / 360));<br />
				 textureBuffer.put((float) ((2 * b) / 360));</p>
<p>				 vertexBuffer.put((float)(R * Math.sin((a + space) / 180 * PI) * Math.sin((b + space) / 180 * PI) &#8211; H));<br />
				 vertexBuffer.put((float)(R * Math.cos((a + space) / 180 * PI) * Math.sin((b + space) / 180 * PI) + K));<br />
				 vertexBuffer.put((float)(R * Math.cos((b + space) / 180 * PI) &#8211; Z));<br />
				 textureBuffer.put((float) ((a + space) / 360));<br />
				 textureBuffer.put((float) ((2 * (b + space)) / 360));<br />
			 }<br />
		}<br />
		vertexBuffer.position(0);<br />
		textureBuffer.position(0);<br />
	}</p>
<p>	public void draw(GL10 gl) {<br />
        gl.glFrontFace(GL10.GL_CW);<br />
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);<br />
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);</p>
<p>        if (m_should_load_texture) {<br />
			loadGLTexture(gl);<br />
			m_should_load_texture = false;<br />
		}<br />
        if (m_texture_id != -1 &amp;&amp; textureBuffer != null) {<br />
			gl.glEnable(GL10.GL_TEXTURE_2D);<br />
			// Enable the texture state<br />
			gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);</p>
<p>			// Point to our buffers<br />
			gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);<br />
			gl.glBindTexture(GL10.GL_TEXTURE_2D, m_texture_id);<br />
		}</p>
<p>        gl.glTranslatef(x, y, z);<br />
		gl.glRotatef(rx, 1, 0, 0);<br />
		gl.glRotatef(ry, 0, 1, 0);<br />
		gl.glRotatef(rz, 0, 0, 1);</p>
<p>       // gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);<br />
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, VertexCount);<br />
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);<br />
    }</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ranger_x3</title>
		<link>http://www.swiftless.com/tutorials/opengl/sphere.html/comment-page-1#comment-2422</link>
		<dc:creator>ranger_x3</dc:creator>
		<pubDate>Wed, 28 Sep 2011 00:30:56 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=208#comment-2422</guid>
		<description>Thank you for the code. Took less than 5 minutes to get it working in my program including adding in the normals, not that they really took much effort either. Just what I needed so I could continue working with my project on noise textures.</description>
		<content:encoded><![CDATA[<p>Thank you for the code. Took less than 5 minutes to get it working in my program including adding in the normals, not that they really took much effort either. Just what I needed so I could continue working with my project on noise textures.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilan</title>
		<link>http://www.swiftless.com/tutorials/opengl/sphere.html/comment-page-1#comment-2411</link>
		<dc:creator>Ilan</dc:creator>
		<pubDate>Mon, 26 Sep 2011 03:24:10 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=208#comment-2411</guid>
		<description>Holy shit. Thanks a lot.

Other then a few compile errors, it runs beautifully.</description>
		<content:encoded><![CDATA[<p>Holy shit. Thanks a lot.</p>
<p>Other then a few compile errors, it runs beautifully.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Swiftless</title>
		<link>http://www.swiftless.com/tutorials/opengl/sphere.html/comment-page-1#comment-2350</link>
		<dc:creator>Swiftless</dc:creator>
		<pubDate>Mon, 19 Sep 2011 11:05:40 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=208#comment-2350</guid>
		<description>Hi Milano,

I&#039;d suggest taking a look at the OpenGL 4.x tutorials as they also can&#039;t use the glVertex3f method. OpenGL ES and OpenGL 4.x have quite a few similarities.

Thanks,
Swiftless</description>
		<content:encoded><![CDATA[<p>Hi Milano,</p>
<p>I&#8217;d suggest taking a look at the OpenGL 4.x tutorials as they also can&#8217;t use the glVertex3f method. OpenGL ES and OpenGL 4.x have quite a few similarities.</p>
<p>Thanks,<br />
Swiftless</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: milano</title>
		<link>http://www.swiftless.com/tutorials/opengl/sphere.html/comment-page-1#comment-2301</link>
		<dc:creator>milano</dc:creator>
		<pubDate>Fri, 16 Sep 2011 11:14:07 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=208#comment-2301</guid>
		<description>how i can show a sphere in Iphone? As you know in ios there is no function as glVertices3f</description>
		<content:encoded><![CDATA[<p>how i can show a sphere in Iphone? As you know in ios there is no function as glVertices3f</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sam</title>
		<link>http://www.swiftless.com/tutorials/opengl/sphere.html/comment-page-1#comment-1888</link>
		<dc:creator>sam</dc:creator>
		<pubDate>Wed, 06 Jul 2011 03:46:16 +0000</pubDate>
		<guid isPermaLink="false">http://swiftless.com/wordpress/?p=208#comment-1888</guid>
		<description>Thanks for your great code! Very clean and clear. I realized the mapping theory through your code. Thousand thx!</description>
		<content:encoded><![CDATA[<p>Thanks for your great code! Very clean and clear. I realized the mapping theory through your code. Thousand thx!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

