12 > //hack to allow color codes to be embedded in strings -MPM
13 > //note we subtract one from color, since 255 is "transparent" so it'll never be used, and 0 would otherwise end the string.
14 > //function must already have orig_color var set (or they could be passed as args...)
15 > //perhaps some sort of recursive orig_color type thing would be better, but that would be way too much trouble for little gain
16 > int gr_message_color_level=1;
17 > #define CHECK_EMBEDDED_COLORS() if ((*text_ptr >= 0x01) && (*text_ptr <= 0x03)) { \
20 > if (gr_message_color_level >= *(text_ptr-1)) \
21 > FG_COLOR = *text_ptr - 1; \
25 > else if ((*text_ptr >= 0x04) && (*text_ptr <= 0x06)){ \
26 > if (gr_message_color_level >= *text_ptr - 3) \
27 > FG_COLOR=orig_color; \
33 > #ifdef __ENV_MSDOS__
41 > #include "../main/inferno.h"
42 > #include "ogl_init.h"
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
46 > int pow2ize(int x);//from ogl.c
48 > int get_font_total_width(grs_font * font){
49 > if (font->ft_flags & FT_PROPORTIONAL){
50 > int i,w=0,c=font->ft_minchar;
51 > for (i=0;c<=font->ft_maxchar;i++,c++){
52 > if (font->ft_widths[i]<0)
54 > w+=font->ft_widths[i];
58 > return font->ft_w*(font->ft_maxchar-font->ft_minchar+1);
61 > void ogl_font_choose_size(grs_font * font,int gap,int *rw,int *rh){
62 > int nchars = font->ft_maxchar-font->ft_minchar+1;
63 > int r,x,y,nc=0,smallest=999999,smallr=-1,tries;
64 > int smallprop=10000;
66 > for (h=32;h<=256;h*=2){
67 > // h=pow2ize(font->ft_h*rows+gap*(rows-1));
68 > if (font->ft_h>h)continue;
69 > r=(h/(font->ft_h+gap));
70 > w=pow2ize((get_font_total_width(font)+(nchars-r)*gap)/r);
76 > mprintf((0,"failed to fit (%ix%i, %ic)\n",w,h,nc));
81 > while(y+font->ft_h<=h){
86 > if (font->ft_flags & FT_PROPORTIONAL){
87 > if (x+font->ft_widths[nc]+gap>w)break;
88 > x+=font->ft_widths[nc++]+gap;
90 > if (x+font->ft_w+gap>w)break;
101 > }while(nc!=nchars);
104 > mprintf((0,"fit: %ix%i %i tries\n",w,h,tries));
106 > if (w*h==smallest){//this gives squarer sizes priority (ie, 128x128 would be better than 512*32)
108 > if (w/h<smallprop){
113 > if (h/w<smallprop){
127 > Error("couldn't fit font?\n");
128 > mprintf((0,"using %ix%i\n",*rw,*rh));
129 > printf("using %ix%i\n",*rw,*rh);
133 > void ogl_init_font(grs_font * font){
134 > int nchars = font->ft_maxchar-font->ft_minchar+1;
135 > int i,w,h,tw,th,x,y,curx=0,cury=0;
137 > // char data[32*32*4];
139 > int gap=0;//having a gap just wastes ram, since we don't filter text textures at all.
141 > ogl_font_choose_size(font,gap,&tw,&th);
142 > data=malloc(tw*th);
143 > gr_init_bitmap(&font->ft_parent_bitmap,BM_LINEAR,0,0,tw,th,tw,data);
145 > font->ft_parent_bitmap.gltexture=ogl_get_free_texture();
147 > font->ft_bitmaps=(grs_bitmap*)malloc( nchars * sizeof(grs_bitmap));
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));
153 > for(i=0;i<nchars;i++){
154 > // s[0]=font->ft_minchar+i;
155 > // gr_get_string_size(s,&w,&h,&aw);
156 > if (font->ft_flags & FT_PROPORTIONAL)
157 > w=font->ft_widths[i];
160 > // mprintf((0,"char %i(%ix%i): ",i,w,h));
162 > mprintf((0,"grr\n"));continue;
164 > if (curx+w+gap>tw){
169 > Error("font doesn't really fit (%i/%i)?\n",i,nchars);
170 > if (font->ft_flags & FT_COLOR) {
171 > if (font->ft_flags & FT_PROPORTIONAL)
172 > fp = font->ft_chars[i];
174 > fp = font->ft_data + i * w*h;
177 > font->ft_parent_bitmap.bm_data[curx+x+(cury+y)*tw]=fp[x+y*w];
180 > // gr_init_bitmap(&font->ft_bitmaps[i],BM_LINEAR,0,0,w,h,w,font->);
182 > int BitMask,bits=0,white=gr_find_closest_color(63,63,63);
183 > // if (w*h>sizeof(data))
184 > // Error("ogl_init_font: toobig\n");
185 > if (font->ft_flags & FT_PROPORTIONAL)
186 > fp = font->ft_chars[i];
188 > fp = font->ft_data + i * BITS_TO_BYTES(w)*h;
191 > for (x=0; x< w; x++ )
198 > if (bits & BitMask)
199 > font->ft_parent_bitmap.bm_data[curx+x+(cury+y)*tw]=white;
201 > font->ft_parent_bitmap.bm_data[curx+x+(cury+y)*tw]=255;
206 > gr_init_sub_bitmap(&font->ft_bitmaps[i],&font->ft_parent_bitmap,curx,cury,w,h);
210 > if (!(font->ft_flags & FT_COLOR)) {
211 > //use GL_INTENSITY instead of GL_RGB
212 > if (ogl_intensity4_ok){
213 > font->ft_parent_bitmap.gltexture->internalformat=GL_INTENSITY4;
214 > font->ft_parent_bitmap.gltexture->format=GL_LUMINANCE;
215 > }else if (ogl_luminance4_alpha4_ok){
216 > font->ft_parent_bitmap.gltexture->internalformat=GL_LUMINANCE4_ALPHA4;
217 > font->ft_parent_bitmap.gltexture->format=GL_LUMINANCE_ALPHA;
218 > }else if (ogl_rgba2_ok){
219 > font->ft_parent_bitmap.gltexture->internalformat=GL_RGBA2;
220 > font->ft_parent_bitmap.gltexture->format=GL_RGBA;
222 > font->ft_parent_bitmap.gltexture->internalformat=ogl_rgba_format;
223 > font->ft_parent_bitmap.gltexture->format=GL_RGBA;
226 > ogl_loadbmtexture_m(&font->ft_parent_bitmap,0);
229 > int ogl_internal_string(int x, int y, char *s )
231 > ubyte * text_ptr, * next_row, * text_ptr1;
232 > int width, spacing,letter;
234 > int orig_color=FG_COLOR;//to allow easy reseting to default string color with colored strings -MPM
240 > if (grd_curscreen->sc_canvas.cv_bitmap.bm_type != BM_OGL)
242 > while (next_row != NULL)
244 > text_ptr1 = next_row;
247 > text_ptr = text_ptr1;
251 > if (xx==0x8000) //centered
252 > xx = get_centered_x(text_ptr);
256 > if (*text_ptr == '\n' )
258 > next_row = &text_ptr[1];
263 > letter = *text_ptr-FMINCHAR;
265 > get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
267 > if (!INFONT(letter) || *text_ptr<=0x06) { //not in font, draw as space
268 > CHECK_EMBEDDED_COLORS() else{
275 > // ogl_ubitblt(FONT->ft_bitmaps[letter].bm_w,FONT->ft_bitmaps[letter].bm_h,xx,yy,0,0,&FONT->ft_bitmaps[letter],NULL);
276 > // if (*text_ptr>='0' && *text_ptr<='9'){
277 > printf("%p\n",&FONT->ft_bitmaps[letter]);
278 > if (FFLAGS&FT_COLOR)
279 > gr_ubitmapm(xx,yy,&FONT->ft_bitmaps[letter]);
281 > if (grd_curcanv->cv_bitmap.bm_type==BM_OGL)
282 > ogl_ubitmapm_c(xx,yy,&FONT->ft_bitmaps[letter],FG_COLOR);
284 > Error("ogl_internal_string: non-color string to non-ogl dest\n");
285 > // gr_ubitmapm(xx,yy,&FONT->ft_bitmaps[letter]);//ignores color..
297 > int gr_internal_color_string(int x, int y, char *s ){
298 > return ogl_internal_string(x,y,s);
304 > #ifdef __ENV_MSDOS__
308 > #define swapshort(a) (a)
309 > #define swapint(a) (a)
311 > old_grs_font *oldfont;
313 < font = (grs_font *) malloc(datasize);
315 > oldfont = (old_grs_font *) malloc(datasize);
316 > font = (grs_font *) malloc(sizeof(grs_font));
317 > font->oldfont = oldfont;
319 < cfread(font,1,datasize,fontfile);
321 > cfread(oldfont,1,datasize,fontfile);
322 > font->ft_flags=swapshort(oldfont->ft_flags);
323 > font->ft_w=swapshort(oldfont->ft_w);
324 > font->ft_h=swapshort(oldfont->ft_h);
325 > font->ft_baseline=swapshort(oldfont->ft_baseline);
326 > font->ft_maxchar=oldfont->ft_maxchar;
327 > font->ft_minchar=oldfont->ft_minchar;
328 > font->ft_bytewidth=swapshort(oldfont->ft_bytewidth);
331 < font->ft_widths = (short *) (((int) font->ft_widths) + ((ubyte *) font));
333 > font->ft_widths = (short *) (((int) oldfont->ft_widths) + ((ubyte *) oldfont));
335 < font->ft_widths[i] = SWAPSHORT(font->ft_widths[i]);
337 > font->ft_widths[i] = swapshort(oldfont->ft_widths[i]);
339 < font->ft_data = ((int) font->ft_data) + ((ubyte *) font);
341 > font->ft_data = ((int) oldfont->ft_data) + ((ubyte *) oldfont);
343 < font->ft_data = ((unsigned char *) font) + sizeof(*font);
345 > font->ft_data = ((unsigned char *) oldfont) + sizeof(*oldfont);
347 < font->ft_kerndata = ((int) font->ft_kerndata) + ((ubyte *) font);
349 > font->ft_kerndata = swapint(((int) oldfont->ft_kerndata) + ((ubyte *) oldfont));
353 > ogl_init_font(font);