How do i implement a circle filling algorithm in opengl?

后端 未结 2 1593
感情败类
感情败类 2020-12-21 12:41

It should be of the form circle(float xcenter, float ycenter, float radius).

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-21 13:11

    There's a gluDisk, but it has a somewhat different signature than you've given. It always centers the disk on the origin, and expects you to use glTranslate if that's not where you want your disk. It's also a bit more versatile in other ways -- the disk it draws can have a hole in the center, which you (apparently) don't care about, as well as a "loops" parameter to draw more than one disk at a time. That makes adapting it to what you've asked for just a bit more work than you'd like:

    void circle(float xcenter, float ycenter, float radius) {
        GLUquadric* quad = gluNewQuadric();
    
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();
        glTranslatef(xcenter, ycenter);
    
        gluDisk(quad, 0, radius, 256, 1);
        glPopMatrix();
        gluDeleteQuadric(quad);
    }
    

    I'd say this is right at the point that it's open to question whether it's easier to just do like @genpfault said, and draw a circular triangle-fan yourself.

提交回复
热议问题