Skip to main content
Removing second question about indexed vs fan vs strip and explaining UV sphere term.
Source Link
DMGregory
  • 140.9k
  • 23
  • 258
  • 401

I am trying to implement a class Sphere in C++.

Therefore I want to calculate the vertices in the constructor of the class (or in a seperate function..). Although I read tons of articles about creating spheres in different ways (UV Sphere, Quad Sphere, Icosphere etc.) I did not understand how to create the vertices for my buffer object.

I decided to use the UV Sphere since it is easy to map a texture on it.

A "UV sphere" in this sense is one where the (quad) edges run like lines of latitude and longitude, and the texture is mapped to the sphere like an equirectangular projection.

Example of a UV sphere and its texture
(Equirectangular Earth texture by Strebe via Wikimedia Commons, CC BY-SA 3.0)

But how can I calculate all the vertices? Do I have to / Should I use indices? Is it better to use the drawing method with GL_TRIANGLE_STRIP or GL_TRIANGLE_FAN? Or is it just a matter of tastevertex positions and texture coordinates?

For my vertices I use a Vertex struct:

struct Vertex
{
    glm::vec3 position;
    glm::vec2 texture;
};

I am trying to implement a class Sphere in C++.

Therefore I want to calculate the vertices in the constructor of the class (or in a seperate function..). Although I read tons of articles about creating spheres in different ways (UV Sphere, Quad Sphere, Icosphere etc.) I did not understand how to create the vertices for my buffer object.

I decided to use the UV Sphere since it is easy to map a texture on it.

But how can I calculate all the vertices? Do I have to / Should I use indices? Is it better to use the drawing method with GL_TRIANGLE_STRIP or GL_TRIANGLE_FAN? Or is it just a matter of taste?

For my vertices I use a Vertex struct:

struct Vertex
{
    glm::vec3 position;
    glm::vec2 texture;
};

I am trying to implement a class Sphere in C++.

Therefore I want to calculate the vertices in the constructor of the class (or in a seperate function..). Although I read tons of articles about creating spheres in different ways (UV Sphere, Quad Sphere, Icosphere etc.) I did not understand how to create the vertices for my buffer object.

I decided to use the UV Sphere since it is easy to map a texture on it.

A "UV sphere" in this sense is one where the (quad) edges run like lines of latitude and longitude, and the texture is mapped to the sphere like an equirectangular projection.

Example of a UV sphere and its texture
(Equirectangular Earth texture by Strebe via Wikimedia Commons, CC BY-SA 3.0)

But how can I calculate all the vertex positions and texture coordinates?

For my vertices I use a Vertex struct:

struct Vertex
{
    glm::vec3 position;
    glm::vec2 texture;
};
Source Link
linux_lover
  • 147
  • 1
  • 3
  • 6

OpenGL calculate UV sphere vertices

I am trying to implement a class Sphere in C++.

Therefore I want to calculate the vertices in the constructor of the class (or in a seperate function..). Although I read tons of articles about creating spheres in different ways (UV Sphere, Quad Sphere, Icosphere etc.) I did not understand how to create the vertices for my buffer object.

I decided to use the UV Sphere since it is easy to map a texture on it.

But how can I calculate all the vertices? Do I have to / Should I use indices? Is it better to use the drawing method with GL_TRIANGLE_STRIP or GL_TRIANGLE_FAN? Or is it just a matter of taste?

For my vertices I use a Vertex struct:

struct Vertex
{
    glm::vec3 position;
    glm::vec2 texture;
};