Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9031141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:39:25+00:00 2026-06-16T07:39:25+00:00

I want to draw using OpenGL library a Ring with sectors, each one with

  • 0

I want to draw using OpenGL library a Ring with sectors, each one with a different color.
To draw a ring i know i can use gluDisk(gluNewQuadric(), 0, 1.5, 32, 100);

But to draw the sectors or zones in different colors i think i need to use a manual way using GL_TRIANGLE_FAN or something similar.

I try it in that way, but the output is not so accurate to a ring.

const float DEG2RAD = 3.14159/180;

glBegin( GL_TRIANGLE_FAN );
        for( int i = 0; i <= 90; i++ )
        {
           float degInRad = i*DEG2RAD;
           glVertex2f(x, y); // point of the inner circle of the ring

           for( int n = 0; n <= 4; n++ ) 
           {
              float const t = = i*DEG2RAD*(n/4);
              glVertex2f(x + sin(t)*r, y + cos(t)*r);  // points of the outer circle.
           }
        }
glEnd();

The idea was following this diagram of how GL_TRIANGLE_FAN works, take 4 points in the outer circle for each point calculated in the inner circle. Because the outer circle is longer than the inner circle. That’s the reason of a loop into another loop.

Types of OpenGL drawings

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:39:26+00:00Added an answer on June 16, 2026 at 7:39 am

    Your code references “inner circle” and “outer circle”, but all you have is a single center point (x,y), and your outer circle points will be all over the place as your angle calculation doesn’t make a lot of sense (you calculate one value in the outer loop, which isn’t used anywhere, and then just kind of multiply everything together in the inner loop, with a divide-by-4 for good measure… that’s not going to give you nice points in a circle).

    In any event, you can’t use a single triangle fan to draw a ring, because all the triangles in the fan must connect to a single point. There’s no magic way to restart the fan at a different point, you just have to glEnd() and start a new one. This won’t work well for proceeding around a ring, as you’ll leave gaps. Triangle-fans are generally one of the least useful of the classic GL primitives.

    I understand you’re trying to use less points in the smaller circle, but honestly I can’t see that it’s worthwhile.

    Your best bet would be to use a triangle-strip instead, with a single loop around your circle, putting in both an inside and an outside vertex every time.

    Pseudo-code for a segment:

    glBegin(GL_TRIANGLE_STRIP);
    for(angle = start_angle; angle < end_angle ; angle += small_increment)
    {
        s = sin(angle); c = cos(angle);
        glVertex2f( x + c * r1, y + s * r1);
        glVertex2f( x + c * r2, y + s * r2);
    }
    glEnd();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to draw an arc using canvas using a gradient fill. How can
I am using OpenGL ES 2.0 and GLSL to draw objects. Then I want
How can I draw 2d text using openGL and Allegro 5 in C++? I
I'm trying to draw two objects using two different textures with one shader program
I draw several 2D shapes using OpenGL and now I want to add the
I want to draw using gldrawarray in opengl es with a vertex array of
I want to draw many spheres (~100k) using OpenGL. So far, I'm doing something
I want to draw text with OpenGL using FreeType and to make it sharper,
I am learning OpenGL 4.0 and I want to draw a simple triangle using
I want to draw a rectangle using OPENGL in Android... Just a simple rectangle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.