bryonq

10-28-2002, 10:47 AM

How would I go about using OpenGL to draw 2D circles? I can use glRect() for rectangles, and glVertex2f for creating triangles and such, but I have not been able to find any commands for drawting them. Any suggestions?

View Full Version : Drawing Circles

bryonq

10-28-2002, 10:47 AM

How would I go about using OpenGL to draw 2D circles? I can use glRect() for rectangles, and glVertex2f for creating triangles and such, but I have not been able to find any commands for drawting them. Any suggestions?

andypotter

10-28-2002, 11:39 AM

1) You can draw a sphere with glusphere()

2) Or you could draw a circle made from several triangles. ie:

glBegin(GL_POLYGON);

float rad; // radius

for( float ang=0; ang <= 2*PI; ang += 0.1)

{

// draw the vertices required.

glVertex3f(cos(ang)*rad, sin(ang)*rad, 0);

}

glEnd();

- andy

2) Or you could draw a circle made from several triangles. ie:

glBegin(GL_POLYGON);

float rad; // radius

for( float ang=0; ang <= 2*PI; ang += 0.1)

{

// draw the vertices required.

glVertex3f(cos(ang)*rad, sin(ang)*rad, 0);

}

glEnd();

- andy

nexusone

10-28-2002, 11:47 AM

OpenGL only is mainly 3D, but even openGL its self has no primitive functions, there is not glRec or glCircle, just vertex.

How there is two utility librarys glu and glut that have 3D primitives like sphere, cone, cylinder, cube.

First you should look at some of the openGL tutor sites like nehe.gamedev.net.

But all objects except for bitmaped are built using vertex's.

Here is how you could code a Rectangle function; where x1, y1 is top left, x2, y2 is bottom right.

My_rec(int x1, int y1, int x2, int y2)

{

glBegin(GL_QUADS);

glVertex2f(x1, y1);

glVertex2f(x1, y2);

glVertex2f(x2, y2);

glVertex2f(x2, y1);

glEnd();

}

Circle would be done but using a math functions to plot the points on the radius of the circle, then building it with vertexs

Originally posted by bryonq:

How would I go about using OpenGL to draw 2D circles? I can use glRect() for rectangles, and glVertex2f for creating triangles and such, but I have not been able to find any commands for drawting them. Any suggestions?

How there is two utility librarys glu and glut that have 3D primitives like sphere, cone, cylinder, cube.

First you should look at some of the openGL tutor sites like nehe.gamedev.net.

But all objects except for bitmaped are built using vertex's.

Here is how you could code a Rectangle function; where x1, y1 is top left, x2, y2 is bottom right.

My_rec(int x1, int y1, int x2, int y2)

{

glBegin(GL_QUADS);

glVertex2f(x1, y1);

glVertex2f(x1, y2);

glVertex2f(x2, y2);

glVertex2f(x2, y1);

glEnd();

}

Circle would be done but using a math functions to plot the points on the radius of the circle, then building it with vertexs

Originally posted by bryonq:

How would I go about using OpenGL to draw 2D circles? I can use glRect() for rectangles, and glVertex2f for creating triangles and such, but I have not been able to find any commands for drawting them. Any suggestions?

kaysoft

10-28-2002, 12:10 PM

Is GL_QUADS slower than GL_TRIANGLES btw?

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.