質問編集履歴
4
画像の添付
test
CHANGED
File without changes
|
test
CHANGED
@@ -438,7 +438,7 @@
|
|
438
438
|
|
439
439
|
### 実行結果
|
440
440
|
|
441
|
-

|
442
442
|
|
443
443
|
|
444
444
|
|
3
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
OpenGLでス
|
1
|
+
OpenGLでテクスチャを実装しようとすると画像にノイズが入ります
|
test
CHANGED
File without changes
|
2
コード更新、実行結果の画像を添付
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
OpenGLでストラクチャを実装しようとすると
|
1
|
+
OpenGLでストラクチャを実装しようとすると画像にノイズが入ります
|
test
CHANGED
@@ -4,433 +4,441 @@
|
|
4
4
|
|
5
5
|
2つアニメーションを実装している立方体があるうち、中心の立方体の6面にストラクチャを貼ろうとしたところ、実行時エラーが発生しました。
|
6
6
|
|
7
|
+
試しに、1つのポリゴンを表示するようにしているところです。
|
8
|
+
|
7
9
|
|
8
10
|
|
9
11
|
###発生している問題・エラーメッセージ
|
10
12
|
|
13
|
+
テクスチャの画像に下の実行結果のようなノイズが入ってしまう。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
###該当のソースコード
|
18
|
+
|
19
|
+
```c
|
20
|
+
|
21
|
+
#include <stdio.h>
|
22
|
+
|
23
|
+
#include <GLUT/glut.h>
|
24
|
+
|
25
|
+
#include <stdlib.h>
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
#define KEY_ESC 27
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
/*Gold*/
|
34
|
+
|
35
|
+
float diffuse[]={0.7, 0.6, 0.2, 1.0}; //拡散反射成分(R,G,B,A強度0.0〜1.0)
|
36
|
+
|
37
|
+
float specular[]={0.6, 0.5, 0.4, 1.0}; //鏡面反射成分(R,G,B,A強度0.0〜1.0)
|
38
|
+
|
39
|
+
float ambient[]={0.3,0.2,0.1,1.0}; //環境光反射成分(R,G,B,A強度0.0〜1.0)
|
40
|
+
|
41
|
+
float shininess=10.0; //鏡面光の鋭さ(0.0〜128.0)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
double param_big = 0.0;
|
46
|
+
|
47
|
+
double param_small = 0.5;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
/* Texture */
|
52
|
+
|
53
|
+
#define TEXWIDTH 256
|
54
|
+
|
55
|
+
#define TEXHEIGHT 256
|
56
|
+
|
57
|
+
//#define TEXWIDTH 512
|
58
|
+
|
59
|
+
//#define TEXHEIGHT 512
|
60
|
+
|
61
|
+
static const char texture1[] = "./image01.data";
|
62
|
+
|
63
|
+
//static const char texture2[] = "sample.data";
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
void myKbd(unsigned char key,int x, int y){
|
68
|
+
|
69
|
+
if(key==KEY_ESC)exit(0);
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
void texture_map(void){
|
74
|
+
|
75
|
+
// --------- テクスチャマッピング開始 -------------
|
76
|
+
|
77
|
+
glEnable(GL_TEXTURE_2D);
|
78
|
+
|
79
|
+
glNormal3d(0.0,0.0,1.0); //法線ベクトルの設定
|
80
|
+
|
81
|
+
glBegin(GL_QUADS);
|
82
|
+
|
83
|
+
glTexCoord2d(0,1); glVertex3d(-1,-1,0); //左下
|
84
|
+
|
85
|
+
glTexCoord2d(1,1); glVertex3d(1,-1,0); //左上
|
86
|
+
|
87
|
+
glTexCoord2d(1,0); glVertex3d(1,1,0); //右上
|
88
|
+
|
89
|
+
glTexCoord2d(0,0); glVertex3d(-1,1,0); //右下
|
90
|
+
|
91
|
+
//上面
|
92
|
+
|
93
|
+
// glTexCoord2d(0.0,1); glVertex3d(0.0,0.0,0.0); //左下
|
94
|
+
|
95
|
+
// glTexCoord2d(0.0,0.0); glVertex3d(1,0.0,0); //左上
|
96
|
+
|
97
|
+
// glTexCoord2d(1,0.0); glVertex3d(1,0,-1); //右上
|
98
|
+
|
99
|
+
// glTexCoord2d(1,1); glVertex3d(0,0.0,-1); //右下
|
100
|
+
|
101
|
+
//底面
|
102
|
+
|
103
|
+
// glTexCoord2d(0.0,0.5); glVertex3d(0,-0.5,0); //左下
|
104
|
+
|
105
|
+
// glTexCoord2d(0.0,0.0); glVertex3d(0,-0.5,-0.5); //左上
|
106
|
+
|
107
|
+
// glTexCoord2d(0.5,0.0); glVertex3d(0.5,-0.5,-0.5); //右上
|
108
|
+
|
109
|
+
// glTexCoord2d(0.5,0.5); glVertex3d(0.5,-0.5,0.0); //右下
|
110
|
+
|
111
|
+
// //左側
|
112
|
+
|
113
|
+
// glTexCoord2d(0.0,0.5); glVertex3d(0.0,-0.5,0.0); //左下
|
114
|
+
|
115
|
+
// glTexCoord2d(0.0,0.0); glVertex3d(0.0,0.0,0.0); //左上
|
116
|
+
|
117
|
+
// glTexCoord2d(0.5,0.0); glVertex3d(0.0,0.0,-0.5); //右上
|
118
|
+
|
119
|
+
// glTexCoord2d(0.5,0.5); glVertex3d(0.0,-0.5,-0.5); //右下
|
120
|
+
|
121
|
+
// //奥側
|
122
|
+
|
123
|
+
// glTexCoord2d(0.0,0.5); glVertex3d(0.0,-0.5,-0.5); //左下
|
124
|
+
|
125
|
+
// glTexCoord2d(0.0,0.0); glVertex3d(0.0,0.0,-0.5); //左上
|
126
|
+
|
127
|
+
// glTexCoord2d(0.5,0.0); glVertex3d(0.5,0.0,-0.5); //右上
|
128
|
+
|
129
|
+
// glTexCoord2d(0.5,0.5); glVertex3d(0.5,-0.5,-0.5); //右下
|
130
|
+
|
131
|
+
// //右側
|
132
|
+
|
133
|
+
// glTexCoord2d(0.0,0.5); glVertex3d(0.5,-0.5,0.0); //左下
|
134
|
+
|
135
|
+
// glTexCoord2d(0.0,0.0); glVertex3d(0.5,0.0,0.0); //左上
|
136
|
+
|
137
|
+
// glTexCoord2d(0.5,0.0); glVertex3d(0.5,0,-0.5); //右上
|
138
|
+
|
139
|
+
// glTexCoord2d(0.5,0.5); glVertex3d(0.5,-0.5,-0.5); //右下
|
140
|
+
|
141
|
+
// //手前側
|
142
|
+
|
143
|
+
// glTexCoord2d(0.0,0.5); glVertex3d(0.0,-0.5,0.0); //左下
|
144
|
+
|
145
|
+
// glTexCoord2d(0.0,0.0); glVertex3d(0.0,0.0,0.0); //左上
|
146
|
+
|
147
|
+
// glTexCoord2d(0.5,0.0); glVertex3d(0.5,0.0,0.0); //右上
|
148
|
+
|
149
|
+
// glTexCoord2d(0.5,0.5); glVertex3d(0.5,-0.5,0.0); //右下
|
150
|
+
|
151
|
+
glEnd();
|
152
|
+
|
153
|
+
glDisable(GL_TEXTURE_2D);
|
154
|
+
|
155
|
+
// --------- テクスチャマッピング終了 -------------
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
void display(void){ // ディスプレイコールバック関数
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
// -------いつも必要な関数----------------
|
164
|
+
|
165
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //デプスバッファの設定(隠面消去のため)
|
166
|
+
|
167
|
+
glEnable(GL_DEPTH_TEST);
|
168
|
+
|
169
|
+
glPushMatrix();
|
170
|
+
|
171
|
+
// ------------------------------------
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
gluLookAt(3.0, 3.0, 5.0, // 視点の位置
|
176
|
+
|
177
|
+
0.0, 0.0, 0.0, // 見たいものの位置
|
178
|
+
|
179
|
+
0.0, 1.0, 0.0); // 画像のどこが上なのかを指定(ベクトル)
|
180
|
+
|
181
|
+
glColor4f(0.0,0.0,0.0,1.0);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
// --------- 外側の直方体 回転 ------------------
|
186
|
+
|
187
|
+
glPushMatrix(); //現在の座標系を保存
|
188
|
+
|
189
|
+
glRotatef(45.0*(float)param_big,1.0,0.0,0.0); //座標系をy軸周りに(45 × i)度回転
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
glPushMatrix(); //回転した状態の座標系を保存
|
196
|
+
|
197
|
+
glTranslatef(0.0,0.0,-1.0); //座標系を平行移動
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
//課題2
|
202
|
+
|
203
|
+
glPushMatrix(); //現在の座標系を保存
|
204
|
+
|
205
|
+
glRotatef(-45.0*(float)param_big,1.0,0.0,0.0); //座標系をy軸周りに(45 × i)度回転
|
206
|
+
|
207
|
+
// --------------------------------------------
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
//立方体の描画(外側)
|
212
|
+
|
213
|
+
glLineWidth(2.0);
|
214
|
+
|
215
|
+
glutWireCube(2.0);
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
glPopMatrix(); //平行移動前の座標系を復元
|
220
|
+
|
221
|
+
glPopMatrix(); //平行移動も回転もしていない元の座標系を復元
|
222
|
+
|
223
|
+
glPopMatrix();
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
// 照明をON
|
228
|
+
|
229
|
+
// glEnable(GL_LIGHT0);
|
230
|
+
|
231
|
+
// glEnable(GL_LIGHTING);
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
//表面属性の設定
|
236
|
+
|
237
|
+
glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);
|
238
|
+
|
239
|
+
glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
|
240
|
+
|
241
|
+
glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);
|
242
|
+
|
243
|
+
glMaterialf(GL_FRONT,GL_SHININESS,shininess);
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
// ------ 中心の直方体 回転 -----------
|
250
|
+
|
251
|
+
glPushMatrix(); //現在の座標系を保存
|
252
|
+
|
253
|
+
glRotatef(-45.0*(float)param_small,1.0,0.0,0.0); //座標系をy軸周りに(45 × i)度回転
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
glPushMatrix(); //回転した状態の座標系を保存
|
260
|
+
|
261
|
+
glTranslatef(0.0,0.0,-1.0); //座標系を平行移動
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
glPushMatrix(); //現在の座標系を保存
|
266
|
+
|
267
|
+
glRotatef(45.0*(float)param_small,1.0,0.0,0.0); //座標系をy軸周りに(45 × i)度回転
|
268
|
+
|
269
|
+
// ----------------------------
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
texture_map();
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
glPopMatrix(); //平行移動前の座標系を復元
|
278
|
+
|
279
|
+
glPopMatrix(); //平行移動も回転もしていない元の座標系を復元
|
280
|
+
|
281
|
+
glPopMatrix();
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
glPopMatrix(); //座標系の復帰
|
286
|
+
|
287
|
+
glDisable(GL_DEPTH_TEST); //デプスバッファ更新を無効にする(隠面消去OFF)
|
288
|
+
|
289
|
+
glutSwapBuffers();
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
void myReshape(int width, int height){
|
294
|
+
|
295
|
+
double aspect = (double)width/(double)height;
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
glViewport(0,0,width,height);
|
300
|
+
|
301
|
+
glMatrixMode(GL_PROJECTION);
|
302
|
+
|
303
|
+
glLoadIdentity();
|
304
|
+
|
305
|
+
gluPerspective(30.0,aspect,1.0,100.0); //透視投影の設定
|
306
|
+
|
307
|
+
glMatrixMode(GL_MODELVIEW);
|
308
|
+
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
void myMouse(int button,int state, int x,int y){ //マウスコールバック関数
|
314
|
+
|
315
|
+
if(state == GLUT_DOWN){
|
316
|
+
|
317
|
+
switch(button){
|
318
|
+
|
319
|
+
case GLUT_LEFT_BUTTON:
|
320
|
+
|
321
|
+
exit(-1);break;
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
void init(char *progname){ //初期化関数
|
330
|
+
|
331
|
+
int width = 500, height = 500;
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
glutInitWindowPosition(0,0);
|
336
|
+
|
337
|
+
glutInitWindowSize(width,height);
|
338
|
+
|
339
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); //デプスバッファの設定(隠面消去のため)
|
340
|
+
|
341
|
+
glutCreateWindow(progname);
|
342
|
+
|
343
|
+
glClearColor(1.0,1.0,1.0,1.0);
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
//テクスチャ画像の読み込み
|
348
|
+
|
349
|
+
GLubyte texture[TEXHEIGHT][TEXWIDTH][3];
|
350
|
+
|
351
|
+
FILE *fp;
|
352
|
+
|
353
|
+
if((fp=fopen("./image01.data","rb")) != NULL){
|
354
|
+
|
355
|
+
fread(texture, sizeof texture, 1,fp);
|
356
|
+
|
357
|
+
fclose(fp);
|
358
|
+
|
359
|
+
}else{
|
360
|
+
|
361
|
+
// 任意のエラー処理を記述
|
362
|
+
|
363
|
+
perror(texture1);
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
glPixelStorei(GL_UNPACK_ALIGNMENT,1); //アライメント(データの格納方法)の設定
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXWIDTH, TEXHEIGHT, 0,
|
372
|
+
|
373
|
+
GL_RGB, GL_UNSIGNED_BYTE, texture); //画像データをテクスチャメモリにセットする
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
//テクスチャパラメータの設定(テクスチャマッピングの拡大・縮小法の設定)
|
378
|
+
|
379
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
380
|
+
|
381
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
//テクスチャの合成環境の設定(ポリゴンの陰影等をテクスチャに反映する等の設定)
|
386
|
+
|
387
|
+
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
void idle(void){
|
394
|
+
|
395
|
+
param_big +=0.1;
|
396
|
+
|
397
|
+
param_small += 0.05;
|
398
|
+
|
399
|
+
glutPostRedisplay();
|
400
|
+
|
401
|
+
}
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
int main(int argc,char *argv[]){ //メイン関数
|
406
|
+
|
407
|
+
glutInit(&argc,argv);
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
init(argv[0]);
|
412
|
+
|
413
|
+
glutReshapeFunc(myReshape);
|
414
|
+
|
415
|
+
glutDisplayFunc(display);
|
416
|
+
|
417
|
+
glutKeyboardFunc(myKbd);
|
418
|
+
|
419
|
+
glutMouseFunc(myMouse);
|
420
|
+
|
421
|
+
//課題3
|
422
|
+
|
423
|
+
glutIdleFunc(idle);
|
424
|
+
|
425
|
+
glutMainLoop();
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
return 0;
|
430
|
+
|
431
|
+
}
|
432
|
+
|
11
433
|
|
12
434
|
|
13
435
|
```
|
14
436
|
|
15
|
-
|
437
|
+
|
16
|
-
|
17
|
-
|
438
|
+
|
18
|
-
|
19
|
-
```
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
###該当のソースコード
|
24
|
-
|
25
|
-
```c
|
26
|
-
|
27
|
-
#include <stdio.h>
|
28
|
-
|
29
|
-
#include <GLUT/glut.h>
|
30
|
-
|
31
|
-
#include <stdlib.h>
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
#define KEY_ESC 27
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
/*Gold*/
|
40
|
-
|
41
|
-
float diffuse[]={0.7, 0.6, 0.2, 1.0}; //拡散反射成分(R,G,B,A強度0.0〜1.0)
|
42
|
-
|
43
|
-
float specular[]={0.6, 0.5, 0.4, 1.0}; //鏡面反射成分(R,G,B,A強度0.0〜1.0)
|
44
|
-
|
45
|
-
float ambient[]={0.3,0.2,0.1,1.0}; //環境光反射成分(R,G,B,A強度0.0〜1.0)
|
46
|
-
|
47
|
-
float shininess=10.0; //鏡面光の鋭さ(0.0〜128.0)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
double param_big = 0.0;
|
52
|
-
|
53
|
-
double param_small = 0.5;
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
/* Texture */
|
58
|
-
|
59
|
-
#define TEXWIDTH 256
|
60
|
-
|
61
|
-
#define TEXHEIGHT 256
|
62
|
-
|
63
|
-
static const char texture1[] = "./motya.data";
|
64
|
-
|
65
|
-
//static const char texture2[] = "sample.data";
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
void myKbd(unsigned char key,int x, int y){
|
70
|
-
|
71
|
-
if(key==KEY_ESC)exit(0);
|
72
|
-
|
73
|
-
}
|
74
|
-
|
75
|
-
void texture_map(void){
|
76
|
-
|
77
|
-
// --------- テクスチャマッピング開始 -------------
|
78
|
-
|
79
|
-
glEnable(GL_TEXTURE_2D);
|
80
|
-
|
81
|
-
glNormal3d(0.0,0.0,1.0); //法線ベクトルの設定
|
82
|
-
|
83
|
-
glBegin(GL_QUADS);
|
84
|
-
|
85
|
-
//上面
|
86
|
-
|
87
|
-
glTexCoord2d(0.0,0.5); glVertex3d(0.0,0.0,0.0); //左下
|
88
|
-
|
89
|
-
glTexCoord2d(0.0,0.0); glVertex3d(0,0,-0.5); //左上
|
90
|
-
|
91
|
-
glTexCoord2d(0.5,0.0); glVertex3d(0.5,0,-0.5); //右上
|
92
|
-
|
93
|
-
glTexCoord2d(0.5,0.5); glVertex3d(0.5,0.0,0.0); //右下
|
94
|
-
|
95
|
-
//底面
|
96
|
-
|
97
|
-
glTexCoord2d(0.0,0.5); glVertex3d(0,-0.5,0); //左下
|
98
|
-
|
99
|
-
glTexCoord2d(0.0,0.0); glVertex3d(0,-0.5,-0.5); //左上
|
100
|
-
|
101
|
-
glTexCoord2d(0.5,0.0); glVertex3d(0.5,-0.5,-0.5); //右上
|
102
|
-
|
103
|
-
glTexCoord2d(0.5,0.5); glVertex3d(0.5,-0.5,0.0); //右下
|
104
|
-
|
105
|
-
//左側
|
106
|
-
|
107
|
-
glTexCoord2d(0.0,0.5); glVertex3d(0.0,-0.5,0.0); //左下
|
108
|
-
|
109
|
-
glTexCoord2d(0.0,0.0); glVertex3d(0.0,0.0,0.0); //左上
|
110
|
-
|
111
|
-
glTexCoord2d(0.5,0.0); glVertex3d(0.0,0.0,-0.5); //右上
|
112
|
-
|
113
|
-
glTexCoord2d(0.5,0.5); glVertex3d(0.0,-0.5,-0.5); //右下
|
114
|
-
|
115
|
-
//奥側
|
116
|
-
|
117
|
-
glTexCoord2d(0.0,0.5); glVertex3d(0.0,-0.5,-0.5); //左下
|
118
|
-
|
119
|
-
glTexCoord2d(0.0,0.0); glVertex3d(0.0,0.0,-0.5); //左上
|
120
|
-
|
121
|
-
glTexCoord2d(0.5,0.0); glVertex3d(0.5,0.0,-0.5); //右上
|
122
|
-
|
123
|
-
glTexCoord2d(0.5,0.5); glVertex3d(0.5,-0.5,-0.5); //右下
|
124
|
-
|
125
|
-
//右側
|
126
|
-
|
127
|
-
glTexCoord2d(0.0,0.5); glVertex3d(0.5,-0.5,0.0); //左下
|
128
|
-
|
129
|
-
glTexCoord2d(0.0,0.0); glVertex3d(0.5,0.0,0.0); //左上
|
130
|
-
|
131
|
-
glTexCoord2d(0.5,0.0); glVertex3d(0.5,0,-0.5); //右上
|
132
|
-
|
133
|
-
glTexCoord2d(0.5,0.5); glVertex3d(0.5,-0.5,-0.5); //右下
|
134
|
-
|
135
|
-
//手前側
|
136
|
-
|
137
|
-
glTexCoord2d(0.0,0.5); glVertex3d(0.0,-0.5,0.0); //左下
|
138
|
-
|
139
|
-
glTexCoord2d(0.0,0.0); glVertex3d(0.0,0.0,0.0); //左上
|
140
|
-
|
141
|
-
glTexCoord2d(0.5,0.0); glVertex3d(0.5,0.0,0.0); //右上
|
142
|
-
|
143
|
-
glTexCoord2d(0.5,0.5); glVertex3d(0.5,-0.5,0.0); //右下
|
144
|
-
|
145
|
-
glEnd();
|
146
|
-
|
147
|
-
glDisable(GL_TEXTURE_2D);
|
148
|
-
|
149
|
-
// --------- テクスチャマッピング終了 -------------
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
void display(void){ // ディスプレイコールバック関数
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
// -------いつも必要な関数----------------
|
158
|
-
|
159
|
-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //デプスバッファの設定(隠面消去のため)
|
160
|
-
|
161
|
-
glEnable(GL_DEPTH_TEST);
|
162
|
-
|
163
|
-
glPushMatrix();
|
164
|
-
|
165
|
-
// ------------------------------------
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
gluLookAt(3.0, 3.0, 5.0, // 視点の位置
|
170
|
-
|
171
|
-
0.0, 0.0, 0.0, // 見たいものの位置
|
172
|
-
|
173
|
-
0.0, 1.0, 0.0); // 画像のどこが上なのかを指定(ベクトル)
|
174
|
-
|
175
|
-
glColor4f(0.0,0.0,0.0,1.0);
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
texture_map();
|
180
|
-
|
181
|
-
// --------- 外側の直方体 回転 ------------------
|
182
|
-
|
183
|
-
glPushMatrix(); //現在の座標系を保存
|
184
|
-
|
185
|
-
glRotatef(45.0*(float)param_big,1.0,0.0,0.0); //座標系をy軸周りに(45 × i)度回転
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
glPushMatrix(); //回転した状態の座標系を保存
|
192
|
-
|
193
|
-
glTranslatef(0.0,0.0,-1.0); //座標系を平行移動
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
//課題2
|
198
|
-
|
199
|
-
glPushMatrix(); //現在の座標系を保存
|
200
|
-
|
201
|
-
glRotatef(-45.0*(float)param_big,1.0,0.0,0.0); //座標系をy軸周りに(45 × i)度回転
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
//立方体の描画(外側)
|
206
|
-
|
207
|
-
glLineWidth(2.0);
|
208
|
-
|
209
|
-
glutWireCube(2.0);
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
glPopMatrix(); //平行移動前の座標系を復元
|
214
|
-
|
215
|
-
glPopMatrix(); //平行移動も回転もしていない元の座標系を復元
|
216
|
-
|
217
|
-
glPopMatrix();
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
// 照明をON
|
222
|
-
|
223
|
-
// glEnable(GL_LIGHT0);
|
224
|
-
|
225
|
-
// glEnable(GL_LIGHTING);
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
//表面属性の設定
|
230
|
-
|
231
|
-
glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);
|
232
|
-
|
233
|
-
glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
|
234
|
-
|
235
|
-
glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);
|
236
|
-
|
237
|
-
glMaterialf(GL_FRONT,GL_SHININESS,shininess);
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
// ------ 中心の直方体 回転 -----------
|
242
|
-
|
243
|
-
glPushMatrix(); //現在の座標系を保存
|
244
|
-
|
245
|
-
glRotatef(-45.0*(float)param_small,1.0,0.0,0.0); //座標系をy軸周りに(45 × i)度回転
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
glPushMatrix(); //回転した状態の座標系を保存
|
252
|
-
|
253
|
-
glTranslatef(0.0,0.0,-1.0); //座標系を平行移動
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
//課題2
|
258
|
-
|
259
|
-
glPushMatrix(); //現在の座標系を保存
|
260
|
-
|
261
|
-
glRotatef(45.0*(float)param_small,1.0,0.0,0.0); //座標系をy軸周りに(45 × i)度回転
|
262
|
-
|
263
|
-
// ----------------------------
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
glPopMatrix(); //平行移動前の座標系を復元
|
268
|
-
|
269
|
-
glPopMatrix(); //平行移動も回転もしていない元の座標系を復元
|
270
|
-
|
271
|
-
glPopMatrix();
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
glPopMatrix(); //座標系の復帰
|
276
|
-
|
277
|
-
glDisable(GL_DEPTH_TEST); //デプスバッファ更新を無効にする(隠面消去OFF)
|
278
|
-
|
279
|
-
glutSwapBuffers();
|
280
|
-
|
281
|
-
}
|
282
|
-
|
283
|
-
void myReshape(int width, int height){
|
284
|
-
|
285
|
-
double aspect = (double)width/(double)height;
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
glViewport(0,0,width,height);
|
290
|
-
|
291
|
-
glMatrixMode(GL_PROJECTION);
|
292
|
-
|
293
|
-
glLoadIdentity();
|
294
|
-
|
295
|
-
gluPerspective(30.0,aspect,1.0,100.0); //透視投影の設定
|
296
|
-
|
297
|
-
glMatrixMode(GL_MODELVIEW);
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
void myMouse(int button,int state, int x,int y){ //マウスコールバック関数
|
304
|
-
|
305
|
-
if(state == GLUT_DOWN){
|
306
|
-
|
307
|
-
switch(button){
|
308
|
-
|
309
|
-
case GLUT_LEFT_BUTTON:
|
310
|
-
|
311
|
-
exit(-1);break;
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
void init(char *progname){ //初期化関数
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
//テクスチャ画像の読み込み
|
324
|
-
|
325
|
-
GLubyte texture[TEXHEIGHT][TEXWIDTH][3];
|
326
|
-
|
327
|
-
FILE *fp;
|
328
|
-
|
329
|
-
if((fp=fopen(texture1,"rb")) != NULL){
|
330
|
-
|
331
|
-
fread(texture, sizeof texture, 1,fp);
|
332
|
-
|
333
|
-
fclose(fp);
|
334
|
-
|
335
|
-
}else{
|
336
|
-
|
337
|
-
// 任意のエラー処理を記述
|
338
|
-
|
339
|
-
printf("texture not founed");
|
340
|
-
|
341
|
-
}
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
glPixelStorei(GL_UNPACK_ALIGNMENT,1); //アライメント(データの格納方法)の設定
|
346
|
-
|
347
|
-
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,TEXWIDTH,TEXHEIGHT,0,GL_RGB,
|
348
|
-
|
349
|
-
GL_UNSIGNED_BYTE, texture); //画像データをテクスチャメモリにセットする
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
//テクスチャパラメータの設定(テクスチャマッピングの拡大・縮小法の設定)
|
354
|
-
|
355
|
-
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
356
|
-
|
357
|
-
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
//テクスチャの合成環境の設定(ポリゴンの陰影等をテクスチャに反映する等の設定)
|
362
|
-
|
363
|
-
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
int width = 500, height = 500;
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
glutInitWindowPosition(0,0);
|
372
|
-
|
373
|
-
glutInitWindowSize(width,height);
|
374
|
-
|
375
|
-
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); //デプスバッファの設定(隠面消去のため)
|
376
|
-
|
377
|
-
glutCreateWindow(progname);
|
378
|
-
|
379
|
-
glClearColor(1.0,1.0,1.0,1.0);
|
380
|
-
|
381
|
-
}
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
void idle(void){
|
386
|
-
|
387
|
-
param_big +=0.1;
|
388
|
-
|
389
|
-
param_small += 0.05;
|
390
|
-
|
391
|
-
glutPostRedisplay();
|
392
|
-
|
393
|
-
}
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
int main(int argc,char *argv[]){ //メイン関数
|
398
|
-
|
399
|
-
glutInit(&argc,argv);
|
400
|
-
|
401
|
-
init(argv[0]);
|
402
|
-
|
403
|
-
glutReshapeFunc(myReshape);
|
404
|
-
|
405
|
-
glutDisplayFunc(display);
|
406
|
-
|
407
|
-
glutKeyboardFunc(myKbd);
|
408
|
-
|
409
|
-
glutMouseFunc(myMouse);
|
410
|
-
|
411
|
-
//課題3
|
412
|
-
|
413
|
-
glutIdleFunc(idle);
|
414
|
-
|
415
|
-
glutMainLoop();
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
return 0;
|
420
|
-
|
421
|
-
}
|
422
|
-
|
423
|
-
```
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
###
|
439
|
+
### 実行結果
|
428
|
-
|
429
|
-
|
440
|
+
|
430
|
-
|
431
|
-
|
441
|
+

|
432
|
-
|
433
|
-
この関数の理解が出来ておりません。
|
434
442
|
|
435
443
|
|
436
444
|
|
1
情報追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -90,7 +90,7 @@
|
|
90
90
|
|
91
91
|
glTexCoord2d(0.5,0.0); glVertex3d(0.5,0,-0.5); //右上
|
92
92
|
|
93
|
-
glTexCoord2d(0.5,0.5); glVertex3d(0.5,0,0); //右下
|
93
|
+
glTexCoord2d(0.5,0.5); glVertex3d(0.5,0.0,0.0); //右下
|
94
94
|
|
95
95
|
//底面
|
96
96
|
|
@@ -426,7 +426,11 @@
|
|
426
426
|
|
427
427
|
###試したこと
|
428
428
|
|
429
|
+
glTexCoord2d(x,y,z);
|
430
|
+
|
429
|
-
|
431
|
+
この部分は異なった面毎に座標を変えなければならないのでしょうか?
|
432
|
+
|
433
|
+
この関数の理解が出来ておりません。
|
430
434
|
|
431
435
|
|
432
436
|
|