0

I want draw a sphere using for loop (I want to draw a sphere instead of circle please help)

void drawCircle(double x, double y, double r)
{
    glColor3f(nodeBGClolor.r, nodeBGClolor.g, nodeBGClolor.b);
    int iterations = 500;
    glBegin(GL_POLYGON);
    for (int i = 0; i < iterations; i++)
    {
        double currX = r * cos(2 * PI * (i / (iterations * 1.0)));
        double currY = r * sin(2 * PI * (i / (iterations * 1.0)));
        glVertex2f(x + currX, y + currY);
    }
    glEnd();
}
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • you have `glVertex2f` instead of `glVertex3f` and computing `x,y ` from parametrical circle equation instead of having 2 nested for loops (long,lat) and using spherical to cartesian coordinates conversion to compute `x,y,z` ... also you need to change primitive ... for more info see [draw sphere in OpenGL 4.0](https://stackoverflow.com/a/43112347/2521214) and [sphere triangulation by subdivision](https://stackoverflow.com/a/29139125/2521214) and [Applying map of the earth texture a Sphere](https://stackoverflow.com/a/31804515/2521214). Also do not forget to have 3D camera instead of 2D ... – Spektre May 21 '20 at 13:14
  • ... another resource [Sphere Calculations](https://stackoverflow.com/questions/49080505/sphere-calculations/49081855?noredirect=1) – Rabbid76 May 21 '20 at 18:33

0 Answers0