Beispiel #1
0
  void setup_font()
  {
    if
    (
      (cur_font != font_in->get()) ||
      (cur_render_type !=render_type->get()) ||
      (cur_glyph_size != glyph_size->get())
    )
    {
      vsx::file *fp;
      if ((fp = engine_state->filesystem->f_open(font_in->get().c_str())) == NULL)
      {
        printf("font not found: %s\n",cur_font.c_str());
        return;
      }
      cur_font = font_in->get();
      cur_render_type = render_type->get();
      cur_glyph_size = glyph_size->get();

      if (ftfont) {
        delete ftfont;
        ftfont = 0;
      }
      if (ftfont2) {
        delete ftfont2;
        ftfont2 = 0;
      }
      unsigned long size = engine_state->filesystem->f_get_size(fp);
      char* fdata = (char*)malloc(size);
      unsigned long bread = engine_state->filesystem->f_read((void*)fdata, size, fp);
      if (bread == size)
      {
        switch (cur_render_type)
        {
          case 0:
            ftfont = new FTGLTextureFont((unsigned char*)fdata, size);
          break;
          case 1:
            ftfont = new FTGLPolygonFont((unsigned char*)fdata, size);
            ftfont2 = new FTGLOutlineFont((unsigned char*)fdata, size);
          break;
        }
        ftfont->FaceSize((unsigned int)round(cur_glyph_size));
        ftfont->CharMap(ft_encoding_unicode);
        if (ftfont2) {
          ftfont2->FaceSize((unsigned int)round(cur_glyph_size));
          ftfont2->CharMap(ft_encoding_unicode);
        }
        loading_done = true;
      }
      engine_state->filesystem->f_close(fp);
    }
  }
const bool RegisterFont(const String& filename, int pointSize, const String& nickname)
{
	std::map<String,FTFont*>::iterator it = _fontCache.find(nickname);
	if(it != _fontCache.end())
	{
		UnRegisterFont(nickname);
	}
	
	if (theWorld.IsHighResScreen())
	{
		pointSize = pointSize * 2;
	}

	FTFont *font = new FTGLTextureFont(filename.c_str());
	if(font->Error())
	{
		sysLog.Log("Failed to open font " + filename);
		return false;
	}
	if(!font->FaceSize(pointSize))
	{
		sysLog.Log("Failed to set size.");
		return false;
	}
	font->CharMap(FT_ENCODING_NONE);
	font->UseDisplayList(true);

	_fontCache[nickname] = font;
	return true;
}
Beispiel #3
0
    AudicleFTGLFont( char * name ) { 
        
        glEnable ( GL_TEXTURE_2D );
        
        char fontlocation[512];
        strncpy ( fontlocation, fontpath, 512 );
        strncat ( fontlocation, name, 512 - strlen ( fontlocation ) );
        
        m_font = new FTGLTextureFont ( fontlocation );
        
        if ( m_font->Error() ) { 
            fprintf(stderr, "AudicleFTGLFont: font load error %d - exiting\n", m_font->Error() );
            exit(1);
        }
        else { 
            
        if ( !m_font->FaceSize(18) ) { 
            fprintf(stderr, "AudicleFTGLFont: font size error  %d - exiting\n", m_font->Error() );
            exit(1);
        }

        m_name = name;
        m_font->Depth(2);
        m_font->CharMap(ft_encoding_unicode);
    
        glDisable ( GL_TEXTURE_2D );
        
        float x1, y1, z1, x2, y2, z2;
        
        m_font->BBox( samplestring , x1, y1, z1, x2, y2, z2);
        m_height = y2;
        m_line_height = m_font->LineHeight();
        
        m_height_unit_scale = 1.0 / m_height ;
        m_line_unit_scale = 1.0 / m_line_height ;
        m_mono_width = m_height; 

        }
    }
Beispiel #4
0
// ----------------------------------------------------------------------------
FTFont* 
GSystemGL::SetupFont( const char * inPath, int inFontSize ) const
{
	FTFont * font = 0;

	char faceName2[40];
	strcpy(faceName2, inPath);

#ifdef WIN32 
	if( !strcmp(inPath,"Times") )
		strcpy(faceName2, "times.ttf");	
#endif

	switch (fFontType) {
		case kPixmapFont:
//			font = new FTGLPixmapFont(inPath);
			font = new FTGLPixmapFont((const char*)faceName2);
			break;
		case kBitmapFont:
			font = new FTGLBitmapFont((const char*)faceName2);
			break;
		case kOutlineFont:
			font = new FTGLOutlineFont((const char*)faceName2);
			break;
		case kPolygonFont:
			font = new FTGLPolygonFont((const char*)faceName2);
            glEnable( GL_TEXTURE_2D);
//            glBindTexture(GL_TEXTURE_2D, textureID);
			glDisable( GL_BLEND);
			break;
		case kExtrudeFont:
			font = new FTGLExtrdFont((const char*)faceName2);
			break;
		case kTextureFont:
			font = new FTGLTextureFont((const char*)faceName2);
			glEnable( GL_TEXTURE_2D);
			glDisable( GL_DEPTH_TEST);
			break;
	}

	if( !font || font->Error()) {
		cerr <<  "Failed to open font " << inPath << endl;
		delete font;
		return 0;
	}
	else {
//		font->Depth(20);   // extrusion distance for the font. Only for FTGLExtrdFont
		int cmc = font->CharMapCount();
		FT_Encoding encoding = ft_encoding_none;
		FT_Encoding* cml = font->CharMapList();
		for (int i=0; i<cmc; i++) {
			if (i==0) encoding = cml[i];
			if (cml[i] == ft_encoding_apple_roman) {
				encoding = ft_encoding_apple_roman;
				break;
			}
		}
		font->CharMap(encoding);
		font->FaceSize(inFontSize);
	}
	return font;
}