Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // opengl.cpp : Defines the entry point for the console application.
- //
- #include "glut.h"
- #include "math.h"
- float x=0,y=0;
- void drawCircle (float xc, float yc, float rad)
- {
- //
- // draw a circle centered at (xc,yc) with radius rad
- //
- glPushMatrix();
- glTranslatef(xc,yc,0);
- glBegin(GL_LINE_LOOP);
- //
- for (int angle=0; angle<365; angle=angle+5)
- {
- float angle_radians = angle * (float)3.14159 / (float)180;
- float x = rad * (float)cos(angle_radians);
- float y = rad * (float)sin(angle_radians);
- glVertex3f(x,y,0);
- }
- //
- glEnd();
- glPopMatrix();
- }
- void display(void)
- {
- /* clear window */
- glClear(GL_COLOR_BUFFER_BIT);
- glPushMatrix();
- glTranslatef(x,y,0);
- //glRotatef(kat,0,0,1); rotacja w okolo osi z
- /* draw unit square polygon */
- glBegin(GL_POLYGON);
- glVertex2f(-0.5, -0.5);
- glVertex2f(-0.5, 0.5);
- glVertex2f(0.5, 0.5);
- glVertex2f(0.5, -0.5);
- glEnd();
- /* flush GL buffers */
- glPopMatrix();
- glFlush();
- }
- static void Key(unsigned char key, int x_d, int y_d)
- {
- switch (key) {
- case '1':
- x+=.1;
- y+=.1;
- glutPostRedisplay();
- break;
- case '2':
- x-=.1;
- y-=.1;
- glutPostRedisplay();
- break;
- case 27:
- exit(0);
- }
- }
- void init()
- {
- /* set clear color to black */
- glClearColor (0.0, 0.0, 0.0, 0.0);
- /* set fill color to white */
- glColor3f(1.0, 1.0, 1.0);
- /* set up standard orthogonal view with clipping */
- /* box as cube of side 2 centered at origin */
- /* This is default view and these statement could be removed */
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
- glMatrixMode (GL_MODELVIEW);
- glLoadIdentity ();
- }
- int main(int argc, char* argv[])
- {
- glutInit(&argc,argv);
- glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(500,500);
- glutInitWindowPosition(0,0);
- glutCreateWindow("simple");
- glutDisplayFunc(display);
- glutKeyboardFunc(Key);
- init();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement