8 > #include "bitmap.h"
\r
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
20 > if (gr_message_color_level >= *(text_ptr-1)) \
\r
21 > FG_COLOR = *text_ptr - 1; \
\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
33 > #ifdef __ENV_MSDOS__
\r
41 > #include "../main/inferno.h"
\r
42 > #include "ogl_init.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
46 > int pow2ize(int x);//from ogl.c
\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
54 > w+=font->ft_widths[i];
\r
58 > return font->ft_w*(font->ft_maxchar-font->ft_minchar+1);
\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
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
76 > mprintf((0,"failed to fit (%ix%i, %ic)\n",w,h,nc));
\r
81 > while(y+font->ft_h<=h){
\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
90 > if (x+font->ft_w+gap>w)break;
\r
91 > x+=font->ft_w+gap;
\r
97 > y+=font->ft_h+gap;
\r
101 > }while(nc!=nchars);
\r
104 > mprintf((0,"fit: %ix%i %i tries\n",w,h,tries));
\r
106 > if (w*h==smallest){//this gives squarer sizes priority (ie, 128x128 would be better than 512*32)
\r
108 > if (w/h<smallprop){
\r
110 > smallest++;//hack
\r
113 > if (h/w<smallprop){
\r
115 > smallest++;//hack
\r
119 > if (w*h<smallest){
\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
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
137 > // char data[32*32*4];
\r
139 > int gap=0;//having a gap just wastes ram, since we don't filter text textures at all.
\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
145 > font->ft_parent_bitmap.gltexture=ogl_get_free_texture();
\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
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
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
164 > if (curx+w+gap>tw){
\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
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
180 > // gr_init_bitmap(&font->ft_bitmaps[i],BM_LINEAR,0,0,w,h,w,font->);
\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
188 > fp = font->ft_data + i * BITS_TO_BYTES(w)*h;
\r
189 > for (y=0;y<h;y++){
\r
191 > for (x=0; x< w; x++ )
\r
193 > if (BitMask==0) {
\r
198 > if (bits & BitMask)
\r
199 > font->ft_parent_bitmap.bm_data[curx+x+(cury+y)*tw]=white;
\r
201 > font->ft_parent_bitmap.bm_data[curx+x+(cury+y)*tw]=255;
\r
206 > gr_init_sub_bitmap(&font->ft_bitmaps[i],&font->ft_parent_bitmap,curx,cury,w,h);
\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
222 > font->ft_parent_bitmap.gltexture->internalformat=ogl_rgba_format;
\r
223 > font->ft_parent_bitmap.gltexture->format=GL_RGBA;
\r
226 > ogl_loadbmtexture_m(&font->ft_parent_bitmap,0);
\r
229 > int ogl_internal_string(int x, int y, char *s )
\r
231 > ubyte * text_ptr, * next_row, * text_ptr1;
\r
232 > int width, spacing,letter;
\r
234 > int orig_color=FG_COLOR;//to allow easy reseting to default string color with colored strings -MPM
\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
244 > text_ptr1 = next_row;
\r
247 > text_ptr = text_ptr1;
\r
251 > if (xx==0x8000) //centered
\r
252 > xx = get_centered_x(text_ptr);
\r
254 > while (*text_ptr)
\r
256 > if (*text_ptr == '\n' )
\r
258 > next_row = &text_ptr[1];
\r
263 > letter = *text_ptr-FMINCHAR;
\r
265 > get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
\r
267 > if (!INFONT(letter) || *text_ptr<=0x06) { //not in font, draw as space
\r
268 > CHECK_EMBEDDED_COLORS() else{
\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
281 > if (grd_curcanv->cv_bitmap.bm_type==BM_OGL)
\r
282 > ogl_ubitmapm_c(xx,yy,&FONT->ft_bitmaps[letter],FG_COLOR);
\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
297 > int gr_internal_color_string(int x, int y, char *s ){
\r
298 > return ogl_internal_string(x,y,s);
\r
304 > #ifdef __ENV_MSDOS__
\r
308 > #define swapshort(a) (a)
\r
309 > #define swapint(a) (a)
\r
311 > old_grs_font *oldfont;
\r
313 < font = (grs_font *) malloc(datasize);
\r
315 > oldfont = (old_grs_font *) malloc(datasize);
\r
316 > font = (grs_font *) malloc(sizeof(grs_font));
\r
317 > font->oldfont = oldfont;
\r
319 < cfread(font,1,datasize,fontfile);
\r
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
331 < font->ft_widths = (short *) (((int) font->ft_widths) + ((ubyte *) font));
\r
333 > font->ft_widths = (short *) (((int) oldfont->ft_widths) + ((ubyte *) oldfont));
\r
335 < font->ft_widths[i] = SWAPSHORT(font->ft_widths[i]);
\r
337 > font->ft_widths[i] = swapshort(oldfont->ft_widths[i]);
\r
339 < font->ft_data = ((int) font->ft_data) + ((ubyte *) font);
\r
341 > font->ft_data = ((int) oldfont->ft_data) + ((ubyte *) oldfont);
\r
343 < font->ft_data = ((unsigned char *) font) + sizeof(*font);
\r
345 > font->ft_data = ((unsigned char *) oldfont) + sizeof(*oldfont);
\r
347 < font->ft_kerndata = ((int) font->ft_kerndata) + ((ubyte *) font);
\r
349 > font->ft_kerndata = swapint(((int) oldfont->ft_kerndata) + ((ubyte *) oldfont));
\r
353 > ogl_init_font(font);
\r