質問編集履歴
1
文章の訂正 ソースコードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,69 @@
|
|
1
1
|
現在、openGLでアニメーションを作る授業をしています。
|
2
2
|
gccを使って作成しています。そこで球を横に回転させていのですが、
|
3
3
|
ソースコードが分からないです。
|
4
|
-
|
4
|
+
このプログラムだと真っ暗になってしまいます。
|
5
|
+
どこを変えたら表示されるようになりますか。
|
6
|
+
|
7
|
+
#include <stdlib.h>
|
8
|
+
#include "GL/glut.h"
|
9
|
+
#include <GL/gl.h>
|
10
|
+
#include <GL/glu.h>
|
11
|
+
#include <math.h>
|
12
|
+
#define KEY_ESC 27
|
13
|
+
|
14
|
+
float theta =0.0; /*物体の回転角度*/
|
15
|
+
|
16
|
+
void display(void)
|
17
|
+
{
|
18
|
+
glClear(GL_COLOR_BUFFER_BIT);
|
19
|
+
|
20
|
+
glPushMatrix();
|
21
|
+
glTranslatef(0.0,1.0,30.0);
|
22
|
+
glRotatef(3.0*theta,0.2,-1.0,0.0);
|
23
|
+
glRotatef(-90.0,1.0,0.2,0.0);
|
24
|
+
glColor3f(1.0,1.0,0.0);
|
25
|
+
glutWireSphere(1.0,15,15); /*球*/
|
26
|
+
glPopMatrix();
|
27
|
+
|
28
|
+
glutSwapBuffers();/*バッファをスワップする*/
|
29
|
+
}
|
30
|
+
|
31
|
+
void idle(void)/*イベントがなければidleがつねに実行される*/
|
32
|
+
{
|
33
|
+
theta=fmod(theta+0.1,360.0);/*回転角を0°~360°まで0.5°づつ増加させる)*/
|
34
|
+
glutPostRedisplay();/*ディスプレイコールバックバック関数(display)を実行*/
|
35
|
+
}
|
36
|
+
|
37
|
+
void myKbd(unsigned char key,int x,int y)
|
38
|
+
{
|
39
|
+
if(key == KEY_ESC) exit(0);
|
40
|
+
}
|
41
|
+
|
42
|
+
void myInit(char *progname)
|
43
|
+
{
|
44
|
+
int width=500,height=500;
|
45
|
+
float aspect =(float)width/(float)height;
|
46
|
+
|
47
|
+
glutInitWindowPosition(0,0);
|
48
|
+
glutInitWindowSize(width,height);
|
49
|
+
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
|
50
|
+
/*ダブルバッファの宣言*/
|
51
|
+
glutCreateWindow(progname);
|
52
|
+
glClearColor(0.0,0.0,0.0,1.0);
|
53
|
+
glutKeyboardFunc(myKbd);
|
54
|
+
glMatrixMode(GL_PROJECTION);
|
55
|
+
glLoadIdentity();
|
56
|
+
gluPerspective(45.0,aspect,1.0,10.0);
|
57
|
+
glMatrixMode(GL_MODELVIEW);
|
58
|
+
}
|
59
|
+
|
60
|
+
int main (int argc, char** argv)
|
61
|
+
{
|
62
|
+
glutInit(&argc,argv);
|
63
|
+
myInit(argv[0]);
|
64
|
+
glutDisplayFunc(display);
|
65
|
+
glutIdleFunc(idle);
|
66
|
+
/*イベントが無い場合にはidleを繰り返し実行する*/
|
67
|
+
glutMainLoop();
|
68
|
+
return(0);
|
69
|
+
}
|