#include #include #include typedef GLfloat Matrix3x3[3][3]; const GLdouble pi = 3.14158; typedef struct wcPt2D { GLfloat x, y; } wcPt2D; void init(void) { /* determina cor da janela de branca*/ glClearColor(1.0, 1.0, 1.0, 1.0); } void paint_circle_points(wcPt2D point, wcPt2D origin) { printf("%f %f\n", point.x, point.y); glBegin(GL_POINTS); glVertex2f(origin.x + point.x, origin.y + point.y); glVertex2f(origin.x + point.x, origin.y - point.y); glVertex2f(origin.x - point.x, origin.y + point.y); glVertex2f(origin.x - point.x, origin.y - point.y); glVertex2f(origin.x + point.y, origin.y + point.x); glVertex2f(origin.x + point.y, origin.y - point.x); glVertex2f(origin.x - point.y, origin.y + point.x); glVertex2f(origin.x - point.y, origin.y - point.x); glEnd(); } void draw_circle(wcPt2D origin, GLint radius) { GLint x, y, theta; GLfloat d; wcPt2D p; for (theta = 0; theta <= 45; theta++) { p.x = radius * cos(theta * pi / 180.0); p.y = radius * sin(theta * pi / 180.0); paint_circle_points(p, origin); } } /* Janela inicial */ GLsizei winWidth = 600, winHeight = 600; /* limites para as coordenadas do mundo */ GLfloat xwcMin = -300.0, xwcMax = 300.0; GLfloat ywcMin = -300.0, ywcMax = 300.0; void winReshapeFcn(GLint newWidth, GLint newHeight) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(xwcMin, xwcMax, ywcMin, ywcMax); glClear(GL_COLOR_BUFFER_BIT); } void displayFcn(void) { glColor3d(1.0, 0.0, 0.0); wcPt2D origin = {150.0, 150.0}; GLfloat radius = 50.0; glColor3f(1.0, 0.0, 0.0); draw_circle(origin, radius); /* glBegin(GL_QUADS); glVertex2f(0, 0); glVertex2f(0, 150); glVertex2f(150, 150); glVertex2f(150, 0); glEnd(); */ glFlush(); } int main(int argc, char ** argv) { glutInit( & argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(winWidth, winHeight); glutInitWindowPosition(50, 50); glutCreateWindow("Draw Circle"); init(); glutDisplayFunc(displayFcn); glutReshapeFunc(winReshapeFcn); glutMainLoop(); }