Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: How to change the position of a circle?

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2013
    Posts
    5

    How to change the position of a circle?

    Hi guys Iam new to OpenGL. Iam trying to create a small circle and would like to position it in the bottom-left corner of the screen. The code below draws a massive circle. Could you please tell me how to change the size of the circle and the position of it to a specific place on the window.

    Thanks


    Code :
     
    #define PI 3.1415926535898
    GLint circle_points =100;
     
    void Circle()
    {
     
        glClear(GL_COLOR_BUFFER_BIT);
        double angle = 2*  PI/circle_points ;
     
        glBegin(GL_LINE_LOOP);
            double angle1=0.0;
            glVertex2d( cos(0.0) , sin(0.0));
            int i;
            for ( i=0 ; i< circle_points ;i++)
            {
                printf( "angle = %f \n" , angle1);
                glVertex2d(cos(angle1),sin(angle1));
                angle1 += angle ;
            }
        glEnd();
        glFlush();
    }

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,097
    The function you need is gltranslate (or just add a offset to each of youR points).

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2013
    Posts
    5
    Where do I add the gltranslate inside the void Circle() or outside?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,097
    Normally outside that way you can draw several circles at different locations. (Remember to use glPushMatrix and glPopMatrix to save and restore the untranslated coordinate system) Also move your clear outside.

Posting Permissions

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