How can i wrap the earth image around a 3D Sphere using OpenGL, GLFW, GLAD, GLM?

Computer Graphics Asked by b_cass_ on August 27, 2021

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 “” tutorials.i know how to create triangles and 3d rotational cube.

2 Answers

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.

Answered by Trantor on August 27, 2021

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.

Answered by gallickgunner on August 27, 2021

Add your own answers!

Related Questions

BRDF for point lights should not return values over 1

1  Asked on August 27, 2021 by emil-kabirov


Dynamic Array in GLSL

3  Asked on January 13, 2021 by archmede


Combine box shadow with a signed distance field

0  Asked on January 2, 2021 by weichsem


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP