]> icculus.org git repositories - btb/d2x.git/blob - 2d/diff
This commit was generated by cvs2svn to compensate for changes in r2,
[btb/d2x.git] / 2d / diff
1 13a14
2 > #include <conf.h>\r
3 23c24
4 < #include "mem.h"\r
5 ---
6 > #include "u_mem.h"\r
7 31a33
8 > #include "bitmap.h"\r
9 133a136
10\r
11 135a139,156
12 > //hack to allow color codes to be embedded in strings -MPM\r
13 > //note we subtract one from color, since 255 is "transparent" so it'll never be used, and 0 would otherwise end the string.\r
14 > //function must already have orig_color var set (or they could be passed as args...)\r
15 > //perhaps some sort of recursive orig_color type thing would be better, but that would be way too much trouble for little gain\r
16 > int gr_message_color_level=1;\r
17 > #define CHECK_EMBEDDED_COLORS() if ((*text_ptr >= 0x01) && (*text_ptr <= 0x03)) { \\r
18 >               text_ptr++; \\r
19 >               if (*text_ptr){ \\r
20 >                       if (gr_message_color_level >= *(text_ptr-1)) \\r
21 >                               FG_COLOR = *text_ptr - 1; \\r
22 >                       text_ptr++; \\r
23 >               } \\r
24 >       } \\r
25 >       else if ((*text_ptr >= 0x04) && (*text_ptr <= 0x06)){ \\r
26 >               if (gr_message_color_level >= *text_ptr - 3) \\r
27 >                       FG_COLOR=orig_color; \\r
28 >               text_ptr++; \\r
29 >       }\r
30 359c380
31\r
32 ---
33 > #ifdef __ENV_MSDOS__ \r
34 749a771
35 > #endif\r
36 975a998
37 > #ifndef OGL\r
38 1049a1073,1336
39 > #else // OGL\r
40\r
41 > #include "../main/inferno.h"\r
42 > #include "ogl_init.h"\r
43 > #include "args.h"\r
44 > //font handling routines for OpenGL - Added 9/25/99 Matthew Mueller - they are here instead of in arch/ogl because they use all these defines\r
45\r
46 > int pow2ize(int x);//from ogl.c\r
47\r
48 > int get_font_total_width(grs_font * font){\r
49 >       if (font->ft_flags & FT_PROPORTIONAL){\r
50 >               int i,w=0,c=font->ft_minchar;\r
51 >               for (i=0;c<=font->ft_maxchar;i++,c++){\r
52 >                       if (font->ft_widths[i]<0)\r
53 >                               Error("heh?\n");\r
54 >                       w+=font->ft_widths[i];\r
55 >               }\r
56 >               return w;\r
57 >       }else{\r
58 >               return font->ft_w*(font->ft_maxchar-font->ft_minchar+1);\r
59 >       }\r
60 > }\r
61 > void ogl_font_choose_size(grs_font * font,int gap,int *rw,int *rh){\r
62 >       int     nchars = font->ft_maxchar-font->ft_minchar+1;\r
63 >       int r,x,y,nc=0,smallest=999999,smallr=-1,tries;\r
64 >       int smallprop=10000;\r
65 >       int h,w;\r
66 >       for (h=32;h<=256;h*=2){\r
67 > //            h=pow2ize(font->ft_h*rows+gap*(rows-1));\r
68 >               if (font->ft_h>h)continue;\r
69 >               r=(h/(font->ft_h+gap));\r
70 >               w=pow2ize((get_font_total_width(font)+(nchars-r)*gap)/r);\r
71 >               tries=0;\r
72 >               do {\r
73 >                       if (tries)\r
74 >                               w=pow2ize(w+1);\r
75 >                       if(tries>3){\r
76 >                               mprintf((0,"failed to fit (%ix%i, %ic)\n",w,h,nc));\r
77 >                               break;\r
78 >                       }\r
79 >                       nc=0;\r
80 >                       y=0;\r
81 >                       while(y+font->ft_h<=h){\r
82 >                               x=0;\r
83 >                               while (x<w){\r
84 >                                       if (nc==nchars)\r
85 >                                               break;\r
86 >                                       if (font->ft_flags & FT_PROPORTIONAL){\r
87 >                                               if (x+font->ft_widths[nc]+gap>w)break;\r
88 >                                               x+=font->ft_widths[nc++]+gap;\r
89 >                                       }else{\r
90 >                                               if (x+font->ft_w+gap>w)break;\r
91 >                                               x+=font->ft_w+gap;\r
92 >                                               nc++;\r
93 >                                       }\r
94 >                               }\r
95 >                               if (nc==nchars)\r
96 >                                       break;\r
97 >                               y+=font->ft_h+gap;\r
98 >                       }\r
99 >                       \r
100 >                       tries++;\r
101 >               }while(nc!=nchars);\r
102 >               if (nc!=nchars)\r
103 >                       continue;\r
104 >               mprintf((0,"fit: %ix%i  %i tries\n",w,h,tries));\r
105\r
106 >               if (w*h==smallest){//this gives squarer sizes priority (ie, 128x128 would be better than 512*32)\r
107 >                       if (w>=h){\r
108 >                               if (w/h<smallprop){\r
109 >                                       smallprop=w/h;\r
110 >                                       smallest++;//hack\r
111 >                               }\r
112 >                       }else{\r
113 >                               if (h/w<smallprop){\r
114 >                                       smallprop=h/w;\r
115 >                                       smallest++;//hack\r
116 >                               }\r
117 >                       }\r
118 >               }\r
119 >               if (w*h<smallest){\r
120 >                       smallr=1;\r
121 >                       smallest=w*h;\r
122 >                       *rw=w;\r
123 >                       *rh=h;\r
124 >               }\r
125 >       }\r
126 >       if (smallr<=0)\r
127 >               Error("couldn't fit font?\n");\r
128 >       mprintf((0,"using %ix%i\n",*rw,*rh));\r
129 >       printf("using %ix%i\n",*rw,*rh);\r
130 >       \r
131 > }\r
132\r
133 > void ogl_init_font(grs_font * font){\r
134 >       int     nchars = font->ft_maxchar-font->ft_minchar+1;\r
135 >       int i,w,h,tw,th,x,y,curx=0,cury=0;\r
136 >       char *fp;\r
137 >       //      char data[32*32*4];\r
138 >       char *data;\r
139 >       int gap=0;//having a gap just wastes ram, since we don't filter text textures at all.\r
140 >       //      char s[2];\r
141 >       ogl_font_choose_size(font,gap,&tw,&th);\r
142 >       data=malloc(tw*th);\r
143 >       gr_init_bitmap(&font->ft_parent_bitmap,BM_LINEAR,0,0,tw,th,tw,data);\r
144\r
145 >       font->ft_parent_bitmap.gltexture=ogl_get_free_texture();\r
146\r
147 >       font->ft_bitmaps=(grs_bitmap*)malloc( nchars * sizeof(grs_bitmap));\r
148 >       mprintf((0,"ogl_init_font %s, %s, nchars=%i, (%ix%i tex)\n",(font->ft_flags & FT_PROPORTIONAL)?"proportional":"fixedwidth",(font->ft_flags & FT_COLOR)?"color":"mono",nchars,tw,th));\r
149 >       //      s[1]=0;\r
150 >       h=font->ft_h;\r
151 >       //      sleep(5);\r
152\r
153 >       for(i=0;i<nchars;i++){\r
154 >               //              s[0]=font->ft_minchar+i;\r
155 >               //              gr_get_string_size(s,&w,&h,&aw);\r
156 >               if (font->ft_flags & FT_PROPORTIONAL)\r
157 >                       w=font->ft_widths[i];\r
158 >               else\r
159 >                       w=font->ft_w;\r
160 > //            mprintf((0,"char %i(%ix%i): ",i,w,h));\r
161 >               if (w<1 || w>256){\r
162 >                       mprintf((0,"grr\n"));continue;\r
163 >               }\r
164 >               if (curx+w+gap>tw){\r
165 >                       cury+=h+gap;\r
166 >                       curx=0;\r
167 >               }\r
168 >               if (cury+h>th)\r
169 >                       Error("font doesn't really fit (%i/%i)?\n",i,nchars);\r
170 >               if (font->ft_flags & FT_COLOR) {\r
171 >                       if (font->ft_flags & FT_PROPORTIONAL)\r
172 >                               fp = font->ft_chars[i];\r
173 >                       else\r
174 >                               fp = font->ft_data + i * w*h;\r
175 >                       for (y=0;y<h;y++)\r
176 >                               for (x=0;x<w;x++){\r
177 >                                       font->ft_parent_bitmap.bm_data[curx+x+(cury+y)*tw]=fp[x+y*w];\r
178 >                               }\r
179\r
180 >                       //                      gr_init_bitmap(&font->ft_bitmaps[i],BM_LINEAR,0,0,w,h,w,font->);\r
181 >               }else{\r
182 >                       int BitMask,bits=0,white=gr_find_closest_color(63,63,63);\r
183 >                       //                      if (w*h>sizeof(data))\r
184 >                       //                              Error("ogl_init_font: toobig\n");\r
185 >                       if (font->ft_flags & FT_PROPORTIONAL)\r
186 >                               fp = font->ft_chars[i];\r
187 >                       else\r
188 >                               fp = font->ft_data + i * BITS_TO_BYTES(w)*h;\r
189 >                       for (y=0;y<h;y++){\r
190 >                               BitMask=0;\r
191 >                               for (x=0; x< w; x++ )\r
192 >                               {\r
193 >                                       if (BitMask==0) {\r
194 >                                               bits = *fp++;\r
195 >                                               BitMask = 0x80;\r
196 >                                       }\r
197\r
198 >                                       if (bits & BitMask)\r
199 >                                               font->ft_parent_bitmap.bm_data[curx+x+(cury+y)*tw]=white;\r
200 >                                       else\r
201 >                                               font->ft_parent_bitmap.bm_data[curx+x+(cury+y)*tw]=255;\r
202 >                                       BitMask >>= 1;\r
203 >                               }\r
204 >                       }\r
205 >               }\r
206 >               gr_init_sub_bitmap(&font->ft_bitmaps[i],&font->ft_parent_bitmap,curx,cury,w,h);\r
207\r
208 >               curx+=w+gap;\r
209 >       }\r
210 >       if (!(font->ft_flags & FT_COLOR)) {\r
211 >               //use GL_INTENSITY instead of GL_RGB\r
212 >               if (ogl_intensity4_ok){\r
213 >                       font->ft_parent_bitmap.gltexture->internalformat=GL_INTENSITY4;\r
214 >                       font->ft_parent_bitmap.gltexture->format=GL_LUMINANCE;\r
215 >               }else if (ogl_luminance4_alpha4_ok){\r
216 >                       font->ft_parent_bitmap.gltexture->internalformat=GL_LUMINANCE4_ALPHA4;\r
217 >                       font->ft_parent_bitmap.gltexture->format=GL_LUMINANCE_ALPHA;\r
218 >               }else if (ogl_rgba2_ok){\r
219 >                       font->ft_parent_bitmap.gltexture->internalformat=GL_RGBA2;\r
220 >                       font->ft_parent_bitmap.gltexture->format=GL_RGBA;\r
221 >               }else{\r
222 >                       font->ft_parent_bitmap.gltexture->internalformat=ogl_rgba_format;\r
223 >                       font->ft_parent_bitmap.gltexture->format=GL_RGBA;\r
224 >               }\r
225 >       }\r
226 >       ogl_loadbmtexture_m(&font->ft_parent_bitmap,0);\r
227 > }\r
228\r
229 > int ogl_internal_string(int x, int y, char *s )\r
230 > {\r
231 >       ubyte * text_ptr, * next_row, * text_ptr1;\r
232 >       int width, spacing,letter;\r
233 >       int xx,yy;\r
234 >       int orig_color=FG_COLOR;//to allow easy reseting to default string color with colored strings -MPM\r
235\r
236 >       next_row = s;\r
237\r
238 >       yy = y;\r
239\r
240 >       if (grd_curscreen->sc_canvas.cv_bitmap.bm_type != BM_OGL)\r
241 >               Error("carp.\n");\r
242 >       while (next_row != NULL)\r
243 >       {\r
244 >               text_ptr1 = next_row;\r
245 >               next_row = NULL;\r
246\r
247 >               text_ptr = text_ptr1;\r
248\r
249 >               xx = x;\r
250\r
251 >               if (xx==0x8000)                 //centered\r
252 >                       xx = get_centered_x(text_ptr);\r
253\r
254 >               while (*text_ptr)\r
255 >               {\r
256 >                       if (*text_ptr == '\n' )\r
257 >                       {\r
258 >                               next_row = &text_ptr[1];\r
259 >                               yy += FHEIGHT;\r
260 >                               break;\r
261 >                       }\r
262\r
263 >                       letter = *text_ptr-FMINCHAR;\r
264\r
265 >                       get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);\r
266\r
267 >                       if (!INFONT(letter) || *text_ptr<=0x06) {       //not in font, draw as space\r
268 >                               CHECK_EMBEDDED_COLORS() else{\r
269 >                                       xx += spacing;\r
270 >                                       text_ptr++;\r
271 >                               }\r
272 >                               continue;\r
273 >                       }\r
274 >                       \r
275 > //                    ogl_ubitblt(FONT->ft_bitmaps[letter].bm_w,FONT->ft_bitmaps[letter].bm_h,xx,yy,0,0,&FONT->ft_bitmaps[letter],NULL);\r
276 > //                    if (*text_ptr>='0' && *text_ptr<='9'){\r
277 >                       printf("%p\n",&FONT->ft_bitmaps[letter]);\r
278 >                       if (FFLAGS&FT_COLOR)\r
279 >                               gr_ubitmapm(xx,yy,&FONT->ft_bitmaps[letter]);\r
280 >                       else{\r
281 >                               if (grd_curcanv->cv_bitmap.bm_type==BM_OGL)\r
282 >                                       ogl_ubitmapm_c(xx,yy,&FONT->ft_bitmaps[letter],FG_COLOR);\r
283 >                               else\r
284 >                                       Error("ogl_internal_string: non-color string to non-ogl dest\n");\r
285 > //                                    gr_ubitmapm(xx,yy,&FONT->ft_bitmaps[letter]);//ignores color..\r
286 >                       }\r
287 >                       //}\r
288\r
289 >                       xx += spacing;\r
290\r
291 >                       text_ptr++;\r
292 >               }\r
293\r
294 >       }\r
295 >       return 0;\r
296 > }\r
297 > int gr_internal_color_string(int x, int y, char *s ){\r
298 >       return ogl_internal_string(x,y,s);\r
299 > }\r
300\r
301 > #endif // OGL\r
302\r
303 1118a1406
304 > #ifdef __ENV_MSDOS__\r
305 1123a1412
306 > #endif\r
307 1248a1538,1539
308 > #define swapshort(a) (a)\r
309 > #define swapint(a) (a)\r
310 1251a1543
311 >       old_grs_font *oldfont;\r
312 1284c1576,1578
313 <       font = (grs_font *) malloc(datasize);\r
314 ---
315 >       oldfont = (old_grs_font *) malloc(datasize);\r
316 >       font = (grs_font *) malloc(sizeof(grs_font));\r
317 >       font->oldfont = oldfont;\r
318 1288c1582,1590
319 <       cfread(font,1,datasize,fontfile);\r
320 ---
321 >       cfread(oldfont,1,datasize,fontfile);\r
322 >         font->ft_flags=swapshort(oldfont->ft_flags);\r
323 >         font->ft_w=swapshort(oldfont->ft_w);\r
324 >         font->ft_h=swapshort(oldfont->ft_h);\r
325 >         font->ft_baseline=swapshort(oldfont->ft_baseline);\r
326 >         font->ft_maxchar=oldfont->ft_maxchar;\r
327 >         font->ft_minchar=oldfont->ft_minchar;\r
328 >         font->ft_bytewidth=swapshort(oldfont->ft_bytewidth);\r
329\r
330 1307c1609
331 <               font->ft_widths = (short *) (((int) font->ft_widths) + ((ubyte *) font));\r
332 ---
333 >               font->ft_widths = (short *) (((int) oldfont->ft_widths) + ((ubyte *) oldfont));\r
334 1311c1613
335 <                       font->ft_widths[i] = SWAPSHORT(font->ft_widths[i]);\r
336 ---
337 >                       font->ft_widths[i] = swapshort(oldfont->ft_widths[i]);\r
338 1314c1616
339 <               font->ft_data = ((int) font->ft_data) + ((ubyte *) font);\r
340 ---
341 >               font->ft_data = ((int) oldfont->ft_data) + ((ubyte *) oldfont);\r
342 1330c1632
343 <               font->ft_data = ((unsigned char *) font) + sizeof(*font);\r
344 ---
345 >               font->ft_data = ((unsigned char *) oldfont) + sizeof(*oldfont);\r
346 1339c1641
347 <               font->ft_kerndata = ((int) font->ft_kerndata) + ((ubyte *) font);\r
348 ---
349 >               font->ft_kerndata = swapint(((int) oldfont->ft_kerndata) + ((ubyte *) oldfont));\r
350 1386a1689,1692
351\r
352 > #ifdef OGL\r
353 >       ogl_init_font(font);\r
354 > #endif\r