Drawing Circle with OpenGL

后端 未结 6 1628
时光取名叫无心
时光取名叫无心 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条回答
  •  猫巷女王i
    2020-12-31 02:18

    We will find the value of X and Y from this image. We know, sinθ=vertical/hypotenuse and cosθ=base/hypotenuse from the image we can say X=base and Y=vertical. Now we can write X=hypotenuse * cosθ and Y=hypotenuse * sinθ.

    Now look at this code

    void display(){
    float x,y;
    glColor3f(1, 1, 0);
    for(double i =0; i <= 360;){
        glBegin(GL_TRIANGLES);
        x=5*cos(i);
        y=5*sin(i);
        glVertex2d(x, y);
        i=i+.5;
        x=5*cos(i);
        y=5*sin(i);
        glVertex2d(x, y);
        glVertex2d(0, 0);
        glEnd();
        i=i+.5;
    }
    glEnd();
    
    glutSwapBuffers();
    }
    

提交回复
热议问题