version 1.4 | | version 1.5 |
---|
| | |
* Graphical routines for drawing fonts. | | * Graphical routines for drawing fonts. |
* | | * |
* $Log$ | | * $Log$ |
| | * Revision 1.5 1999/09/30 23:02:26 donut |
| | * opengl direct support for ingame and normal menus, fonts as textures, and automap support |
| | * |
* Revision 1.4 1999/09/21 04:05:54 donut | | * Revision 1.4 1999/09/21 04:05:54 donut |
* mostly complete OGL implementation (still needs bitmap handling (reticle), and door/fan textures are corrupt) | | * mostly complete OGL implementation (still needs bitmap handling (reticle), and door/fan textures are corrupt) |
* | | * |
| | |
| | |
#define BITS_TO_BYTES(x) (((x)+7)>>3) | | #define BITS_TO_BYTES(x) (((x)+7)>>3) |
| | |
#ifdef OGL | | |
#define FONT_USE_GRPIXEL | | |
#endif | | |
| | |
| | |
int gr_internal_string_clipped(int x, int y, char *s ); | | int gr_internal_string_clipped(int x, int y, char *s ); |
int gr_internal_string_clipped_m(int x, int y, char *s ); | | int gr_internal_string_clipped_m(int x, int y, char *s ); |
| | |
int w,w2,s2; | | int w,w2,s2; |
| | |
for (w=0;*s!=0 && *s!='\n';s++) { | | for (w=0;*s!=0 && *s!='\n';s++) { |
| | if (*s<=0x06) |
| | continue;//skip color codes. |
get_char_width(s[0],s[1],&w2,&s2); | | get_char_width(s[0],s[1],&w2,&s2); |
w += s2; | | w += s2; |
} | | } |
| | |
| | |
bits = 0; | | bits = 0; |
| | |
#ifdef FONT_USE_GRPIXEL | | |
VideoOffset1 = x; | | |
#else | | |
VideoOffset1 = y * ROWSIZE + x; | | VideoOffset1 = y * ROWSIZE + x; |
#endif | | |
| | |
next_row = s; | | next_row = s; |
| | |
| | |
| | |
if (x==0x8000) { //centered | | if (x==0x8000) { //centered |
int xx = get_centered_x(text_ptr1); | | int xx = get_centered_x(text_ptr1); |
#ifdef FONT_USE_GRPIXEL | | |
VideoOffset1 = xx; | | |
#else | | |
VideoOffset1 = y * ROWSIZE + xx; | | VideoOffset1 = y * ROWSIZE + xx; |
#endif | | |
} | | } |
| | |
for (r=0; r<FHEIGHT; r++) | | for (r=0; r<FHEIGHT; r++) |
| | |
} | | } |
| | |
if (bits & BitMask) | | if (bits & BitMask) |
#ifdef FONT_USE_GRPIXEL | | |
gr_upixelc(VideoOffset++,y,FG_COLOR); | | |
#else | | |
DATA[VideoOffset++] = (unsigned char) FG_COLOR; | | DATA[VideoOffset++] = (unsigned char) FG_COLOR; |
#endif | | |
else | | else |
VideoOffset++; | | VideoOffset++; |
BitMask >>= 1; | | BitMask >>= 1; |
| | |
VideoOffset += spacing-width; | | VideoOffset += spacing-width; |
} | | } |
| | |
#ifndef FONT_USE_GRPIXEL | | |
VideoOffset1 += ROWSIZE; | | VideoOffset1 += ROWSIZE; |
#endif | | |
y++; | | y++; |
} | | } |
} | | } |
| | |
return 0; | | return 0; |
} | | } |
| | |
| | #ifdef OGL |
| | #include "../main/inferno.h" |
| | #include "ogl_init.h" |
| | //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 |
| | void ogl_init_font(grs_font * font){ |
| | int nchars = font->ft_maxchar-font->ft_minchar+1; |
| | int i,w,h; |
| | char *fp; |
| | // char data[32*32*4]; |
| | char *data; |
| | // char s[2]; |
| | font->ft_bitmaps=(grs_bitmap*)malloc( nchars * sizeof(grs_bitmap)); |
| | mprintf((0,"ogl_init_font %s, %s, nchars=%i\n",(font->ft_flags & FT_PROPORTIONAL)?"proportional":"fixedwidth",(font->ft_flags & FT_COLOR)?"color":"mono",nchars)); |
| | // s[1]=0; |
| | h=font->ft_h; |
| | for(i=0;i<nchars;i++){ |
| | // s[0]=font->ft_minchar+i; |
| | // gr_get_string_size(s,&w,&h,&aw); |
| | if (font->ft_flags & FT_PROPORTIONAL) |
| | w=font->ft_widths[i]; |
| | else |
| | w=font->ft_w; |
| | mprintf((0,"char %i(%ix%i): ",i,w,h)); |
| | if (w<1 || w>256){ |
| | mprintf((0,"grr\n"));continue; |
| | } |
| | if (font->ft_flags & FT_COLOR) { |
| | if (font->ft_flags & FT_PROPORTIONAL) |
| | fp = font->ft_chars[i]; |
| | else |
| | fp = font->ft_data + i * w*h; |
| | // gr_init_bitmap(&font->ft_bitmaps[i],BM_LINEAR,0,0,w,h,w,font->); |
| | }else{ |
| | int j,k,BitMask,bits=0,dofs=0,white=gr_find_closest_color(63,63,63); |
| | // if (w*h>sizeof(data)) |
| | // Error("ogl_init_font: toobig\n"); |
| | data=malloc(w*h); |
| | if (font->ft_flags & FT_PROPORTIONAL) |
| | fp = font->ft_chars[i]; |
| | else |
| | fp = font->ft_data + i * BITS_TO_BYTES(w)*h; |
| | for (k=0;k<h;k++){ |
| | BitMask=0; |
| | for (j=0; j< w; j++ ) |
| | { |
| | if (BitMask==0) { |
| | bits = *fp++; |
| | BitMask = 0x80; |
| | } |
| | |
| | if (bits & BitMask) |
| | data[dofs++] = white; |
| | else |
| | data[dofs++] = 255; |
| | BitMask >>= 1; |
| | } |
| | } |
| | fp=data; |
| | } |
| | gr_init_bitmap(&font->ft_bitmaps[i],BM_LINEAR,0,0,w,h,w,fp); |
| | ogl_loadbmtexture_m(&font->ft_bitmaps[i],0); |
| | // font->ft_bitmaps[i].bm_data=NULL;//no longer needed. |
| | } |
| | } |
| | |
| | int ogl_internal_string(int x, int y, char *s ) |
| | { |
| | ubyte * text_ptr, * next_row, * text_ptr1; |
| | int width, spacing,letter; |
| | int xx,yy; |
| | int orig_color=FG_COLOR;//to allow easy reseting to default string color with colored strings -MPM |
| | |
| | next_row = s; |
| | |
| | yy = y; |
| | |
| | if (grd_curscreen->sc_canvas.cv_bitmap.bm_type != BM_OGL) |
| | Error("carp.\n"); |
| | while (next_row != NULL) |
| | { |
| | text_ptr1 = next_row; |
| | next_row = NULL; |
| | |
| | text_ptr = text_ptr1; |
| | |
| | xx = x; |
| | |
| | if (xx==0x8000) //centered |
| | xx = get_centered_x(text_ptr); |
| | |
| | while (*text_ptr) |
| | { |
| | if (*text_ptr == '\n' ) |
| | { |
| | next_row = &text_ptr[1]; |
| | yy += FHEIGHT; |
| | break; |
| | } |
| | |
| | letter = *text_ptr-FMINCHAR; |
| | |
| | get_char_width(text_ptr[0],text_ptr[1],&width,&spacing); |
| | |
| | if (!INFONT(letter)) { //not in font, draw as space |
| | CHECK_EMBEDDED_COLORS() else{ |
| | xx += spacing; |
| | text_ptr++; |
| | } |
| | continue; |
| | } |
| | |
| | if (FFLAGS&FT_COLOR) |
| | gr_ubitmapm(xx,yy,&FONT->ft_bitmaps[letter]); |
| | else{ |
| | if (grd_curcanv->cv_bitmap.bm_type==BM_OGL) |
| | ogl_ubitmapm_c(xx,yy,&FONT->ft_bitmaps[letter],FG_COLOR); |
| | else |
| | gr_ubitmapm(xx,yy,&FONT->ft_bitmaps[letter]);//ignores color.. |
| | } |
| | |
| | xx += spacing; |
| | |
| | text_ptr++; |
| | } |
| | |
| | } |
| | return 0; |
| | } |
| | #endif //OGL |
| | |
int gr_string(int x, int y, char *s ) | | int gr_string(int x, int y, char *s ) |
{ | | { |
int w, h, aw; | | int w, h, aw; |
| | |
// Partially clipped... | | // Partially clipped... |
//mprintf( (0, "Text '%s' at (%d,%d) is getting clipped!\n", s, x, y )); | | //mprintf( (0, "Text '%s' at (%d,%d) is getting clipped!\n", s, x, y )); |
} | | } |
| | |
// Partially clipped... | | // Partially clipped... |
| | #ifdef OGL |
| | return ogl_internal_string(x,y,s); |
| | #else |
| | |
if (FFLAGS & FT_COLOR) | | if (FFLAGS & FT_COLOR) |
return gr_internal_color_string( x, y, s); | | return gr_internal_color_string( x, y, s); |
| | |
return gr_internal_string_clipped_m( x, y, s ); | | return gr_internal_string_clipped_m( x, y, s ); |
| | |
return gr_internal_string_clipped( x, y, s ); | | return gr_internal_string_clipped( x, y, s ); |
| | #endif |
} | | } |
| | |
int gr_ustring(int x, int y, char *s ) | | int gr_ustring(int x, int y, char *s ) |
{ | | { |
| | #ifdef OGL |
| | return ogl_internal_string(x,y,s); |
| | #else |
if (FFLAGS & FT_COLOR) { | | if (FFLAGS & FT_COLOR) { |
| | |
return gr_internal_color_string(x,y,s); | | return gr_internal_color_string(x,y,s); |
| | |
#endif | | #endif |
} | | } |
return 0; | | return 0; |
| | #endif |
} | | } |
| | |
| | |
| | |
{ | | { |
if ( font->ft_chars ) | | if ( font->ft_chars ) |
free( font->ft_chars ); | | free( font->ft_chars ); |
| | free( font->oldfont ); |
| | #ifdef OGL |
| | if (font->ft_bitmaps) |
| | free( font->ft_bitmaps ); |
| | #endif |
free( font ); | | free( font ); |
} | | } |
} | | } |
| | |
| | |
grs_font * gr_init_font( char * fontname ) | | grs_font * gr_init_font( char * fontname ) |
{ | | { |
grs_font *font; | | old_grs_font *font; |
| | grs_font *newfont; |
int i; | | int i; |
unsigned char * ptr; | | unsigned char * ptr; |
int nchars; | | int nchars; |
| | |
if (file_id != 0x4e465350) /* 'NFSP' */ | | if (file_id != 0x4e465350) /* 'NFSP' */ |
Error( "File %s is not a font file", fontname ); | | Error( "File %s is not a font file", fontname ); |
| | |
font = (grs_font *) malloc(datasize); | | font = (old_grs_font *) malloc(datasize); |
| | newfont = (grs_font *) malloc(sizeof(grs_font)); |
| | newfont->oldfont=font; |
| | |
cfread(font,1,datasize,fontfile); | | cfread(font,1,datasize,fontfile); |
| | |
| | |
| | |
cfclose(fontfile); | | cfclose(fontfile); |
| | |
| | memcpy(newfont,font,(ubyte*)&newfont->oldfont-(ubyte*)newfont);//fill in newfont data from oldfont struct |
| | mprintf((0,"%i %i %i\n",sizeof(grs_font),sizeof(old_grs_font),(ubyte*)&newfont->oldfont-(ubyte*)newfont)); |
| | |
| | #ifdef OGL |
| | ogl_init_font(newfont); |
| | #endif |
| | |
//set curcanv vars | | //set curcanv vars |
| | |
FONT = font; | | FONT = newfont; |
FG_COLOR = 0; | | FG_COLOR = 0; |
BG_COLOR = 0; | | BG_COLOR = 0; |
| | |
return font; | | return newfont; |
| | |
} | | } |
| | |