@@ -36,6 +36,7 @@ bool initGL(int *argc, char **argv);
36
36
void display ();
37
37
void keyboard (unsigned char key, int x, int y);
38
38
void mouse (int button, int state, int x, int y);
39
+ void reshape (int width, int height);
39
40
void motion (int x, int y);
40
41
void printHelp ();
41
42
@@ -84,19 +85,21 @@ int main(int argc, char **argv)
84
85
glutKeyboardFunc (keyboard);
85
86
glutMouseFunc (mouse);
86
87
glutMotionFunc (motion);
88
+ glutReshapeFunc (reshape);
87
89
glutMainLoop ();
88
90
}
89
91
90
92
bool initGL (int *argc, char **argv)
91
93
{
92
94
glutInit (argc, argv);
95
+ glutDisplayFunc (display);
93
96
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE);
94
97
glutInitWindowSize (window_width, window_height);
95
98
glutCreateWindow (" Lesson 0 - basic transformations" );
96
99
glutDisplayFunc (display);
97
100
glutKeyboardFunc (keyboard);
98
101
glutMotionFunc (motion);
99
-
102
+ glutReshapeFunc (reshape);
100
103
glClearColor (0.0 , 0.0 , 0.0 , 1.0 );
101
104
glDisable (GL_DEPTH_TEST);
102
105
@@ -108,19 +111,26 @@ bool initGL(int *argc, char **argv)
108
111
109
112
return true ;
110
113
}
114
+ void reshape (int width, int height) {
115
+ glViewport (0 , 0 , width, height);
116
+ glMatrixMode (GL_PROJECTION);
117
+ glLoadIdentity ();
118
+ gluPerspective (60.0 , (GLfloat)width / (GLfloat) height, 0.01 , 10000.0 );
119
+ }
111
120
112
121
void display ()
113
122
{
114
123
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
115
124
125
+
116
126
glMatrixMode (GL_MODELVIEW);
117
127
glLoadIdentity ();
118
128
glTranslatef (translate_x, translate_y, translate_z);
119
129
glRotatef (rotate_x, 1.0 , 0.0 , 0.0 );
120
130
glRotatef (rotate_y, 0.0 , 0.0 , 1.0 );
121
131
122
132
glBegin (GL_LINES);
123
- glColor3f (1 .0f , 0 .0f , 0 .0f );
133
+ glColor3f (1 .0f , 0 .0f , 0 .0f );
124
134
glVertex3f (0 .0f , 0 .0f , 0 .0f );
125
135
glVertex3f (1 .0f , 0 .0f , 0 .0f );
126
136
0 commit comments