annotate Renderer/Engine/viewerGL.cc @ 942:b2f7d2ad3804

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