CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Drawing a Circle in OpenGL

  1. #1
    Join Date
    Aug 2009

    Drawing a Circle in OpenGL

    Hi all, I am trying to draw a simple circle using OpenGL and C++

    I am just getting started coding OpenGL.

    I got the following code to draw the circle:

    void drawCircle(float cx, float cy, float r, int num_segments)
    for(int ii = 0; ii < num_segments; ii++)
    float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle

    float x = r * cosf(theta);//calculate the x component
    float y = r * sinf(theta);//calculate the y component

    glVertex2f(x + cx, y + cy);//output vertex


    Now in a separate function I am trying to call the drawCircle functions as follows in order to get the circle to appear:


    However, I see no circle. Could somebody point me in the right direction of what I am doing wrong? Thanks!

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Seattle, WA

    Re: Drawing a Circle in OpenGL

    The code you've posted is fine if you're looking to draw a black circle of radius 10 with the origin at 0,0.

    Potential issues include:
    -What color is the background? Have you cleared the color buffer to this color?
    -Do you have a depth buffer? If so, is it cleared or is depth testing disabled?
    -Do you have a double-buffered context? If so, have you swapped the buffers after drawing?
    -Do you have a context *at all*? Try printing out the result of glGetString(GL_EXTENSIONS) to see. If something comes out, you do.
    -Are you able to clear the window to various colors and observe the results?
    -Is your modelview matrix set up properly (normally the identity)?
    -Is your projection matrix set up properly (for this, normally orthographic)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)