bool CWin32Font::Create(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags) { FT_Library library = FontManager().GetFTLibrary(); if (!library) return false; const unsigned char *file = FontManager().GetFontFile(windowsFontName); if (!file) { m_szName = UTL_INVAL_SYMBOL; return false; } FT_Face face; FT_Open_Args args; args.flags = FT_OPEN_MEMORY | FT_OPEN_DRIVER; args.memory_base = file + sizeof(int); args.memory_size = *((const int *)file); args.stream = NULL; args.driver = FT_Get_Module(library, "truetype"); if (FT_Open_Face(library, &args, 0, &face)) { m_szName = UTL_INVAL_SYMBOL; return false; } m_FTFace = face; m_szName = windowsFontName; m_iTall = tall; m_iFlags = flags & WIN32FONT_FLAGS_MASK; m_iScanLines = scanlines; m_iBlur = blur; m_iDropShadowOffset = (flags & vgui::ISurface::FONTFLAG_DROPSHADOW) ? 1 : 0; m_iOutlineSize = (flags & vgui::ISurface::FONTFLAG_OUTLINE) ? 1 : 0; m_bRotary = (flags & vgui::ISurface::FONTFLAG_ROTARY) ? 1 : 0; m_bAdditive = (flags & vgui::ISurface::FONTFLAG_ADDITIVE) ? 1 : 0; tall <<= 6; FT_Set_Char_Size(face, tall, tall, 72, 72); float scale = ((float)(face->size->metrics.ascender) * (1.0f / 64.0f)) / (float)(face->ascender); m_iBaseline = (int)(ceilf((float)(face->bbox.yMax) * scale)); m_iHeight = m_iBaseline + (int)(ceilf((float)(-face->bbox.yMin) * scale)) + m_iDropShadowOffset + (m_iOutlineSize << 1); m_iMaxCharWidth = (face->size->metrics.max_advance + 127) >> 6; m_iAscent = (int)(ceilf((float)(face->ascender) * scale)); m_rgiBitmapSize[0] = m_iMaxCharWidth + (m_iOutlineSize << 1); m_rgiBitmapSize[1] = m_iHeight; return true; }
Manager::Manager( const char* name, int width, int height, Engine::WindowMode wm ): RTTI_CLASS_DEFINE( Manager ), m_engine( 0 ), m_game( 0 ), m_pushState( 0 ), m_progressState( 0 ), m_progressStateDefault( 0 ), m_popState( false ), m_changeState( false ), m_loading( false ), m_states( 0 ), m_scenes( 0 ), m_materials( 0 ), m_effects( 0 ), m_fonts( 0 ), m_textures( 0 ), m_canvases( 0 ), m_assets( 0 ), m_assetsLoading( 0 ), m_actors( 0 ), m_controls( 0 ), m_collisions( 0 ), m_audio( 0 ) { m_engine = xnew Engine(); m_engine->initiation( name, width, height, wm ); m_states = xnew Stack< IState >(); m_scenes = xnew SceneManager(); m_materials = xnew MaterialManager(); m_effects = xnew EffectManager(); m_fonts = xnew FontManager(); m_textures = xnew TextureManager(); m_canvases = xnew CanvasManager(); m_assets = xnew AssetManager(); m_assetsLoading = xnew AssetManager(); m_actors = xnew Stack< ActorManager >(); m_controls = xnew Stack< ControlManager >(); m_collisions = xnew Stack< CollisionManager >(); m_audio = xnew AudioManager(); Global::use().engine = m_engine; Global::use().scenes = m_scenes; Global::use().materials = m_materials; Global::use().effects = m_effects; Global::use().fonts = m_fonts; Global::use().textures = m_textures; Global::use().canvases = m_canvases; Global::use().assets = m_assets; Global::use().assetsLoading = m_assetsLoading; Global::use().actors = 0; Global::use().controls = 0; Global::use().collisions = 0; Global::use().audio = m_audio; }
//--------------------------------------------------------------------- OverlaySystem::OverlaySystem() { mOverlayManager = OGRE_NEW Ogre::OverlayManager(); mOverlayManager->addOverlayElementFactory(OGRE_NEW Ogre::PanelOverlayElementFactory()); mOverlayManager->addOverlayElementFactory(OGRE_NEW Ogre::BorderPanelOverlayElementFactory()); mOverlayManager->addOverlayElementFactory(OGRE_NEW Ogre::TextAreaOverlayElementFactory()); mFontManager = OGRE_NEW FontManager(); #if OGRE_PROFILING mProfileListener = new Ogre::OverlayProfileSessionListener(); Ogre::Profiler* prof = Ogre::Profiler::getSingletonPtr(); if (prof) { prof->addListener(mProfileListener); } #endif }
//----------------------------------------------------------------------- Root::Root(const String& pluginFileName, const String& configFileName, const String& logFileName) : mLogManager(0) , mRenderSystemCapabilitiesManager(0) , mNextFrame(0) , mFrameSmoothingTime(0.0f) , mNextMovableObjectTypeFlag(1) , mIsInitialised(false) { // superclass will do singleton checking String msg; // Init mActiveRenderer = 0; mVersion = StringConverter::toString(OGRE_VERSION_MAJOR) + "." + StringConverter::toString(OGRE_VERSION_MINOR) + "." + StringConverter::toString(OGRE_VERSION_PATCH) + OGRE_VERSION_SUFFIX + " " + "(" + OGRE_VERSION_NAME + ")"; mConfigFileName = configFileName; // Create log manager and default log file if there is no log manager yet if(LogManager::getSingletonPtr() == 0) { mLogManager = OGRE_NEW LogManager(); mLogManager->createLog(logFileName, true, true); } // Dynamic library manager mDynLibManager = OGRE_NEW DynLibManager(); mArchiveManager = OGRE_NEW ArchiveManager(); // ResourceGroupManager mResourceGroupManager = OGRE_NEW ResourceGroupManager(); // ResourceBackgroundQueue mResourceBackgroundQueue = OGRE_NEW ResourceBackgroundQueue(); // Create SceneManager enumerator (note - will be managed by singleton) mSceneManagerEnum = OGRE_NEW SceneManagerEnumerator(); mCurrentSceneManager = NULL; mShadowTextureManager = OGRE_NEW ShadowTextureManager(); mRenderSystemCapabilitiesManager = OGRE_NEW RenderSystemCapabilitiesManager(); // ..material manager mMaterialManager = OGRE_NEW MaterialManager(); // Mesh manager mMeshManager = OGRE_NEW MeshManager(); // Skeleton manager mSkeletonManager = OGRE_NEW SkeletonManager(); // ..particle system manager mParticleManager = OGRE_NEW ParticleSystemManager(); // Compiler manager //mCompilerManager = OGRE_NEW ScriptCompilerManager(); mTimer = OGRE_NEW Timer(); // Overlay manager mOverlayManager = OGRE_NEW OverlayManager(); mPanelFactory = OGRE_NEW PanelOverlayElementFactory(); mOverlayManager->addOverlayElementFactory(mPanelFactory); mBorderPanelFactory = OGRE_NEW BorderPanelOverlayElementFactory(); mOverlayManager->addOverlayElementFactory(mBorderPanelFactory); mTextAreaFactory = OGRE_NEW TextAreaOverlayElementFactory(); mOverlayManager->addOverlayElementFactory(mTextAreaFactory); // Font manager mFontManager = OGRE_NEW FontManager(); #if OGRE_PROFILING // Profiler mProfiler = OGRE_NEW Profiler(); Profiler::getSingleton().setTimer(mTimer); #endif mFileSystemArchiveFactory = OGRE_NEW FileSystemArchiveFactory(); ArchiveManager::getSingleton().addArchiveFactory( mFileSystemArchiveFactory ); mZipArchiveFactory = OGRE_NEW ZipArchiveFactory(); ArchiveManager::getSingleton().addArchiveFactory( mZipArchiveFactory ); #if OGRE_NO_FREEIMAGE == 0 // Register image codecs FreeImageCodec::startup(); #endif #if OGRE_NO_DEVIL == 0 // Register image codecs ILCodecs::registerCodecs(); #endif #if OGRE_NO_DDS_CODEC == 0 // Register image codecs DDSCodec::startup(); #endif mHighLevelGpuProgramManager = OGRE_NEW HighLevelGpuProgramManager(); mExternalTextureSourceManager = OGRE_NEW ExternalTextureSourceManager(); mCompositorManager = OGRE_NEW CompositorManager(); mCompilerManager = OGRE_NEW ScriptCompilerManager(); // Auto window mAutoWindow = 0; // instantiate and register base movable factories mEntityFactory = OGRE_NEW EntityFactory(); addMovableObjectFactory(mEntityFactory); mLightFactory = OGRE_NEW LightFactory(); addMovableObjectFactory(mLightFactory); mBillboardSetFactory = OGRE_NEW BillboardSetFactory(); addMovableObjectFactory(mBillboardSetFactory); mManualObjectFactory = OGRE_NEW ManualObjectFactory(); addMovableObjectFactory(mManualObjectFactory); mBillboardChainFactory = OGRE_NEW BillboardChainFactory(); addMovableObjectFactory(mBillboardChainFactory); mRibbonTrailFactory = OGRE_NEW RibbonTrailFactory(); addMovableObjectFactory(mRibbonTrailFactory); // Load plugins if (!pluginFileName.empty()) loadPlugins(pluginFileName); LogManager::getSingleton().logMessage("*-*-* OGRE Initialising"); msg = "*-*-* Version " + mVersion; LogManager::getSingleton().logMessage(msg); // Can't create managers until initialised mControllerManager = 0; mFirstTimePostWindowInit = false; }
//----------------------------------------------------------------------------- // Purpose: creates the font. returns false if the font cannot be mounted. //----------------------------------------------------------------------------- bool CBitmapFont::Create( const char *pFontFilename, float scalex, float scaley, int flags ) { MEM_ALLOC_CREDIT(); if ( !pFontFilename || !pFontFilename[0] ) { return false; } CUtlSymbol symbol; char fontName[MAX_PATH]; Q_FileBase( pFontFilename, fontName, MAX_PATH ); Q_strlower( fontName ); symbol = fontName; // find a match that can use same entries BitmapFontTable_t *pFontTable = NULL; for ( int i=0; i<g_BitmapFontTable.Count(); i++ ) { if ( symbol == g_BitmapFontTable[i].m_szName ) { m_bitmapFontHandle = i; pFontTable = &g_BitmapFontTable[m_bitmapFontHandle]; break; } } if ( !pFontTable ) { void *pBuf = NULL; int nLength; nLength = FontManager().FileSystem()->ReadFileEx( pFontFilename, "GAME", &pBuf ); if ( nLength <= 0 || !pBuf ) { // not found return false; } if ( ((BitmapFont_t*)pBuf)->m_id != LittleLong( BITMAPFONT_ID ) || ((BitmapFont_t*)pBuf)->m_Version != LittleLong( BITMAPFONT_VERSION ) ) { // bad version return false; } if ( IsX360() ) { CByteswap swap; swap.ActivateByteSwapping( true ); swap.SwapFieldsToTargetEndian( (BitmapFont_t*)pBuf ); swap.SwapFieldsToTargetEndian( (BitmapGlyph_t*)((char*)pBuf + sizeof( BitmapFont_t )), ((BitmapFont_t*)pBuf)->m_NumGlyphs ); } // create it m_bitmapFontHandle = g_BitmapFontTable.AddToTail(); pFontTable = &g_BitmapFontTable[m_bitmapFontHandle]; pFontTable->m_szName = fontName; pFontTable->m_pBitmapFont = new BitmapFont_t; memcpy( pFontTable->m_pBitmapFont, pBuf, sizeof( BitmapFont_t ) ); pFontTable->m_pBitmapGlyphs = new BitmapGlyph_t[pFontTable->m_pBitmapFont->m_NumGlyphs]; memcpy( pFontTable->m_pBitmapGlyphs, (unsigned char*)pBuf + sizeof(BitmapFont_t), pFontTable->m_pBitmapFont->m_NumGlyphs*sizeof(BitmapGlyph_t) ); FontManager().FileSystem()->FreeOptimalReadBuffer( pBuf ); // load the art resources char textureName[MAX_PATH]; Q_snprintf( textureName, MAX_PATH, "vgui/fonts/%s", fontName ); pFontTable->m_pTexture = FontManager().MaterialSystem()->FindTexture( textureName, TEXTURE_GROUP_VGUI ); #ifdef _DEBUG if ( pFontTable->m_pBitmapFont->m_PageWidth != pFontTable->m_pTexture->GetActualWidth() || pFontTable->m_pBitmapFont->m_PageHeight != pFontTable->m_pTexture->GetActualHeight() ) { // font is out of sync with its art Assert( 0 ); return false; } #endif // the font texture lives forever, ensure it doesn't get purged pFontTable->m_pTexture->IncrementReferenceCount(); } // setup font properties m_scalex = scalex; m_scaley = scaley; // flags are derived from the baked font m_iFlags = vgui::ISurface::FONTFLAG_BITMAP; int bitmapFlags = pFontTable->m_pBitmapFont->m_Flags; if ( bitmapFlags & BF_ANTIALIASED ) { m_iFlags |= vgui::ISurface::FONTFLAG_ANTIALIAS; } if ( bitmapFlags & BF_ITALIC ) { m_iFlags |= vgui::ISurface::FONTFLAG_ITALIC; } if ( bitmapFlags & BF_BLURRED ) { m_iFlags |= vgui::ISurface::FONTFLAG_GAUSSIANBLUR; m_iBlur = 1; } if ( bitmapFlags & BF_SCANLINES ) { m_iScanLines = 1; } if ( bitmapFlags & BF_OUTLINED ) { m_iFlags |= vgui::ISurface::FONTFLAG_OUTLINE; m_iOutlineSize = 1; } if ( bitmapFlags & BF_DROPSHADOW ) { m_iFlags |= vgui::ISurface::FONTFLAG_DROPSHADOW; m_iDropShadowOffset = 1; } if ( flags & vgui::ISurface::FONTFLAG_ADDITIVE ) { m_bAdditive = true; m_iFlags |= vgui::ISurface::FONTFLAG_ADDITIVE; } m_iMaxCharWidth = (float)pFontTable->m_pBitmapFont->m_MaxCharWidth * m_scalex; m_iHeight = (float)pFontTable->m_pBitmapFont->m_MaxCharHeight * m_scaley; m_iAscent = (float)pFontTable->m_pBitmapFont->m_Ascent * m_scaley; // mark as valid m_szName = symbol; return true; }
pei::FontAssetPtr CreateFontAsset( const char* name, size_t size, char *type /*= "ttf"*/ ) { return FontManager().CreateFontAsset( name, size, type ); }