Archive Pages Design$type=blogging

How to Draw Circle in OpenGL

In the OpenGL Computer graphics there major problem in drawing circle. In this post we are going t...

In the OpenGL Computer graphics there major problem in drawing circle. In this post we are going to study How to Draw Circle in OpenGL. There is no primitive functions like of lines, points, triangles and other polygons for circle, hence drawing a circle need some new method/function from our side. we are going to learn that today.

There are many methods of Drawing circle in OpenGL, we going to discuss one by one each of them. 

First Method - using the indefinite points 

This method used the no of of point to draw a circle. The problem with this method is you need more precession as we use the sine and cosine function with the value of pie as 3.14159, So little error may in the round circle. Put the following code in a simple display function and run the program for your circle. See the Image it's output - 

glBegin(GL_POINTS);
 for(int i=0;i<1000;++i)
  {
  glVertex3f(cos(2*3.14159*i/1000.0),sin(2*3.14159*i/1000.0),0);
  }
 glEnd();

draw circle opengl - using points

Second Method - using the lines 

As Like above program circles can be created using the small sets of lines.We used the bunch of lines, which are closed together to go round forming a circle. For drawing circle in opengl, this method also used the simple sine and cosine maths functions, but we have not used pie instead go for degree for angles.

typedef struct
{
float x;
float y;
}CIRCLE;

CIRCLE circle;

void createcircle (int k, int r, int h) {
    glBegin(GL_LINES);
    for (int i = 0; i < 180; i++)
    {
    circle.x = r * cos(i) - h;
    circle.y = r * sin(i) + k;
    glVertex3f(circle.x + k,circle.y - h,0);
    
    circle.x = r * cos(i + 0.1) - h;
    circle.y = r * sin(i + 0.1) + k;
    glVertex3f(circle.x + k,circle.y - h,0);
    }
    glEnd();
}

If you know about the structures in C then fine you understand the typedef else we have more object oriented approach making use of classes for C++. Same program above in classes.

class circle{
public : float x,y,rot;

public:
void createcircle (int k, int r, int h);

};
void circle::createcircle (int k, int r, int h) {
  glBegin(GL_LINES);
    for (int i = 0; i < 180; i++)
    {
    x = r * cos(i) - h;
    y = r * sin(i) + k;
    glVertex3f(x + k,y - h,0);
    
    x = r * cos(i + 0.1) - h;
    y = r * sin(i + 0.1) + k;
    glVertex3f(x + k,y - h,0);
    }
    glEnd();
}


COMMENTS

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero DSAV Escapa First Come First Serve Fluids Font Demo Games Gear Motion GlutDino Glutplane Graphics Editor iOS iPhone Java Java OpenGL Graphics Programming Light Torus Linked List Ludo Board Game Mancala board games Memory blocks game Memory Game Menu Mickey Mouse Minesweeper Miniature Steam Engine moth Motion Blur MoveLight moving car Moving Ship Multiplex Networking Based Project Nuclear Power Plant Olympic opengl c++ examples OpenGL ES OpenGL Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Random Flowing lines Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Sphere Spot Light Swing Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation Tutorial water ripple effects Whirlpool
false
ltr
item
OpenGL Projects: How to Draw Circle in OpenGL
How to Draw Circle in OpenGL
http://2.bp.blogspot.com/-cnVEg19-RfA/UybjT_sxO1I/AAAAAAAAGDo/NRo6R4-NlRk/s1600/draw+circle+opengl+-+using+points.JPG
http://2.bp.blogspot.com/-cnVEg19-RfA/UybjT_sxO1I/AAAAAAAAGDo/NRo6R4-NlRk/s72-c/draw+circle+opengl+-+using+points.JPG
OpenGL Projects
http://www.openglprojects.in/2014/03/draw-circle-opengl.html
http://www.openglprojects.in/
http://www.openglprojects.in/
http://www.openglprojects.in/2014/03/draw-circle-opengl.html
true
2020194800836807725
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago