-
Notifications
You must be signed in to change notification settings - Fork 20
/
2D-transformation-about-origin.cpp
74 lines (73 loc) · 1.56 KB
/
2D-transformation-about-origin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//about origin
#include <GL/glut.h>
void display()
{
/* draw unit square polygon */
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.0f, 1.0f);
glVertex2f(150, 150);
glVertex2f(300, 150);
glVertex2f(225, 225);
glEnd();
/* flush GL buffers */
glFlush();
/* clear window */
}
void OptionsMenu(GLint selectedOpt)
{
switch (selectedOpt)
{
case 1:
/* draw unit square polygon */
glBegin(GL_POLYGON);
glVertex2f(150, 150);
glVertex2f(300, 150);
glVertex2f(225, 225);
glEnd();
/* flush GL buffers */
glFlush();
break;
case 2:
glRotatef(15, 0, 0, 1);
glColor3f(1.0f, 0.0f, 0.0f);
break;
case 3:
glScalef(1.5, 1.5, 0);
glColor3f(0.0f, 1.0f, 0.0f);
break;
case 4:
glTranslatef(100, 100, 0);
glColor3f(0.0f, 1.0f, 1.0f);
default: break;
}
}
void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0); //
// set the drawing color
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 800.0, 0.0, 800.0);
}
void main(int argc, char** argv)
{
/* Initialize mode and open a window in upper left corner of
/* screen */
/* Window title is name of program (arg[0]) */
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800, 800);
glutInitWindowPosition(0, 0);
glutCreateWindow("simple");
glutDisplayFunc(display);
glutCreateMenu(OptionsMenu);
glutAddMenuEntry("Polygon ", 1);
glutAddMenuEntry("Rotate ", 2);
glutAddMenuEntry("Scale", 3);
glutAddMenuEntry("Translate ", 4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
init();
glutMainLoop();
}