Drawing Circle with OpenGL

后端 未结 6 1624
时光取名叫无心
时光取名叫无心 2020-12-31 01:46

I\'m trying to draw simple circle with C++/OpenGl

my code is:

#include 
#include 

void Draw() {
    glClear(GL_COLOR_         


        
6条回答
  •  醉酒成梦
    2020-12-31 02:18

    Here is a code to draw a fill elipse, you can use the same method but replacing de xcenter and y center with radius

    void drawFilledelipse(GLfloat x, GLfloat y, GLfloat xcenter,GLfloat ycenter) {
        int i;
        int triangleAmount = 20; //# of triangles used to draw circle
    
        //GLfloat radius = 0.8f; //radius
        GLfloat twicePi = 2.0f * PI;
    
        glBegin(GL_TRIANGLE_FAN);
        glVertex2f(x, y); // center of circle
        for (i = 0; i <= triangleAmount; i++) {
            glVertex2f(
                x + ((xcenter+1)* cos(i * twicePi / triangleAmount)),
                y + ((ycenter-1)* sin(i * twicePi / triangleAmount))
            );
        }
        glEnd();
    }
    

提交回复
热议问题