Skip to content

Commit 21d2f10

Browse files
Merge pull request JanuszBedkowski#3 from michalpelka/master
Fixed aspect ratio issue
2 parents 5fb0748 + 35d0a67 commit 21d2f10

File tree

23 files changed

+206
-2
lines changed

23 files changed

+206
-2
lines changed

tutorial/lesson_0/src/lesson_0_main.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ bool initGL(int *argc, char **argv);
3636
void display();
3737
void keyboard(unsigned char key, int x, int y);
3838
void mouse(int button, int state, int x, int y);
39+
void reshape(int width, int height);
3940
void motion(int x, int y);
4041
void printHelp();
4142

@@ -84,19 +85,21 @@ int main(int argc, char **argv)
8485
glutKeyboardFunc(keyboard);
8586
glutMouseFunc(mouse);
8687
glutMotionFunc(motion);
88+
glutReshapeFunc(reshape);
8789
glutMainLoop();
8890
}
8991

9092
bool initGL(int *argc, char **argv)
9193
{
9294
glutInit(argc, argv);
95+
glutDisplayFunc(display);
9396
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
9497
glutInitWindowSize(window_width, window_height);
9598
glutCreateWindow("Lesson 0 - basic transformations");
9699
glutDisplayFunc(display);
97100
glutKeyboardFunc(keyboard);
98101
glutMotionFunc(motion);
99-
102+
glutReshapeFunc(reshape);
100103
glClearColor(0.0, 0.0, 0.0, 1.0);
101104
glDisable(GL_DEPTH_TEST);
102105

@@ -108,19 +111,26 @@ bool initGL(int *argc, char **argv)
108111

109112
return true;
110113
}
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+
}
111120

112121
void display()
113122
{
114123
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
115124

125+
116126
glMatrixMode(GL_MODELVIEW);
117127
glLoadIdentity();
118128
glTranslatef(translate_x, translate_y, translate_z);
119129
glRotatef(rotate_x, 1.0, 0.0, 0.0);
120130
glRotatef(rotate_y, 0.0, 0.0, 1.0);
121131

122132
glBegin(GL_LINES);
123-
glColor3f(1.0f, 0.0f, 0.0f);
133+
glColor3f(1.0f, 0.0f, 0.0f);
124134
glVertex3f(0.0f, 0.0f, 0.0f);
125135
glVertex3f(1.0f, 0.0f, 0.0f);
126136

tutorial/lesson_1/src/lesson_1_main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ bool initGL(int *argc, char **argv);
3636
void display();
3737
void keyboard(unsigned char key, int x, int y);
3838
void mouse(int button, int state, int x, int y);
39+
void reshape(int width, int height);
3940
void motion(int x, int y);
4041
void printHelp();
4142

@@ -91,6 +92,7 @@ int main(int argc, char **argv)
9192
glutKeyboardFunc(keyboard);
9293
glutMouseFunc(mouse);
9394
glutMotionFunc(motion);
95+
glutReshapeFunc(reshape);
9496
glutMainLoop();
9597
}
9698

@@ -103,6 +105,7 @@ bool initGL(int *argc, char **argv)
103105
glutDisplayFunc(display);
104106
glutKeyboardFunc(keyboard);
105107
glutMotionFunc(motion);
108+
glutReshapeFunc(reshape);
106109

107110
glClearColor(0.0, 0.0, 0.0, 1.0);
108111
glDisable(GL_DEPTH_TEST);
@@ -116,10 +119,18 @@ bool initGL(int *argc, char **argv)
116119
return true;
117120
}
118121

122+
void reshape(int width, int height) {
123+
glViewport(0, 0, width, height);
124+
glMatrixMode(GL_PROJECTION);
125+
glLoadIdentity();
126+
gluPerspective(60.0, (GLfloat)width / (GLfloat) height, 0.01, 10000.0);
127+
}
128+
119129
void display()
120130
{
121131
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
122132

133+
123134
glMatrixMode(GL_MODELVIEW);
124135
glLoadIdentity();
125136
glTranslatef(translate_x, translate_y, translate_z);

tutorial/lesson_10/src/lesson_10_main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ bool initGL(int *argc, char **argv);
105105
void display();
106106
void keyboard(unsigned char key, int x, int y);
107107
void mouse(int button, int state, int x, int y);
108+
void reshape(int width, int height);
108109
void motion(int x, int y);
109110
void printHelp();
110111

@@ -194,6 +195,7 @@ int main(int argc, char **argv)
194195
glutKeyboardFunc(keyboard);
195196
glutMouseFunc(mouse);
196197
glutMotionFunc(motion);
198+
glutReshapeFunc(reshape);
197199
glutMainLoop();
198200
}
199201

@@ -206,6 +208,7 @@ bool initGL(int *argc, char **argv)
206208
glutDisplayFunc(display);
207209
glutKeyboardFunc(keyboard);
208210
glutMotionFunc(motion);
211+
glutReshapeFunc(reshape);
209212

210213
glClearColor(0.0, 0.0, 0.0, 1.0);
211214
glDisable(GL_DEPTH_TEST);
@@ -219,10 +222,18 @@ bool initGL(int *argc, char **argv)
219222
return true;
220223
}
221224

225+
void reshape(int width, int height) {
226+
glViewport(0, 0, width, height);
227+
glMatrixMode(GL_PROJECTION);
228+
glLoadIdentity();
229+
gluPerspective(60.0, (GLfloat)width / (GLfloat) height, 0.01, 10000.0);
230+
}
231+
222232
void display()
223233
{
224234
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
225235

236+
226237
glMatrixMode(GL_MODELVIEW);
227238
glLoadIdentity();
228239
glTranslatef(translate_x, translate_y, translate_z);

tutorial/lesson_11/src/lesson_11_main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ bool initGL(int *argc, char **argv);
4646
void display();
4747
void keyboard(unsigned char key, int x, int y);
4848
void mouse(int button, int state, int x, int y);
49+
void reshape(int width, int height);
4950
void motion(int x, int y);
5051
void printHelp();
5152

@@ -119,6 +120,7 @@ int main(int argc, char **argv)
119120
glutKeyboardFunc(keyboard);
120121
glutMouseFunc(mouse);
121122
glutMotionFunc(motion);
123+
glutReshapeFunc(reshape);
122124
glutMainLoop();
123125
}
124126

@@ -131,6 +133,7 @@ bool initGL(int *argc, char **argv)
131133
glutDisplayFunc(display);
132134
glutKeyboardFunc(keyboard);
133135
glutMotionFunc(motion);
136+
glutReshapeFunc(reshape);
134137

135138
glClearColor(0.0, 0.0, 0.0, 1.0);
136139
glDisable(GL_DEPTH_TEST);
@@ -144,10 +147,18 @@ bool initGL(int *argc, char **argv)
144147
return true;
145148
}
146149

150+
void reshape(int width, int height) {
151+
glViewport(0, 0, width, height);
152+
glMatrixMode(GL_PROJECTION);
153+
glLoadIdentity();
154+
gluPerspective(60.0, (GLfloat)width / (GLfloat) height, 0.01, 10000.0);
155+
}
156+
147157
void display()
148158
{
149159
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
150160

161+
151162
glMatrixMode(GL_MODELVIEW);
152163
glLoadIdentity();
153164
glTranslatef(translate_x, translate_y, translate_z);

tutorial/lesson_12/src/lesson_12_main.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ bool initGL(int *argc, char **argv);
5656
void display();
5757
void keyboard(unsigned char key, int x, int y);
5858
void mouse(int button, int state, int x, int y);
59+
void reshape(int width, int height);
5960
void motion(int x, int y);
6061

6162

@@ -152,6 +153,7 @@ main(int argc, char **argv)
152153
glutKeyboardFunc(keyboard);
153154
glutMouseFunc(mouse);
154155
glutMotionFunc(motion);
156+
glutReshapeFunc(reshape);
155157
glutMainLoop();
156158

157159
}
@@ -165,6 +167,7 @@ bool initGL(int *argc, char **argv)
165167
glutDisplayFunc(display);
166168
glutKeyboardFunc(keyboard);
167169
glutMotionFunc(motion);
170+
glutReshapeFunc(reshape);
168171

169172
// default initialization
170173
glClearColor(0.0, 0.0, 0.0, 1.0);

tutorial/lesson_13/src/lesson_13_main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bool initGL(int *argc, char **argv);
1919
void display();
2020
void keyboard(unsigned char key, int x, int y);
2121
void mouse(int button, int state, int x, int y);
22+
void reshape(int width, int height);
2223
void motion(int x, int y);
2324
void printHelp();
2425

@@ -53,6 +54,7 @@ int main(int argc, char **argv)
5354
glutKeyboardFunc(keyboard);
5455
glutMouseFunc(mouse);
5556
glutMotionFunc(motion);
57+
glutReshapeFunc(reshape);
5658
glutMainLoop();
5759
}
5860

@@ -65,6 +67,7 @@ bool initGL(int *argc, char **argv)
6567
glutDisplayFunc(display);
6668
glutKeyboardFunc(keyboard);
6769
glutMotionFunc(motion);
70+
glutReshapeFunc(reshape);
6871

6972
glClearColor(0.0, 0.0, 0.0, 1.0);
7073
glDisable(GL_DEPTH_TEST);
@@ -78,10 +81,18 @@ bool initGL(int *argc, char **argv)
7881
return true;
7982
}
8083

84+
void reshape(int width, int height) {
85+
glViewport(0, 0, width, height);
86+
glMatrixMode(GL_PROJECTION);
87+
glLoadIdentity();
88+
gluPerspective(60.0, (GLfloat)width / (GLfloat) height, 0.01, 10000.0);
89+
}
90+
8191
void display()
8292
{
8393
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
8494

95+
8596
glMatrixMode(GL_MODELVIEW);
8697
glLoadIdentity();
8798
glTranslatef(translate_x, translate_y, translate_z);

tutorial/lesson_14/src/lesson_14_main.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ bool initGL(int *argc, char **argv);
3535
void display();
3636
void keyboard(unsigned char key, int x, int y);
3737
void mouse(int button, int state, int x, int y);
38+
void reshape(int width, int height);
3839
void motion(int x, int y);
3940

4041

@@ -172,6 +173,7 @@ main(int argc, char **argv)
172173
glutKeyboardFunc(keyboard);
173174
glutMouseFunc(mouse);
174175
glutMotionFunc(motion);
176+
glutReshapeFunc(reshape);
175177
glutMainLoop();
176178
}
177179

@@ -184,6 +186,7 @@ bool initGL(int *argc, char **argv)
184186
glutDisplayFunc(display);
185187
glutKeyboardFunc(keyboard);
186188
glutMotionFunc(motion);
189+
glutReshapeFunc(reshape);
187190

188191
// default initialization
189192
glClearColor(0.0, 0.0, 0.0, 1.0);

tutorial/lesson_15/src/lesson_15_main.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ bool initGL(int *argc, char **argv);
3434
void display();
3535
void keyboard(unsigned char key, int x, int y);
3636
void mouse(int button, int state, int x, int y);
37+
void reshape(int width, int height);
3738
void motion(int x, int y);
3839

3940

@@ -166,6 +167,7 @@ main(int argc, char **argv)
166167
glutKeyboardFunc(keyboard);
167168
glutMouseFunc(mouse);
168169
glutMotionFunc(motion);
170+
glutReshapeFunc(reshape);
169171
glutMainLoop();
170172
}
171173

@@ -178,6 +180,7 @@ bool initGL(int *argc, char **argv)
178180
glutDisplayFunc(display);
179181
glutKeyboardFunc(keyboard);
180182
glutMotionFunc(motion);
183+
glutReshapeFunc(reshape);
181184

182185
// default initialization
183186
glClearColor(0.0, 0.0, 0.0, 1.0);

tutorial/lesson_16/src/lesson_16_main.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ bool initGL(int *argc, char **argv);
3535
void display();
3636
void keyboard(unsigned char key, int x, int y);
3737
void mouse(int button, int state, int x, int y);
38+
void reshape(int width, int height);
3839
void motion(int x, int y);
3940

4041

@@ -191,6 +192,7 @@ main(int argc, char **argv)
191192
glutKeyboardFunc(keyboard);
192193
glutMouseFunc(mouse);
193194
glutMotionFunc(motion);
195+
glutReshapeFunc(reshape);
194196
glutMainLoop();
195197
}
196198

@@ -203,6 +205,7 @@ bool initGL(int *argc, char **argv)
203205
glutDisplayFunc(display);
204206
glutKeyboardFunc(keyboard);
205207
glutMotionFunc(motion);
208+
glutReshapeFunc(reshape);
206209

207210
// default initialization
208211
glClearColor(0.0, 0.0, 0.0, 1.0);

tutorial/lesson_17/src/lesson_17_main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ bool initGL(int *argc, char **argv);
2626
void display();
2727
void keyboard(unsigned char key, int x, int y);
2828
void mouse(int button, int state, int x, int y);
29+
void reshape(int width, int height);
2930
void motion(int x, int y);
3031
void printHelp();
3132
void computePath();
@@ -57,6 +58,7 @@ int main(int argc, char **argv)
5758
glutKeyboardFunc(keyboard);
5859
glutMouseFunc(mouse);
5960
glutMotionFunc(motion);
61+
glutReshapeFunc(reshape);
6062
glutMainLoop();
6163
}
6264

@@ -69,6 +71,7 @@ bool initGL(int *argc, char **argv)
6971
glutDisplayFunc(display);
7072
glutKeyboardFunc(keyboard);
7173
glutMotionFunc(motion);
74+
glutReshapeFunc(reshape);
7275

7376
glClearColor(0.0, 0.0, 0.0, 1.0);
7477
glDisable(GL_DEPTH_TEST);
@@ -82,10 +85,18 @@ bool initGL(int *argc, char **argv)
8285
return true;
8386
}
8487

88+
void reshape(int width, int height) {
89+
glViewport(0, 0, width, height);
90+
glMatrixMode(GL_PROJECTION);
91+
glLoadIdentity();
92+
gluPerspective(60.0, (GLfloat)width / (GLfloat) height, 0.01, 10000.0);
93+
}
94+
8595
void display()
8696
{
8797
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
8898

99+
89100
glMatrixMode(GL_MODELVIEW);
90101
glLoadIdentity();
91102
glTranslatef(translate_x, translate_y, translate_z);

tutorial/lesson_18/src/lesson_18_main.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ bool initGL(int *argc, char **argv);
1616
void display();
1717
void keyboard(unsigned char key, int x, int y);
1818
void mouse(int button, int state, int x, int y);
19+
void reshape(int width, int height);
1920
void motion(int x, int y);
2021
void printHelp();
2122

@@ -41,6 +42,7 @@ int main(int argc, char **argv)
4142
glutKeyboardFunc(keyboard);
4243
glutMouseFunc(mouse);
4344
glutMotionFunc(motion);
45+
glutReshapeFunc(reshape);
4446
glutMainLoop();
4547
}
4648

@@ -53,6 +55,7 @@ bool initGL(int *argc, char **argv)
5355
glutDisplayFunc(display);
5456
glutKeyboardFunc(keyboard);
5557
glutMotionFunc(motion);
58+
glutReshapeFunc(reshape);
5659

5760
glClearColor(0.0, 0.0, 0.0, 1.0);
5861
glDisable(GL_DEPTH_TEST);

0 commit comments

Comments
 (0)