annotate Renderer/Engine/viewerGL.cc @ 960:418939c6837d draft

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