annotate Renderer/Engine/viewerGL.cc @ 1379:13065ad17328 draft

collada moved but only my mac.
author e095732 <e095732@ie.u-ryukyu.ac.jp>
date Thu, 26 Jan 2012 21:56:32 +0900
parents ab9b7d21b32b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "viewerGL.h"
1128
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
2 #include "polygon_pack.h"
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 static void
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 ApplyMatrix(float *v, float *m)
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 {
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
8 float t[4];
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
10 t[0] = v[0];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
11 t[1] = v[1];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
12 t[2] = v[2];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
13 t[3] = v[3];
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
15 for (int i = 0; i < 4; i++) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
16 v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8] + t[3]*m[i+12];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
17 }
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 }
1042
d0bb27bf985b AllExecute speparation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1031
diff changeset
19 #if 0
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 static void
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 ApplyNormalMatrix(float *v, float *m)
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 {
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
23 float t[4];
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
25 t[0] = v[0];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
26 t[1] = v[1];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
27 t[2] = v[2];
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
29 for (int i = 0; i < 3; i++) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
30 v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
31 }
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 }
1042
d0bb27bf985b AllExecute speparation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1031
diff changeset
33 #endif
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
35 ViewerGL::ViewerGL(TaskManager *m, int b, int w, int h, int _num)
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 {
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
37 spe_num = _num;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
38 manager = m;
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
40 quit_flag = false;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
41 start_time = 0;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
42 this_time = 0;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
43 frames = 0;
927
fada580e4604 remove garbage codes from viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 922
diff changeset
44
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 video_init(b, w, h);
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 void
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
49 ViewerGL::video_init(int bpp, int width, int height)
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 {
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
51 SDL_Surface *screen;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
52 int rgb_size[3];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
53 int value = 1;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
54 Uint32 sdl_flag = SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
55 Uint32 video_flag = SDL_OPENGL;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
56
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
57 if (SDL_Init(sdl_flag) < 0) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
58 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
59 exit(1);
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
61
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
62 /* See if we should detect the display depth */
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
63 if ( bpp == 0 )
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
64 {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
65 if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 )
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
66 {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
67 bpp = 8;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
68 }
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
69 else
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
70 {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
71 bpp = 32;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
72 }
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
73 }
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
74
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
75 /* Initialize the bpp */
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
76 switch (bpp)
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
77 {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
78 case 8:
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
79 rgb_size[0] = 3;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
80 rgb_size[1] = 3;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
81 rgb_size[2] = 2;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
82 break;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
83 case 15:
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
84 case 16:
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
85 rgb_size[0] = 5;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
86 rgb_size[1] = 5;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
87 rgb_size[2] = 5;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
88 break;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
89 default:
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
90 rgb_size[0] = 8;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
91 rgb_size[1] = 8;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
92 rgb_size[2] = 8;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
93 break;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
94 }
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
95
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
96 screen = SDL_SetVideoMode(width, height, bpp, video_flag);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
97 if (screen == NULL) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
98 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
99 SDL_Quit();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
100 exit(1);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
101 }
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
102 this->width = screen->w;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
103 this->height = screen->h;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
104 this->bpp = screen->format->BitsPerPixel;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
105
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
106 //各パラメータがちゃんと取れているか確認
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
107 printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
108 printf("\n");
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
109 printf( "Vendor : %s\n", glGetString( GL_VENDOR ) );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
110 printf( "Renderer : %s\n", glGetString( GL_RENDERER ) );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
111 printf( "Version : %s\n", glGetString( GL_VERSION ) );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
112 printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
113 printf("\n");
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
114
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
115 SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
116 printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
117 SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
118 printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
119 SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
120 printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
121 SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
122 printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
123 SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
124 printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
125
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
126 //OpenGLの設定
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
127 glViewport( 0, 0, width, height );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
128 glMatrixMode( GL_PROJECTION );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
129 glLoadIdentity( );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
130
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
131 //正射影
1031
92185a81e94b OpenGL mode fix
Yutaka_Kinjyo
parents: 960
diff changeset
132 //glOrtho( 0.0, width, height, 0.0, OPENGL_PARAM::near, OPENGL_PARAM::far );
92185a81e94b OpenGL mode fix
Yutaka_Kinjyo
parents: 960
diff changeset
133 glOrtho( 0.0, width, height, 0.0, OPENGL_PARAM::far, OPENGL_PARAM::near );
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
134
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
135 glMatrixMode( GL_MODELVIEW );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
136 glLoadIdentity( );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
137
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
138 //アルファブレンディング
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
139 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
140
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
141 //光源
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
142 glLightfv(GL_LIGHT0, GL_AMBIENT, OPENGL_PARAM::lightAmbient);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
143 glLightfv(GL_LIGHT0, GL_DIFFUSE, OPENGL_PARAM::lightDiffuse);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
144 glLightfv(GL_LIGHT0, GL_SPECULAR, OPENGL_PARAM::lightSpecular);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
145 glLightfv(GL_LIGHT0, GL_POSITION, OPENGL_PARAM::lightPosition);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
146
960
418939c6837d success alpha blending neatly
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 959
diff changeset
147 glEnable(GL_DEPTH_TEST);
418939c6837d success alpha blending neatly
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 959
diff changeset
148 glEnable(GL_ALPHA_TEST);
418939c6837d success alpha blending neatly
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 959
diff changeset
149 glAlphaFunc(GL_GREATER, 0);
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
150 glDepthFunc(GL_LESS);
1031
92185a81e94b OpenGL mode fix
Yutaka_Kinjyo
parents: 960
diff changeset
151 //glShadeModel(GL_SMOOTH);
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 void
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
155 ViewerGL::mainLoop()
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 {
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
157 glEnable(GL_LIGHTING);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
158 glEnable(GL_LIGHT0);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
159 glEnable(GL_BLEND);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
160
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
161 while(!quit_flag) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
162 run_loop();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
163 }
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 void
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
167 ViewerGL::run_loop()
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 {
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
169 clear_screen();
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
171 quit_flag = quit_check();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
172 if (quit_flag == true) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
173 this_time = get_ticks();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
174 run_finish();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
175 return;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
176 }
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
177
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
178 clean_pixels();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
179
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
180 sgroot->updateControllerState();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
181 sgroot->allExecute(width, height);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
182 light_xyz_stock = sgroot->getLightVector();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
183 light_switch_stock = sgroot->getLightSwitch();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
184 light_sysswitch_stock = sgroot->getLightSysSwitch();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
185 pickup_vertex();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
186
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
187 psx_sync_n();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
188 frames++;
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 void
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
192 ViewerGL::pickup_vertex()
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 {
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
194 float xyz1[4], xyz2[4], xyz3[4];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
195 float tex_xy1[2], tex_xy2[2], tex_xy3[2];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
196 float normal1[4],normal2[4],normal3[4];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
197 GLuint texture;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
198
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
199 SceneGraphPtr sg_top = sgroot->getDrawSceneGraph();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
200 SceneGraphPtr sg = sg_top;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
201
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
202 while (sg) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
203 if (sg->flag_drawable) {
1130
root@dolphins.cr.ie.u-ryukyu.ac.jp
parents: 1128
diff changeset
204 if (!sg->texture_info->gl_tex) {
root@dolphins.cr.ie.u-ryukyu.ac.jp
parents: 1128
diff changeset
205 sg->texture_info->gl_tex = SDL_GL_LoadTexture(sg->texture_info->texture_image);
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
206 }
1302
ab9b7d21b32b removed real_matrix. sparated screen matrix from camera matrix.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 1130
diff changeset
207
ab9b7d21b32b removed real_matrix. sparated screen matrix from camera matrix.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 1130
diff changeset
208 float normal_matrix[16];
ab9b7d21b32b removed real_matrix. sparated screen matrix from camera matrix.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 1130
diff changeset
209
ab9b7d21b32b removed real_matrix. sparated screen matrix from camera matrix.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 1130
diff changeset
210 for (int i = 0; i<16; i++) normal_matrix[i]=sg->matrix[i];
ab9b7d21b32b removed real_matrix. sparated screen matrix from camera matrix.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 1130
diff changeset
211 normal_matrix[4*0+3]=normal_matrix[4*1+3]=normal_matrix[4*2+3]=0;
ab9b7d21b32b removed real_matrix. sparated screen matrix from camera matrix.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 1130
diff changeset
212
1130
root@dolphins.cr.ie.u-ryukyu.ac.jp
parents: 1128
diff changeset
213 texture = sg->texture_info->gl_tex;
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
214 glBindTexture(GL_TEXTURE_2D, texture);
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
216 glEnable(GL_TEXTURE_2D);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
217 glBegin( GL_TRIANGLES);
1128
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
218
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
219 for (int i = 0; i < sg->pp_num; i++) {
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
220 for (int j = 0; j < sg->pp[i].info.size; j++) {
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
221 TrianglePack tri = sg->pp[i].tri[j];
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
222
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
223 xyz1[0] = tri.ver1.x;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
224 xyz1[1] = tri.ver1.y;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
225 xyz1[2] = tri.ver1.z * -1.0f;
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
226 xyz1[3] = 1.0f;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
227
1128
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
228 xyz2[0] = tri.ver2.x;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
229 xyz2[1] = tri.ver2.y;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
230 xyz2[2] = tri.ver2.z * -1.0f;
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
231 xyz2[3] = 1.0f;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
232
1128
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
233 xyz3[0] = tri.ver3.x;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
234 xyz3[1] = tri.ver3.y;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
235 xyz3[2] = tri.ver3.z * -1.0f;
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
236 xyz3[3] = 1.0f;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
237
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
238 // sg->matrix = 回転行列*透視変換行列
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
239 ApplyMatrix(xyz1, sg->matrix);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
240 ApplyMatrix(xyz2, sg->matrix);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
241 ApplyMatrix(xyz3, sg->matrix);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
242
1031
92185a81e94b OpenGL mode fix
Yutaka_Kinjyo
parents: 960
diff changeset
243
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
244 xyz1[0] /= xyz1[2];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
245 xyz1[1] /= xyz1[2];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
246 xyz2[0] /= xyz2[2];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
247 xyz2[1] /= xyz2[2];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
248 xyz3[0] /= xyz3[2];
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
249 xyz3[1] /= xyz3[2];
1031
92185a81e94b OpenGL mode fix
Yutaka_Kinjyo
parents: 960
diff changeset
250
1128
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
251 tex_xy1[0] = tri.ver1.tex_x;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
252 tex_xy1[1] = tri.ver1.tex_y;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
253 tex_xy2[0] = tri.ver2.tex_x;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
254 tex_xy2[1] = tri.ver2.tex_y;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
255 tex_xy3[0] = tri.ver3.tex_x;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
256 tex_xy3[1] = tri.ver3.tex_y;
1031
92185a81e94b OpenGL mode fix
Yutaka_Kinjyo
parents: 960
diff changeset
257
1128
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
258 normal1[0] = tri.normal1.x;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
259 normal1[1] = tri.normal1.y;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
260 normal1[2] = tri.normal1.z * -1.0f;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
261
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
262 normal1[3] = 0.0f;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
263
1128
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
264 normal2[0] = tri.normal2.x;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
265 normal2[1] = tri.normal2.y;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
266 normal2[2] = tri.normal2.z * -1.0f;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
267
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
268 normal2[3] = 0.0f;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
269
1128
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
270 normal3[0] = tri.normal3.x;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
271 normal3[1] = tri.normal3.y;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
272 normal3[2] = tri.normal3.z * -1.0f;
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
273
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
274 normal3[3] = 0.0f;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
275
1302
ab9b7d21b32b removed real_matrix. sparated screen matrix from camera matrix.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 1130
diff changeset
276 ApplyMatrix(normal1, normal_matrix);
ab9b7d21b32b removed real_matrix. sparated screen matrix from camera matrix.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 1130
diff changeset
277 ApplyMatrix(normal2, normal_matrix);
ab9b7d21b32b removed real_matrix. sparated screen matrix from camera matrix.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 1130
diff changeset
278 ApplyMatrix(normal3, normal_matrix);
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
279
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
280 obj_draw(xyz1, tex_xy1, normal1);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
281 obj_draw(xyz2, tex_xy2, normal2);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
282 obj_draw(xyz3, tex_xy3, normal3);
1128
293b36802714 code cleanup
Yutaka_Kinjyo
parents: 1042
diff changeset
283 }
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
284 }
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
285 glEnd( );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
286 glDisable(GL_TEXTURE_2D);
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 }
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
288
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
289 if (sg->children != NULL) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
290 sg = sg->children;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
291 } else if (sg->brother != NULL) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
292 sg = sg->brother;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
293 } else {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
294 while (sg) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
295 if (sg->brother != NULL) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
296 sg = sg->brother;
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 break;
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 } else {
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
299 if (sg->parent == NULL) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
300 sg = NULL;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
301 break;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
302 } else {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
303 sg = sg->parent;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
304 }
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 void
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
312 ViewerGL::obj_draw(float *xyz, float *tex_xyz, float *normal_xyz)
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 {
1031
92185a81e94b OpenGL mode fix
Yutaka_Kinjyo
parents: 960
diff changeset
314
92185a81e94b OpenGL mode fix
Yutaka_Kinjyo
parents: 960
diff changeset
315
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
316 glTexCoord2f(tex_xyz[0], tex_xyz[1]);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
317 glVertex3f(xyz[0], xyz[1], xyz[2]);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
318 glNormal3f(normal_xyz[0], normal_xyz[1], normal_xyz[2]);
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 void
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
322 ViewerGL::clean_pixels()
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 {
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
324 glClearColor( 0.0, 0.0, 0.0, 1.0 );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
325 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 void
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
329 ViewerGL::clear_screen()
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 {
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
331 GLenum gl_error;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
332 char* sdl_error;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
333
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
334 SDL_GL_SwapBuffers( );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
335
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
336 /* Check for error conditions. */
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
337 gl_error = glGetError( );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
338
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
339 if( gl_error != GL_NO_ERROR )
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
340 {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
341 fprintf( stderr, "OpenGL error: %d\n", gl_error );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
342 }
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
343
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
344 sdl_error = SDL_GetError( );
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
345
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
346 if( sdl_error[0] != '\0' )
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
347 {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
348 fprintf(stderr, "SDL error '%s'\n", sdl_error);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
349 SDL_ClearError();
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
350 }
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 void
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
354 ViewerGL::run_finish()
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 {
960
418939c6837d success alpha blending neatly
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 959
diff changeset
356 glDisable(GL_ALPHA_TEST);
418939c6837d success alpha blending neatly
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 959
diff changeset
357 glDisable(GL_DEPTH_TEST);
944
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
358 glDisable(GL_BLEND);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
359 glDisable(GL_LIGHT0);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
360 glDisable(GL_LIGHTING);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
361
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
362 if (this_time != start_time) {
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
363 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0);
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
364 }
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
365
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
366 delete sgroot;
0ab84d4c689a rename viewerGL
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents: 942
diff changeset
367 quit();
922
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 }
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369
cb1023423861 moving OpenGL mode now!
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 /* end */