<p>I'm not going to post proper working code here just giving you a guideline. There might be an easier way but what I did back in my days was to create a sphere using Triangle Strips. There is an icosahedron approach as well but I haven't looked into that.</p>

<p>So first of all look up on <code>GL_TRIANGLE_STRIPS</code> and how they work. Secondly you need to look up on Spherical coordinates and how to convert them to Cartesian Coordinates.</p>

<p>A brief overview is that Spherical coordinates have parameters (radius, zenith, azimuth). Radius is pretty much self explanatory. Zenith angle is the inclination angle from the pole of the sphere (lines of longitude) While the Azimuth angle runs along the latitude. Zenith runs from <code>0-PI</code> (assuming 0 starts from 1 pole and PI is the second pole) or <code>-PI/2 - PI/2</code> (assuming the extreme at both poles and 0 is the center) and Azimuth from <code>0-2PI</code> (all the way around the sphere).</p>

<p>Now after that you can think of the sphere forming up from concentric Rings. At each fraction of the Zenith angle there is ring that runs around the sphere (the latitude lines). Then you create triangle strips between those rings to fill the sphere up.</p>

<p>So basically you want something like,</p>

<pre><code>zenith = azimuth = 0
ring_increment = PI/num_rings;
sector_inrement = 2PI/num_sectors;

for(i=0; i &lt; PI; i+= ring_increment)
{
    for(j=0; j &lt; 2PI; j+= sector_increment)
    {
        vertex_list.add(convertToCartesianCoord(radius, zenith, azimuth))
        zenith += ring_increment
        vertex_list.add(convertToCartesianCoord(radius, zenith, azimuth))
        zenith -= ring_increment
    }
}
</code></pre>

<p>The more the number of rings and the number of sectors the smoother the sphere will be.</p>

CC BY-SA 4.0
2019-08-04T23:49:36.090Z
2019-08-04T23:49:36.090Z
gallickgunner
<p>Build a hexahedron from 6 triangles(!), setting its 2 vertices at the poles of the sphere, and the other 3 vertices equally around the equator. Then iteratively or recursively subdivide all triangles, projecting the new vertices at the sphere surface (!). Triangle subdivision can be done by replacing an original triangle by 4 new ones, adding new vertices in the middle of all 3 edges and in the middle of the original triangle.</p>

CC BY-SA 4.0
2020-01-12T21:31:16.000Z
2020-01-12T21:31:16.000Z
Trantor
<p>Please help me out with this thing and currently i am a little more than a beginner so please tell me in that context. i don't need any obsolete methods for creating this like using GLUT or GLEW.can you just tell me its algorithm to create the outline of it(like using icosphere or triangles) and how and where in the whole program do i implement this algorithm. currently i am referring the "learnopengl.com" tutorials.i know how to create triangles and 3d rotational cube.   </p>

<opengl><3d><transformations><algorithm><glm>
How can i wrap the earth image around a 3D Sphere using OpenGL, GLFW, GLAD, GLM?
bhagya731
# How can i wrap the earth image around a 3D Sphere using OpenGL, GLFW, GLAD, GLM?

(Asked by: username_0 on 2019-08-04)

Please help me out with this thing and currently i am a little more than a beginner so please tell me in that context. i don't need any obsolete methods for creating this like using GLUT or GLEW.can you just tell me its algorithm to create the outline of it(like using icosphere or triangles) and how and where in the whole program do i implement this algorithm. currently i am referring the "learnopengl.com" tutorials.i know how to create triangles and 3d rotational cube.

**Tags:** opengl, 3d, transformations, algorithm, glm


---

## 2 answers

### Answer by username_1 on 2019-08-04. Score: 0 | Accepted answer

I'm not going to post proper working code here just giving you a guideline. There might be an easier way but what I did back in my days was to create a sphere using Triangle Strips. There is an icosahedron approach as well but I haven't looked into that.

So first of all look up on `GL_TRIANGLE_STRIPS` and how they work. Secondly you need to look up on Spherical coordinates and how to convert them to Cartesian Coordinates.

A brief overview is that Spherical coordinates have parameters (radius, zenith, azimuth). Radius is pretty much self explanatory. Zenith angle is the inclination angle from the pole of the sphere (lines of longitude) While the Azimuth angle runs along the latitude. Zenith runs from `0-PI` (assuming 0 starts from 1 pole and PI is the second pole) or `-PI/2 - PI/2` (assuming the extreme at both poles and 0 is the center) and Azimuth from `0-2PI` (all the way around the sphere).

Now after that you can think of the sphere forming up from concentric Rings. At each fraction of the Zenith angle there is ring that runs around the sphere (the latitude lines). Then you create triangle strips between those rings to fill the sphere up.

So basically you want something like,

```
zenith = azimuth = 0
ring_increment = PI/num_rings;
sector_inrement = 2PI/num_sectors;

for(i=0; i < PI; i+= ring_increment)
{
    for(j=0; j < 2PI; j+= sector_increment)
    {
        vertex_list.add(convertToCartesianCoord(radius, zenith, azimuth))
        zenith += ring_increment
        vertex_list.add(convertToCartesianCoord(radius, zenith, azimuth))
        zenith -= ring_increment
    }
}

```

The more the number of rings and the number of sectors the smoother the sphere will be.


---

### Answer by username_2 on 2020-01-12. Score: 0

Build a hexahedron from 6 triangles(!), setting its 2 vertices at the poles of the sphere, and the other 3 vertices equally around the equator. Then iteratively or recursively subdivide all triangles, projecting the new vertices at the sphere surface (!). Triangle subdivision can be done by replacing an original triangle by 4 new ones, adding new vertices in the middle of all 3 edges and in the middle of the original triangle.


---

