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,117
    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,117
    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.

Similar Threads

  1. OpenGL rotate circle from its position
    By jamesK in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-20-2016, 04:54 PM
  2. How to resize and position a circle
    By KSM888 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-12-2014, 10:53 PM
  3. Change eye position of gluLookAt() doesn't work
    By jiaoyang_28 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-15-2012, 03:21 PM
  4. change camera position via modelview matrix
    By kreyszig in forum OpenGL: General
    Replies: 2
    Last Post: 09-11-2008, 02:57 AM
  5. how to change mouse position ,please help
    By haitian in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 11-28-2005, 10:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean