Created
April 12, 2019 20:24
-
-
Save leandrovianna/3d52faeea09e4bea3e24c941c918cb81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <GL/glut.h> | |
| #include <stdio.h> | |
| #include <math.h> | |
| 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(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment