Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
- #include <cmath>
- void init()
- {
- glClearColor(0, 0 , 0 , 0);
- glMatrixMode(GL_PROJECTION);
- gluOrtho2D(0.0, 20.0, 0.0, 20.0 );
- glMatrixMode(GL_MODELVIEW);
- }
- void drawCircle(int r, int x_center, int y_center)
- {
- int deg =0;
- double theta, x, y;
- glBegin(GL_POLYGON);
- while (deg<360)
- {
- theta = (deg*M_PI)/180;
- x = r*cos(theta) + x_center;
- y = r*sin(theta) + y_center;
- deg++;
- glVertex2d(x , y);
- }
- glEnd();
- }
- int angle= 0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3ub(255,255,255);
- drawCircle(3, 5, 5);
- glPushMatrix();
- glColor3ub(0,0,0);
- glTranslatef(5,5,0);
- glRotatef(angle, 0, 0, 1);
- glTranslatef(-5,-5,0);
- glLineWidth(2.0);
- glBegin(GL_LINES);
- glVertex2i(2,5);
- glVertex2i(8,5);
- glVertex2i(5,2);
- glVertex2i(5,8);
- glEnd();
- glPopMatrix();
- glFlush();
- }
- void update(int value)
- {
- angle -= 10;
- glutPostRedisplay();
- glutTimerFunc(50,update, 0);
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB);
- glutInitWindowPosition(300,200);
- glutInitWindowSize(500,500);
- glutCreateWindow("Circle");
- glutDisplayFunc(display);
- glutTimerFunc(0,update, 0);
- init();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement