PDA

View Full Version : How to change the position of a circle?



Asvan11
10-17-2013, 04:06 PM
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





#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();
}

tonyo_au
10-17-2013, 05:54 PM
The function you need is gltranslate (or just add a offset to each of youR points).

Asvan11
10-18-2013, 05:16 AM
Where do I add the gltranslate inside the void Circle() or outside?

tonyo_au
10-18-2013, 08:42 PM
Normally outside that way you can draw several circles at different locations. (Remember to use glPushMatrix (http://www.opengl.org/sdk/docs/man2/xhtml/glPushMatrix.xml) and glPopMatrix (http://www.opengl.org/sdk/docs/man2/xhtml/glPopMatrix.xml) to save and restore the untranslated coordinate system) Also move your clear outside.