Mercurial > hg > Game > Cerium
annotate Renderer/Engine/SceneGraph.cc @ 1211:7763f03a94e1 draft before-dma-manager
const char fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 22 Jul 2011 08:46:29 +0900 |
parents | 0ee23180d301 |
children | 636dfdc30176 |
rev | line source |
---|---|
539 | 1 #include <iostream> |
2 #include <SDL.h> | |
3 #include <SDL_opengl.h> | |
4 #include <SDL_image.h> | |
5 #include <libxml/parser.h> | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
6 #include <string.h> |
539 | 7 #include "SceneGraph.h" |
8 #include "xml.h" | |
1050 | 9 #include "matrix_calc.h" |
539 | 10 #include "TextureHash.h" |
11 #include "texture.h" | |
12 #include "TaskManager.h" | |
1125 | 13 #include "polygon_pack.h" |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
14 #include <ft2build.h> |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
15 #include <freetype/freetype.h> |
539 | 16 |
17 using namespace std; | |
18 | |
19 SceneGraphPtr scene_graph = NULL; | |
20 SceneGraphPtr scene_graph_viewer = NULL; | |
21 | |
22 static TextureHash texture_hash; | |
860 | 23 texture_list list[TABLE_SIZE]; |
24 | |
539 | 25 extern int decode(char *cont, FILE *outfile); |
26 | |
27 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
28 no_move(SceneGraphPtr self, void *sgroot_, int screen_w, int screen_h) {} |
539 | 29 |
30 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
31 no_collision(SceneGraphPtr self, void *sgroot_, int screen_w, int screen_h, |
539 | 32 SceneGraphPtr tree) {} |
33 | |
34 /** | |
35 * 事前に計算したテクスチャの最大縮小率 scale まで、 | |
36 * テクスチャを 1/2 縮小していく。 | |
37 * このとき、テクスチャは TEXTURE_SPLIT_PIXELx2 のブロック (Tile) で分割し、 | |
38 * これらを連続したメモリ領域に格納していく。 | |
39 * 以下の (1), (2), (3) を Tapestry と呼ぶ | |
40 * | |
41 * 例 scale = 4 の場合 | |
42 * | |
43 * Tapestry(1) 1/1 | |
44 * +---+---+---+---+ | |
45 * | 0 | 1 | 2 | 3 | | |
46 * +---+---+---+---+ | |
47 * | 4 | 5 | 6 | 7 | (2) 1/2 | |
48 * +---+---+---+---+ +---+---+ | |
49 * | 8 | 9 | 10| 11| | 16| 17| (3) 1/4 | |
50 * +---+---+---+---+ +---+---+ +---+ | |
51 * | 12| 13| 14| 15| | 18| 19| | 20| | |
52 * +---+---+---+---+ +---+---+ +---| | |
53 * | |
54 * (1) (2) (3) | |
55 * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | |
56 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * | * | * | 14| 15| 16| 17| 18| 19| 20| | |
57 * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | |
58 * | |
59 * @param[in] tex_w Width of orignal texture | |
60 * @param[in] tex_h Height of orignal texture | |
61 * @param[in] tex_src Original texture | |
62 * @param[in] all_pixel_num Tapestry の合計 pixel 数 | |
63 * @param[in] scale テクスチャの最大縮小率 (= 2^n) | |
64 * @return (1) のアドレス | |
65 */ | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
66 |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
67 |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
68 uint32 white[256] __attribute__((aligned(16))); |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
69 |
539 | 70 static uint32* |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
71 makeTapestry(TaskManager *manager, uint32 tex_w, uint32 tex_h, uint32 *tex_src, |
539 | 72 int all_pixel_num, int scale_cnt) |
73 { | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
74 if (tex_w==0 && tex_h==0) { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
75 // non texture case |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
76 uint32 pattern = SDL_BYTEORDER == SDL_LIL_ENDIAN? 0x00ffffff : 0xffffff00; /* OpenGL RGBA masks */ |
1053 | 77 if (white[0]!=pattern) { // dumb! |
78 #if 1 | |
79 for(int i=0;i<256;i++) | |
80 white[i] = pattern; | |
81 #else | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
82 memset_pattern4(white,&pattern,256); |
1053 | 83 #endif |
84 } | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
85 return white; |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
86 } |
539 | 87 |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
88 uint32 t = 0; |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
89 uint32 diff = TEXTURE_SPLIT_PIXEL; |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
90 uint32 p_diff = 1; |
539 | 91 |
92 uint32 *tex_dest = (uint32*)manager->allocate(sizeof(int)*all_pixel_num); | |
1092
b99abedb5523
fix h w in makeTapestry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1053
diff
changeset
|
93 // uint32 *tex_src_max = (uint32*)( tex_src + tex_h*tex_w); |
539 | 94 |
1092
b99abedb5523
fix h w in makeTapestry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1053
diff
changeset
|
95 // uint32 alpha = SDL_BYTEORDER == SDL_LIL_ENDIAN? 0xff000000 : 0xff; /* OpenGL RGBA masks */ |
b99abedb5523
fix h w in makeTapestry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1053
diff
changeset
|
96 uint32 alpha = tex_src[0]; |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
97 |
539 | 98 while (scale_cnt) { |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
99 // we should use average, except clear one |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
100 for (uint32 y = 0; y < align(tex_h,diff); y += diff) { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
101 for (uint32 x = 0; x < align(tex_w,diff); x += diff) { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
102 for (uint32 j = 0; j < diff; j += p_diff) { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
103 for (uint32 i = 0; i < diff; i += p_diff) { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
104 tex_dest[t++] = |
1092
b99abedb5523
fix h w in makeTapestry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1053
diff
changeset
|
105 (x+i<tex_w && y+j<tex_h) ? tex_src[(x+i) + tex_w*(y+j)]: alpha; |
539 | 106 } |
107 } | |
108 } | |
109 } | |
110 | |
1092
b99abedb5523
fix h w in makeTapestry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1053
diff
changeset
|
111 diff <<= 1; p_diff <<= 1; |
539 | 112 scale_cnt >>= 1; |
113 } | |
114 | |
115 return tex_dest; | |
116 } | |
117 | |
118 | |
119 /** | |
120 * 何の情報も持ってない SceneGraph の生成 | |
121 * 今のところ、とりあえず木構造の繋がりに使うぐらい | |
122 */ | |
1143 | 123 SceneGraph::SceneGraph(TaskManager *manager) |
539 | 124 { |
1129 | 125 |
539 | 126 init(); |
1143 | 127 |
1169 | 128 matrix = (float*)manager->allocate(sizeof(float)*16); |
129 real_matrix = (float*)manager->allocate(sizeof(float)*16); | |
130 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
1143 | 131 |
132 texture_info->texture_id = -1; | |
133 | |
134 for (int i = 0; i < 16; i++) { | |
135 matrix[i] = 0; | |
136 real_matrix[i] = 0; | |
137 } | |
138 | |
139 | |
539 | 140 finalize = &SceneGraph::finalize_copy; |
141 | |
142 this->name = "NULLPO"; | |
1141 | 143 |
539 | 144 } |
145 | |
146 /** | |
147 * orig のコピーとして SceneGraph を生成する | |
148 */ | |
1169 | 149 SceneGraph::SceneGraph( TaskManager *manager, SceneGraphPtr orig) |
539 | 150 { |
908 | 151 |
539 | 152 init(); |
1129 | 153 |
539 | 154 memcpy(this, orig, sizeof(SceneGraph)); |
155 | |
1169 | 156 matrix = (float*)manager->allocate(sizeof(float)*16); |
157 real_matrix = (float*)manager->allocate(sizeof(float)*16); | |
158 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
159 | |
160 for (int i = 0; i < 16; i++) { | |
161 matrix[i] = orig->matrix[i]; | |
162 real_matrix[i] = orig->real_matrix[i]; | |
163 } | |
164 | |
165 memcpy(texture_info, orig->texture_info, sizeof(texture_list)); | |
166 | |
539 | 167 // コピーしない |
168 //flag_remove = 0; | |
169 //flag_drawable = 1; | |
170 next = NULL; | |
171 prev = NULL; | |
172 last = NULL; | |
173 | |
174 parent = NULL; | |
175 brother = NULL; | |
176 children = NULL; | |
177 lastChild = NULL; | |
178 | |
179 finalize = &SceneGraph::finalize_copy; | |
180 | |
181 frame = 0; | |
182 } | |
183 | |
184 | |
185 /* construct polygon from xmlNode. */ | |
186 SceneGraph::SceneGraph(TaskManager *manager, xmlNodePtr surface) | |
187 { | |
1143 | 188 |
539 | 189 init(); |
1143 | 190 |
1169 | 191 matrix = (float*)manager->allocate(sizeof(float)*16); |
192 real_matrix = (float*)manager->allocate(sizeof(float)*16); | |
193 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
1143 | 194 texture_info->texture_id = -1; |
1125 | 195 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
196 //size : 頂点の数かな |
539 | 197 size = atoi((char *)xmlGetProp(surface,(xmlChar *)"size")); |
198 name = (char *)xmlGetProp(surface,(xmlChar *)"name"); | |
199 parent_name = (char *)xmlGetProp(surface,(xmlChar *)"parent"); | |
200 | |
908 | 201 for (int i = 0; i < 16; i++) { |
1130 | 202 matrix[i] = 0; |
908 | 203 real_matrix[i] = 0; |
204 } | |
205 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
206 if (size % 3 != 0) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
207 printf("vertex size is error. size %% 3 = %lld\n", size % 3); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
208 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
209 |
1136 | 210 if (size > 0) { |
211 pp_num = (size/3 + MAX_SIZE_TRIANGLE - 1) / MAX_SIZE_TRIANGLE; | |
212 pp = (PolygonPack*)manager->allocate(sizeof(PolygonPack)*pp_num); | |
213 } else { | |
214 pp_num = 0; | |
215 pp = NULL; | |
216 } | |
906
becd6fad3ae0
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
217 |
539 | 218 get_data(manager, surface->children); |
219 | |
220 finalize = &SceneGraph::finalize_original; | |
1108 | 221 |
539 | 222 } |
223 | |
1211 | 224 SceneGraph::SceneGraph(TaskManager *manager,const char *font,int pixels,Uint32 color,const char *string_name) { |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
225 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
226 init(); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
227 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
228 this->matrix = (float*)manager->allocate(sizeof(float)*16); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
229 this->real_matrix = (float*)manager->allocate(sizeof(float)*16); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
230 this->texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
231 texture_info->texture_id = -1; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
232 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
233 //size : 頂点の数かな |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
234 size = 6; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
235 parent_name = NULL; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
236 name = string_name; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
237 for (int i = 0; i < 16; i++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
238 matrix[i] = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
239 real_matrix[i] = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
240 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
241 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
242 if (size % 3 != 0) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
243 printf("vertex size is error. size %% 3 = %lld\n", size % 3); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
244 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
245 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
246 if (size > 0) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
247 pp_num = (size/3 + MAX_SIZE_TRIANGLE - 1) / MAX_SIZE_TRIANGLE; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
248 pp = (PolygonPack*)manager->allocate(sizeof(PolygonPack)*pp_num); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
249 } else { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
250 pp_num = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
251 pp = NULL; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
252 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
253 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
254 create_font_data(manager, font, pixels, color, string_name); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
255 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
256 finalize = &SceneGraph::finalize_original; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
257 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
258 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
259 void |
1211 | 260 SceneGraph::create_font_data(TaskManager *manager,const char *font ,int pixels, Uint32 color, const char *string_name) |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
261 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
262 //font_coordinate(pixels/2,pixels); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
263 font_normal(); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
264 font_model(); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
265 //font_texture(); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
266 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
267 get_font_image(manager, font, pixels, color, string_name); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
268 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
269 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
270 void |
1211 | 271 SceneGraph::get_font_image(TaskManager *manager,const char *font ,int pixels ,Uint32 color, const char *string_name) |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
272 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
273 int tex_id; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
274 if (texture_hash.hash_regist(string_name, tex_id)) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
275 SDL_Surface *texture_image = load_font_image(font,pixels,color,string_name); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
276 if(!texture_image){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
277 printf("Can't load image %s\n",string_name); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
278 exit(0); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
279 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
280 texture_info->texture_id = makeTapestries(manager, texture_image,tex_id); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
281 printf("%d\n",texture_info->texture_id); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
282 tex_id = texture_info->texture_id; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
283 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
284 } else { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
285 texture_info->texture_id = tex_id; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
286 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
287 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
288 texture_info->t_w = list[tex_id].t_w; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
289 texture_info->t_h = list[tex_id].t_h; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
290 texture_info->pixels_orig = list[tex_id].pixels_orig; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
291 texture_info->pixels = list[tex_id].pixels; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
292 texture_info->scale_max = list[tex_id].scale_max; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
293 texture_info->texture_image = list[tex_id].texture_image; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
294 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
295 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
296 SDL_Surface* |
1211 | 297 SceneGraph::load_font_image(const char *font ,int pixel,Uint32 color , const char *string_name) |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
298 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
299 //printf("laod_font_iamge"); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
300 FT_Library library; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
301 FT_Error err; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
302 err = FT_Init_FreeType(&library); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
303 if(err){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
304 exit(1); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
305 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
306 FT_Face face; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
307 err = FT_New_Face(library,font,0,&face);//font:フォントファイルのパス |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
308 if(err){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
309 exit(1); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
310 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
311 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
312 err = FT_Set_Pixel_Sizes(face,pixel,pixel); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
313 if(err){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
314 exit(1); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
315 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
316 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
317 u_int32_t changecode[256] = {0}; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
318 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
319 conv(string_name+5,strlen(string_name+5),changecode); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
320 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
321 unsigned int characode = changecode[0]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
322 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
323 err = FT_Load_Char(face,characode,0); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
324 if(err){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
325 exit(1); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
326 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
327 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
328 err = FT_Render_Glyph(face->glyph,FT_RENDER_MODE_MONO); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
329 if(err){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
330 exit(1); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
331 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
332 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
333 FT_Bitmap *bm = &face->glyph->bitmap; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
334 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
335 //baseline計算 y_ppem(nominal height) - bitmap_top(topからのbaseline) |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
336 float baseline = face->size->metrics.y_ppem - face->glyph->bitmap_top; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
337 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
338 float row = 1; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
339 float width = 1; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
340 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
341 font_coordinate(baseline,face->glyph->bitmap.rows,face->glyph->bitmap.width); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
342 this->seq = face->glyph->bitmap.width; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
343 font_texture(row,width); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
344 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
345 int index = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
346 Uint32 *pixels = (Uint32*)malloc(bm->rows*bm->pitch*8*4); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
347 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
348 for (int row = 0; row < bm->rows; row ++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
349 for (int col = 0; col < bm->pitch; col ++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
350 int c = bm->buffer[bm->pitch * row + col]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
351 for (int bit = 7; bit >= 0; bit --) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
352 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
353 if (((c >> bit) & 1) == 0) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
354 //printf(" "); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
355 pixels[index++] = 0x0000000; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
356 } else { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
357 //printf("##"); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
358 //pixels[index++] = 0x00ffffff; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
359 pixels[index++] = color; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
360 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
361 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
362 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
363 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
364 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
365 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
366 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
367 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
368 SDL_Surface *texture_image = SDL_CreateRGBSurfaceFrom(pixels, bm->pitch*8, bm->rows, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
369 32, bm->pitch*8*4, redMask, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
370 greenMask, blueMask, alphaMask); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
371 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
372 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
373 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
374 if (!texture_image) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
375 printf("error\n"); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
376 return 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
377 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
378 SDL_Surface *tmpImage |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
379 = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
380 texture_image->h, 32, redMask, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
381 greenMask, blueMask, alphaMask); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
382 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
383 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
384 SDL_Surface *converted; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
385 converted = SDL_ConvertSurface(texture_image, tmpImage->format, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
386 SDL_HWSURFACE); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
387 if (converted != NULL) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
388 SDL_FreeSurface(texture_image); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
389 texture_image = converted; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
390 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
391 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
392 return texture_image; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
393 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
394 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
395 void |
1211 | 396 SceneGraph::conv(const char *str, int length, u_int32_t *out) { |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
397 int oindex = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
398 int i = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
399 while (i < length) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
400 out[oindex] = str[i++] & 0xff; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
401 int len = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
402 u_int32_t mask; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
403 for (mask = 0x80; out[oindex] & mask; mask >>= 1) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
404 out[oindex] -= mask; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
405 len++; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
406 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
407 int j; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
408 for (j = 1; j < len; j++) |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
409 out[oindex] = (out[oindex] << 6) | (str[i++] & 0x3f); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
410 oindex++; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
411 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
412 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
413 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
414 /*文字のSceneGraphを生成する*/ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
415 |
539 | 416 void |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
417 SceneGraph::init() |
539 | 418 { |
419 next = NULL; | |
420 prev = NULL; | |
421 last = NULL; | |
422 | |
423 parent = NULL; | |
424 brother = NULL; | |
425 children = NULL; | |
426 lastChild = NULL; | |
427 | |
428 stack_xyz[0] = 0.0f; | |
429 stack_xyz[2] = 0.0f; | |
430 stack_xyz[1] = 0.0f; | |
431 stack_angle[0] = 0.0f; | |
432 stack_angle[1] = 0.0f; | |
433 stack_angle[2] = 0.0f; | |
434 | |
435 size = 0; | |
1141 | 436 pp_num = 0; |
437 | |
539 | 438 //data = NULL; |
1128 | 439 |
539 | 440 move = no_move; |
441 collision = no_collision; | |
442 | |
443 flag_remove = 0; | |
444 flag_drawable = 1; | |
445 sgid = -1; | |
446 gid = -1; | |
447 | |
448 frame = 0; | |
449 } | |
450 | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
451 SceneGraph::~SceneGraph() |
539 | 452 { |
453 (this->*finalize)(); | |
454 } | |
455 | |
456 /** | |
457 * xml ファイルから生成されたオリジナル SceneGraph なので | |
458 * polygon data を削除 | |
459 */ | |
460 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
461 SceneGraph::finalize_original() |
539 | 462 { |
463 //delete [] data; | |
860 | 464 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
465 free(pp); |
1142
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
466 free(matrix); |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
467 free(real_matrix); |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
468 free(texture_info); |
860 | 469 |
539 | 470 } |
471 | |
472 /** | |
473 * SceneGraph ID から生成された、コピー SceneGraph なので | |
474 * polygon data は削除しない。オリジナルの方で削除する。 | |
475 */ | |
476 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
477 SceneGraph::finalize_copy() |
539 | 478 { |
1142
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
479 |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
480 free(matrix); |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
481 free(real_matrix); |
1169 | 482 free(texture_info); |
539 | 483 } |
484 | |
485 | |
486 /** | |
487 * add Children | |
488 * 親の登録と、brother のリストへ加える | |
489 * | |
490 * @param child new child | |
491 */ | |
492 SceneGraphPtr | |
493 SceneGraph::addChild(SceneGraphPtr child) | |
494 { | |
495 /* childrenのリストの最後に加える (brother として)*/ | |
496 if (this->lastChild != NULL) { | |
497 SceneGraphPtr last = this->lastChild; | |
498 last->brother = child; | |
850 | 499 //child->parent = this; |
500 //return child; | |
539 | 501 } |
891 | 502 |
539 | 503 this->lastChild = child; |
891 | 504 |
539 | 505 if (this->children == NULL) { |
506 this->children = child; | |
507 } | |
891 | 508 |
539 | 509 child->parent = this; |
510 | |
511 return child; | |
512 } | |
513 | |
514 | |
515 /** | |
516 * add Brother | |
517 * addChild() でも brother の操作をしないといけないので、そっちに回す | |
518 * | |
519 * @param bro new Brother | |
520 */ | |
521 SceneGraphPtr | |
522 SceneGraph::addBrother(SceneGraphPtr bro) | |
523 { | |
524 if (this->parent) { | |
525 parent->addChild(bro); | |
526 } else { | |
527 fprintf(stderr, "error : SceneGraph::%s : %s doesn't have parent\n", | |
528 __FUNCTION__, this->name); | |
529 } | |
530 | |
531 return bro; | |
532 } | |
533 | |
534 /* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL. */ | |
535 SceneGraphPtr | |
536 SceneGraph::searchSceneGraph(const char *name) | |
537 { | |
538 SceneGraphPtr tmp; | |
539 SceneGraphPtr result; | |
540 | |
541 /* 本人か */ | |
542 if( 0==strcmp(this->name, name) ) return this; | |
543 | |
544 /* 子供から再帰的に探す */ | |
545 for(tmp = this->children; tmp; tmp = tmp->next) { | |
546 if ((result=tmp->searchSceneGraph(name)) != NULL) | |
547 return result; | |
548 } | |
549 | |
550 /* 無かったら NULL. */ | |
551 return NULL; | |
552 } | |
553 | |
554 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
555 SceneGraph::tree_check() |
539 | 556 { |
557 SceneGraphPtr t = this; | |
558 | |
559 while(t) | |
560 { | |
561 cout << "my_name : " << t->name << endl; | |
562 if(t->children != NULL) | |
563 { | |
564 cout << "--move children : " << t->children->name << endl; | |
565 t = t->children; | |
566 } | |
567 else if(t->brother != NULL) | |
568 { | |
569 cout << "--move brother : " << t->brother->name << endl; | |
570 t = t->brother; | |
571 } | |
572 else | |
573 { | |
574 while(t) | |
575 { | |
576 if(t->brother != NULL) | |
577 { | |
578 cout << "--move brother : " << t->brother->name << endl; | |
579 t = t->brother; | |
580 break; | |
581 } | |
582 else | |
583 { | |
584 if(t->parent) | |
585 { | |
586 cout << "--move parent : " << t->parent->name << endl; | |
587 } | |
588 t = t->parent; | |
589 } | |
590 } | |
591 } | |
592 } | |
593 } | |
594 | |
595 | |
596 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
597 SceneGraph::print_member() |
539 | 598 { |
599 cout << "size = " << size << endl; | |
600 cout << "name = " << name << endl; | |
601 cout << "parent_name = " << parent_name << endl; | |
602 | |
603 if (parent != NULL) { | |
604 cout << "parent->name = " << parent->name << endl; | |
605 } | |
606 | |
607 if (children != NULL) { | |
608 cout << "children->name = " << children->name << endl; | |
609 } | |
610 } | |
611 | |
612 | |
613 /* | |
614 * surface nodeからポリゴンの情報を読み出す 再帰しない | |
615 */ | |
616 void | |
617 SceneGraph::get_data(TaskManager *manager, xmlNodePtr cur) | |
618 { | |
619 //char *image_name; | |
620 | |
621 for(;cur;cur=cur->next) | |
622 { | |
623 if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate")) | |
624 { | |
625 char *cont = (char *)xmlNodeGetContent(cur); | |
626 pickup_coordinate(cont); | |
627 } | |
628 else if(!xmlStrcmp(cur->name,(xmlChar*)"normal")) | |
629 { | |
630 char *cont = (char *)xmlNodeGetContent(cur); | |
631 pickup_normal(cont); | |
632 } | |
633 else if(!xmlStrcmp(cur->name,(xmlChar*)"model")) | |
634 { | |
635 char *cont = (char *)xmlNodeGetContent(cur); | |
636 pickup_model(cont); | |
637 } | |
638 else if(!xmlStrcmp(cur->name,(xmlChar*)"texture")) | |
639 { | |
640 char *cont = (char *)xmlNodeGetContent(cur); | |
641 pickup_texture(cont); | |
642 } | |
643 else if(!xmlStrcmp(cur->name,(xmlChar*)"imageflag")) | |
644 { | |
645 int id; | |
646 char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); | |
647 texture_hash.hash_regist(filename, id); | |
648 } | |
649 else if(!xmlStrcmp(cur->name,(xmlChar*)"image")) | |
650 { | |
651 get_image(manager, cur); | |
652 } | |
653 } | |
654 } | |
655 | |
1166
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
656 static int |
1211 | 657 is_bmp(const char *name) { |
1166
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
658 int bmp = 0; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
659 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
660 while(*name) { |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
661 if (bmp==0 && *name=='.') bmp = 1; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
662 else if (bmp==1 && (*name=='b' || *name=='B')) bmp = 2; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
663 else if (bmp==2 && (*name=='m' || *name=='M')) bmp = 3; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
664 else if (bmp==3 && (*name=='p' || *name=='P')) bmp = 4; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
665 else bmp = 0; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
666 name++; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
667 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
668 return bmp==4; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
669 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
670 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
671 #if (__LITTLE_ENDIAN__) |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
672 #define LITTLEENDIAN 1 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
673 #else |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
674 #define LITTLEENDIAN 0 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
675 #endif |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
676 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
677 static void |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
678 make_black_alpha(SDL_Surface *texture_image) |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
679 { |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
680 int tex_w = texture_image->w; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
681 int tex_h = texture_image->h; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
682 #if LITTLEENDIAN |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
683 uint32 alpha = 0x000000ff; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
684 #else |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
685 uint32 alpha = 0xff000000; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
686 #endif |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
687 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
688 uint32 *pixels = (uint32*)texture_image->pixels; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
689 int i; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
690 for(i=0;i<tex_w*tex_h;i++) { |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
691 uint32 pixel = pixels[i] & ~alpha; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
692 if (pixel==0) { |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
693 pixels[i] = 0; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
694 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
695 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
696 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
697 |
539 | 698 SDL_Surface* |
1211 | 699 SceneGraph::load_decode_image(const char *file_name, const char *image_name, xmlNodePtr cur) |
539 | 700 { |
1211 | 701 int fd = mkstemp((char *)image_name); |
539 | 702 FILE *outfile = fdopen(fd, "wb"); |
703 | |
704 if (NULL == outfile) { | |
705 cout << "error open file\n"; | |
706 return 0; | |
707 } | |
708 | |
709 char *cont = (char *)xmlNodeGetContent(cur); | |
710 //decode(cont, image_name); | |
711 decode(cont, outfile); | |
712 fclose(outfile); | |
713 | |
1166
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
714 int alpha_black = is_bmp(file_name); |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
715 |
539 | 716 |
717 /** | |
718 * image を 32bit(RGBA) に変換する | |
719 */ | |
720 SDL_Surface *texture_image = IMG_Load(image_name); | |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
721 if (!texture_image) return 0; |
539 | 722 SDL_Surface *tmpImage |
1123 | 723 = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, |
996 | 724 texture_image->h, 32, redMask, |
725 greenMask, blueMask, alphaMask); | |
726 | |
727 //= SDL_CreateRGBSurface(SDL_HWSURFACE, 0, | |
728 // 0, 32, redMask, | |
729 // greenMask, blueMask, alphaMask); | |
539 | 730 SDL_Surface *converted; |
731 converted = SDL_ConvertSurface(texture_image, tmpImage->format, | |
996 | 732 SDL_HWSURFACE); |
733 | |
734 //SDL_SetAlpha(converted, 0, 0); | |
735 | |
539 | 736 if (converted != NULL) { |
737 SDL_FreeSurface(texture_image); | |
738 texture_image = converted; | |
739 } | |
740 | |
1166
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
741 if (alpha_black) { |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
742 make_black_alpha(texture_image); |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
743 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
744 |
942
27df980045b5
FB mode is working again on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
930
diff
changeset
|
745 // this->gl_tex = SDL_GL_LoadTexture(texture_image); |
539 | 746 return texture_image; |
747 } | |
748 | |
749 int | |
750 SceneGraph::makeTapestries(TaskManager *manager, SDL_Surface *texture_image, int id) { | |
751 uint32 *tapestry; | |
752 int scale = 1; | |
753 int tex_w = texture_image->w; | |
754 int tex_h = texture_image->h; | |
755 int all_pixel_num = 0; | |
1047
f87218eed9fc
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1033
diff
changeset
|
756 int nw = tex_w; |
f87218eed9fc
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1033
diff
changeset
|
757 int nh = tex_h; |
539 | 758 |
759 /** | |
760 * テクスチャの w or h が 8 pixel で分割できる間、 | |
761 * 1/2 の縮小画像を作る。 | |
762 * ここでは、最大の scale (1/scale) を見つける | |
763 * | |
764 * (ex) | |
765 * (128,128) => 64,64 : 32,32: 16,16 : 8,8 | |
766 * scale = 16 | |
767 * (128, 64) => 64,32 : 32,16: 16,8 | |
768 * scale = 8 | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
769 * 8 pixcel align してない場合は、透明に 8 pixcel に拡張する |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
770 * (200, 57) => 200,64 : 100,32 : 56,16: 32,8 (16,1 : 8,1 まで落すべき? 32byte) |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
771 * scale = 32 |
539 | 772 */ |
1047
f87218eed9fc
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1033
diff
changeset
|
773 |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
774 do { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
775 tex_w = align(tex_w,8); |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
776 tex_h = align(tex_h,8); |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
777 all_pixel_num += tex_w * tex_h; |
539 | 778 tex_w >>= 1; /* tex_w /= 2 */ |
779 tex_h >>= 1; | |
780 scale <<= 1; /* scale *= 2 */ | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
781 } while( tex_w >8 || tex_h > 8 ); |
539 | 782 |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
783 scale >>= 1; // 必ず 1 以上になる |
539 | 784 |
785 tapestry = makeTapestry(manager, texture_image->w, texture_image->h, | |
786 (uint32*)texture_image->pixels, | |
787 all_pixel_num, scale); | |
788 | |
1047
f87218eed9fc
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1033
diff
changeset
|
789 list[id].t_w = nw; |
f87218eed9fc
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1033
diff
changeset
|
790 list[id].t_h = nh; |
539 | 791 list[id].pixels_orig = (Uint32*)texture_image->pixels; |
792 list[id].pixels = tapestry; | |
793 list[id].scale_max = scale; | |
942
27df980045b5
FB mode is working again on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
930
diff
changeset
|
794 list[id].texture_image = texture_image; |
539 | 795 |
796 return id; | |
797 } | |
798 | |
799 void | |
800 SceneGraph::get_image(TaskManager *manager, xmlNodePtr cur) | |
801 { | |
802 char image_name[20] = "/tmp/image_XXXXXX"; | |
803 char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); | |
804 | |
805 if (filename == NULL || filename[0] == 0) { | |
806 return; | |
807 } | |
808 | |
809 /** | |
810 * image_name を既に Load していれば何もしない | |
811 */ | |
812 int tex_id; | |
1184 | 813 if (texture_hash.sg_hash_regist(filename, tex_id) == -1) { |
539 | 814 |
1166
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
815 SDL_Surface *texture_image = load_decode_image(filename, image_name, cur); |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
816 if (texture_image==0) { |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
817 printf("Can't load image %s\n",filename); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
818 exit(0); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
819 } |
1130 | 820 texture_info->texture_id = makeTapestries(manager, texture_image, tex_id); |
821 tex_id = texture_info->texture_id; | |
539 | 822 |
823 if (unlink(image_name)) { | |
824 cout << "unlink error\n"; | |
825 } | |
826 } else { | |
827 /** | |
828 * 以前に Load されている Texture を共用 | |
829 */ | |
1130 | 830 texture_info->texture_id = tex_id; |
539 | 831 } |
832 | |
860 | 833 // こんなことすると list[] のいみあるのかなーと |
834 // 微妙に思う、自分で書き換えた感想 by gongo | |
1130 | 835 texture_info->t_w = list[tex_id].t_w; |
836 texture_info->t_h = list[tex_id].t_h;; | |
837 texture_info->pixels_orig = list[tex_id].pixels_orig; | |
838 texture_info->pixels = list[tex_id].pixels; | |
839 texture_info->scale_max = list[tex_id].scale_max; | |
840 texture_info->texture_image = list[tex_id].texture_image; | |
860 | 841 |
539 | 842 } |
843 | |
844 | |
845 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
846 SceneGraph::delete_data() |
539 | 847 { |
848 SceneGraphPtr n = this->next, m; | |
849 | |
850 //n = this; | |
851 //delete [] n->data; | |
852 | |
853 if (next) { | |
854 while (n) { | |
855 m = n->next; | |
856 delete n; | |
857 n = m; | |
858 } | |
859 } | |
860 } | |
861 | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
862 /* move_func 実行 sgroot 渡す */ |
539 | 863 void |
864 SceneGraph::move_execute(int w, int h) | |
865 { | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
866 (*move)(this, this->sgroot, w, h); |
539 | 867 } |
868 | |
869 void | |
870 SceneGraph::collision_check(int w, int h, SceneGraphPtr tree) | |
871 { | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
872 (*collision)(this, this->sgroot, w, h, tree); |
539 | 873 } |
874 | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
875 void |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
876 SceneGraph::create_sg_execute() |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
877 { |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
878 (*create_sg)(this->sgroot, property, update_property); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
879 } |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
880 |
1033
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
881 void |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
882 SceneGraph::set_move_collision(move_func new_move) |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
883 { |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
884 this->move = new_move; |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
885 } |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
886 |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
887 void |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
888 SceneGraph::set_move_collision(collision_func new_collision) |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
889 { |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
890 this->collision = new_collision; |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
891 } |
539 | 892 |
893 void | |
894 SceneGraph::set_move_collision(move_func new_move, | |
895 collision_func new_collision) | |
896 { | |
897 this->move = new_move; | |
898 this->collision = new_collision; | |
899 } | |
900 | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
901 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
902 void |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
903 SceneGraph::set_move_collision(move_func new_move, |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
904 collision_func new_collision, void *sgroot_) |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
905 { |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
906 this->move = new_move; |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
907 this->collision = new_collision; |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
908 // add |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
909 this->sgroot = sgroot_; |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
910 } |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
911 |
539 | 912 void |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
913 SceneGraph::set_move_collision(move_func new_move, |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
914 collision_func new_collision, create_sg_func new_create_sg) |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
915 { |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
916 this->move = new_move; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
917 this->collision = new_collision; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
918 this->create_sg = new_create_sg; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
919 } |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
920 |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
921 void |
539 | 922 SceneGraph::add_next(SceneGraphPtr next) |
923 { | |
924 /* next のリストの最後に加える */ | |
925 if (this->next != NULL) { | |
926 SceneGraphPtr tmp = this->last; | |
927 tmp->next = next; | |
928 } else { | |
929 this->next = next; | |
930 } | |
931 | |
932 this->last = next; | |
933 } | |
934 | |
935 /** | |
936 * SceneGraph の clone | |
937 * @return clone SceneGraph | |
938 */ | |
939 SceneGraphPtr | |
1136 | 940 SceneGraph::clone(TaskManager *manager) { |
941 | |
1169 | 942 SceneGraphPtr p = new SceneGraph(manager, this); |
1136 | 943 |
1140
3975c384ff93
SceneGraph initalize... can worked on Mac OS X. not check Cell arch.
Yutaka_Kinjyo
parents:
1136
diff
changeset
|
944 |
539 | 945 return p; |
946 } | |
947 | |
948 /** | |
949 * SceneGraph の clone | |
950 * 予め allocate されてる領域への placement new を行う | |
951 * | |
952 * @param buf clone 領域 | |
953 * @return clone SceneGraph | |
954 */ | |
1169 | 955 |
539 | 956 SceneGraphPtr |
1169 | 957 SceneGraph::clone(TaskManager *manager, void *buf) { |
958 SceneGraphPtr p = new(buf) SceneGraph(manager, this); | |
539 | 959 return p; |
960 } | |
961 | |
962 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
963 SceneGraph::remove() |
539 | 964 { |
965 this->flag_remove = 1; | |
966 } | |
967 | |
968 /** | |
969 * tree から node を削除する | |
970 * | |
971 * @param tree SceneGraphTree | |
972 * @return node削除後の SceneGraphTree | |
973 */ | |
974 SceneGraphPtr | |
975 SceneGraph::realRemoveFromTree(SceneGraphPtr tree) | |
976 { | |
977 SceneGraphPtr node = this; | |
978 SceneGraphPtr parent = node->parent; | |
979 SceneGraphPtr ret = tree; | |
980 | |
981 if (parent) { | |
982 SceneGraphPtr brother = parent->children; | |
983 SceneGraphPtr p, p1 = NULL; | |
984 | |
985 p = brother; | |
986 if (p) { | |
987 if (p == node) { | |
988 parent->children = NULL; | |
989 parent->lastChild = NULL; | |
990 } else { | |
991 p1 = p->brother; | |
992 | |
993 while (p1 && p1 != node) { | |
994 p1 = p1->brother; | |
995 p = p->brother; | |
996 } | |
997 | |
998 if (p1) { | |
999 p->brother = p1->brother; | |
1000 | |
1001 // node が最後尾なら、lastChild を変更 | |
1002 if (parent->lastChild == p1) { | |
1003 parent->lastChild = p; | |
1004 } | |
1005 } else { | |
1006 // Can't find remove node | |
1007 } | |
1008 } | |
1009 } | |
1010 } else { | |
1011 // 親が居ない = tree root なので | |
1012 // NULL を返す | |
1013 ret = NULL; | |
1014 } | |
1015 | |
1016 return ret; | |
1017 } | |
1018 | |
1019 /** | |
1020 * list から node を削除する | |
1021 * | |
1022 * @param list SceneGraphList | |
1023 * @return node削除後の SceneGraphList | |
1024 */ | |
1025 SceneGraphPtr | |
1026 SceneGraph::realRemoveFromList(SceneGraphPtr list) | |
1027 { | |
1028 SceneGraphPtr node = this; | |
1029 SceneGraphPtr prev = node->prev; | |
1030 SceneGraphPtr next = node->next; | |
1031 SceneGraphPtr ret = list; | |
1032 | |
1033 if (prev) { | |
1034 prev->next = next; | |
1035 } else { | |
1036 ret = next; | |
1037 } | |
1038 | |
1039 if (next) { | |
1040 next->prev = prev; | |
1041 } | |
1042 | |
1043 return ret; | |
1044 } | |
1045 | |
1046 int | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
1047 SceneGraph::isRemoved() |
539 | 1048 { |
1049 return flag_remove; | |
1050 } | |
1051 | |
1052 /** | |
1053 * 平行移動 | |
1054 * | |
1055 * @param x Ttranslate in the x direction | |
1056 * @param y Ttranslate in the y direction | |
1057 * @param z Ttranslate in the z direction | |
1058 */ | |
1059 void | |
1060 SceneGraph::translate(float x, float y, float z) | |
1061 { | |
1062 this->xyz[0] = x; | |
1063 this->xyz[1] = y; | |
1064 this->xyz[2] = z; | |
1065 } | |
1066 | |
1067 /** | |
1068 * x 軸方向への平行移動 | |
1069 * | |
1070 * @param x Ttranslate in the x direction | |
1071 */ | |
1072 void | |
1073 SceneGraph::translateX(float x) | |
1074 { | |
1075 this->xyz[0] = x; | |
1076 } | |
1077 | |
1078 /** | |
1079 * y 軸方向への平行移動 | |
1080 * | |
1081 * @param y Ttranslate in the y direction | |
1082 */ | |
1083 void | |
1084 SceneGraph::translateY(float y) | |
1085 { | |
1086 this->xyz[1] = y; | |
1087 } | |
1088 | |
1089 /** | |
1090 * z 軸方向への平行移動 | |
1091 * | |
1092 * @param z Ttranslate in the z direction | |
1093 */ | |
1094 void | |
1095 SceneGraph::translateZ(float z) | |
1096 { | |
1097 this->xyz[2] = z; | |
1098 } | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
1099 |
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
1100 /* end */ |