Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Drawing a circle with OpenGL

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1 riyunoa   Members   

126
Like
0Likes
Like

Posted 03 July 2005 - 09:31 PM

Hello everyone... I have a problem... How do I draw a circle with GL_LINES? I have tried using glTranslatef() and glRotatef() but it doesn't seem to work on GL_LINES... Then I tried calculating the positions of the vertices with sin and cos... @_# Help~!!

#2 T2k   Members   

220
Like
0Likes
Like

Posted 03 July 2005 - 09:47 PM

You cant Translate/Rotate during a glBegin/glEnd commandpair. you will have to calc the vertices with sin/cos, something like:

#define PI 3.14...
glBegin(GL_LINE_STRIP);
for(int i=0; i <= 360; i++)
glVertex3f(sin(i*PI/180)*5, cos(i*PI/180)*5, 1);
glEnd();

this should draw a circle with 360 lines and a radius of 5 in the xy-plane at z=1, however its not tested code, so it may be that it draws a not closed circle or does nothing :p

edited GL_LINES into GL_LINE_STRIP

T2k

#3 Dev48GameDev   Members   

122
Like
0Likes
Like

Posted 03 July 2005 - 09:47 PM

Can you post your code here?
It is more simple to answer you with some lines of code...

#4 riyunoa   Members   

126
Like
0Likes
Like

Posted 03 July 2005 - 10:09 PM

This is what I tried:


glBegin(GL_LINES);
for ( float angle = 0; angle <= 2*3.142; angle+=3.142/30)
{
x = 100.0 * cos (angle);
z = 100.0 * sin (angle);



glVertex3f(x/2, 0.0, z/2);
glVertex3f(x, 0.0, z);

}
glEnd();




And it gave me this:


It is supposed to be like this:


#5 tksuoran   Members   

186
Like
0Likes
Like

Posted 03 July 2005 - 10:17 PM

Try GL_LINE_LOOP instead of GL_LINES inside your glBegin(), and remove the line with /2, just one glVertex3f() inside the loop.

#6 werekarg   Members   

193
Like
0Likes
Like

Posted 03 July 2005 - 10:41 PM

in the way you started, replace the inner loop with:


glVertex3f(100.0 * cos (angle) / 2, 0, 100.0 * sin (angle) / 2);
glVertex3f(100.0 * cos (angle + 3.142/30) / 2, 0, 100.0 * sin (angle + 3.142/30) / 2);






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.