-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pan_rotation_zoom.cpp
executable file
·91 lines (82 loc) · 1.9 KB
/
Pan_rotation_zoom.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<windows.h>
#include <GL/glut.h>
#include <stdlib.h>
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
}
void draw_triangle(void)
{
glShadeModel(GL_SMOOTH);
glColor3f(0.0,0.0,1.0);
glBegin (GL_TRIANGLES);//画出三角形,为混合色填充方式
glVertex2f(50.0, 25.0);
glColor3f(0.4,0.5,0.60);
glVertex2f(150.0, 25.0);
glColor3f(0.9,0.7,0.8);
glVertex2f(100.0, 100.0);
glEnd();
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity ();
glColor3f (1.0, 1.0, 1.0);
glTranslatef(-100.0,-50.0,1.0);
draw_triangle ();
glLoadIdentity ();
glTranslatef (0.0, 100.0, 1.0);
draw_triangle ();
glLoadIdentity ();
glRotatef (90.0, 0.0, 0.0, 1.0);
draw_triangle ();
glLoadIdentity ();
glScalef (0.5, 0.5, 1.0);
draw_triangle ();
glFlush ();
}
/*
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity ();
glColor3f (1.0, 1.0, 1.0);
glTranslatef(-100.0,-50.0,1.0);
draw_triangle ();
glLoadIdentity ();
glTranslatef (0.0, 100.0, 1.0);
glRotatef (90.0, 0.0, 0.0, 1.0);
glScalef (0.5, 0.5, 1.0);
draw_triangle ();//经过三种变换后画出图形
glFlush ();
}
*/
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
if (w <= h)
gluOrtho2D (-200.0, 250.0, -100.0*(GLfloat)h/(GLfloat)w,
200.0*(GLfloat)h/(GLfloat)w);//调整裁剪窗口
else
gluOrtho2D (-200.0*(GLfloat)w/(GLfloat)h,
250.0*(GLfloat)w/(GLfloat)h, -50.0, 200.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (600, 600);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}