// Load FtglOutlineFont void FtglOutlineFont::loadFont() { if (isLoaded()) return; // Check for required parameters if( filename() == nullptr ) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "No ttf file" << std::endl; } return; } // Generate filename const size_t FONTPATHNAME_LENGTH = 256; char fontPathname[FONTPATHNAME_LENGTH]; if (fontDirectory() != nullptr) lcStrcpy(fontPathname, FONTPATHNAME_LENGTH, fontDirectory()); else lcStrcpy(fontPathname, FONTPATHNAME_LENGTH, "./"); lcStrcat(fontPathname, FONTPATHNAME_LENGTH, filename()); FTGLOutlineFont* ftglFont = new FTGLOutlineFont(fontPathname); if (ftglFont != nullptr && !ftglFont->Error()) { // set the face size and return the pointer, then tell our base class that we have a loaded font ftglFont->FaceSize(getFaceSize()); ftgl(ftglFont); setFontLoaded(); } else { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "FtglOutlineFont::loadFont() - font did not load correctly: file: \""; std::cerr << fontPathname << "\""; std::cerr << std::endl; } std::exit(1); } }
void BepdfApplication::Initialize() { if (!mInitialized) { mInitialized = true; // built in fonts BPath fontDirectory(mAppPath); fontDirectory.Append("fonts"); // built in encodings BPath encodingDirectory(mAppPath); encodingDirectory.Append("encodings"); InitXpdf(NULL, fontDirectory.Path(), encodingDirectory.Path()); // system fonts BPath systemFontsPath; if (find_directory(B_BEOS_FONTS_DIRECTORY, &systemFontsPath) == B_OK) { BDirectory directory(systemFontsPath.Path()); BEntry entry; while (directory.GetNextEntry(&entry) == B_OK) { if (!entry.IsDirectory()) continue; BPath fontDirectory; if (entry.GetPath(&fontDirectory) != B_OK) continue; setGlobalParameter("fontDir", fontDirectory.Path()); } } // CID fonts BMessage msg; mSettings->GetDisplayCIDFonts(msg); DisplayCIDFonts displayNames(msg); // record new names bool foundNewName = false; GList* list = getCIDToUnicodeNames(globalParams); for (int i = 0; i < list->getLength(); i ++) { GString* name = (GString*)list->get(i); if (displayNames.Contains(name->getCString())) { continue; } // record name displayNames.Set(name->getCString()); foundNewName = true; } // store in settings if (foundNewName) { msg.MakeEmpty(); displayNames.Archive(msg); mSettings->SetDisplayCIDFonts(msg); } // set CID fonts for (int i = 0; i < list->getLength(); i ++) { GString* name = (GString*)list->get(i); BString file; DisplayCIDFonts::Type type; displayNames.Get(name->getCString(), file, type); if (type == DisplayCIDFonts::kUnknownType || file.Length() == 0) { continue; } if (type == DisplayCIDFonts::kTrueType) { setGlobalParameter("displayCIDFontTT", name->getCString(), file.String()); } else { setGlobalParameter("displayCIDFontT1", name->getCString(), file.String()); } } deleteGList(list, GString); } }
void MySample::Create() { CPUTAssetLibrary *pAssetLibrary = CPUTAssetLibrary::GetAssetLibrary(); cString ExecutableDirectory; CPUTFileSystem::GetExecutableDirectory(&ExecutableDirectory); ExecutableDirectory.append(_L(ASSET_LOCATION)); pAssetLibrary->SetMediaDirectoryName(ExecutableDirectory); #ifdef ENABLE_GUI CPUTGuiControllerOGL *pGUI = (CPUTGuiControllerOGL*)CPUTGetGuiController(); std::string mediaDirectory = ws2s(pAssetLibrary->GetMediaDirectoryName()); std::string fontDirectory("Font/"); CPUTFont *pFont = CPUTFont::CreateFont(SYSTEM_LOCATION + fontDirectory, "arial_64.fnt"); pGUI->SetFont(pFont); // // Create some controls // CPUTDropdown *pDropdownMethod; pGUI->CreateText(_L("Test Font"), ID_IGNORE_CONTROL_ID, ID_MAIN_PANEL, &pTextMethod); pTextMethod->SetColor(1.0f, 1.0f, 1.0f, 1.0f); CreateInstancingControlButtons(); #endif CPUTFileSystem::GetExecutableDirectory(&ExecutableDirectory); ExecutableDirectory.append(_L(ASSET_LOCATION)); pAssetLibrary->SetMediaDirectoryName(ExecutableDirectory); int width, height; mpWindow->GetClientDimensions(&width, &height); DEBUG_PRINT(_L("Resize Window")); ResizeWindow(width, height); mpScene = new CPUTScene(); DEBUG_PRINT(_L("Load Scene")); // Load the scene if (CPUTFAILED(mpScene->LoadScene(SCENE_FILE))) { LOGI("Failed to Load Scene, try loading asset set individually"); CPUTAssetSet *pAssetSet = NULL; pAssetSet = pAssetLibrary->GetAssetSet( ASSET_SET_FILE ); mpScene->AddAssetSet(pAssetSet); pAssetSet->Release(); } LOGI("Loaded the scene"); // Get the camera. Get the first camera encountered in the scene or // if there are none, create a new one. unsigned int numAssets = mpScene->GetNumAssetSets(); for (unsigned int i = 0; i < numAssets; ++i) { CPUTAssetSet *pAssetSet = mpScene->GetAssetSet(i); if (pAssetSet->GetCameraCount() > 0) { mpCamera = pAssetSet->GetFirstCamera(); break; } } // Create the camera if (mpCamera == NULL) { mpCamera = new CPUTCamera(); pAssetLibrary->AddCamera( _L(""), _L("SampleStart Camera"), _L(""), mpCamera ); mpCamera->SetPosition( 0.0f, cameraY, 100.0f ); // Set the projection matrix for all of the cameras to match our window. // TODO: this should really be a viewport matrix. Otherwise, all cameras will have the same FOV and aspect ratio, etc instead of just viewport dimensions. mpCamera->SetAspectRatio(((float)width)/((float)height)); } mpCamera->SetFov(DegToRad(90.0)); // TODO: Fix converter's FOV bug (Maya generates cameras for which fbx reports garbage for fov) mpCamera->SetFarPlaneDistance(100000.0f); mpCamera->Update(); mpCameraController = new CPUTCameraControllerFPS(); mpCameraController->SetCamera(mpCamera); mpCameraController->SetLookSpeed(0.004f); mpCameraController->SetMoveSpeed(150.0f); // retrieve function pointer glDrawElementsInstancedEXT = (PFNGLDRAWELEMENTSINSTANCEDEXTPROC) ( eglGetProcAddress( "glDrawElementsInstanced" ) ); if( glDrawElementsInstancedEXT == NULL ) { LOGE( "Failed to load extension pointer" ); } currentRowCount = NUM_ROWS / 1.5; currentColCount = NUM_COLUMNS; LOGI("Getting handles for materials"); // get handles to switch instancing / non instancing pAssetLibrary->PrintAssetLibrary(); supportMaterial = pAssetLibrary->GetMaterialByName("instanceV2/Material/concreteMultiMaterial.mtl"); techMaterial = pAssetLibrary->GetMaterialByName("instanceV2/Material/techALowMultiMataterial.mtl"); isInstanced = true; CPUTModel *pModel = pAssetLibrary->GetModelByName( _L( ".instangeGrptechALow" ) ); pModel->SetDrawModelCallBack((DrawModelCallBackFunc)drawCallback); pModel = pAssetLibrary->GetModelByName( _L( ".instangeGrpconcrete" ) ); pModel->SetDrawModelCallBack((DrawModelCallBackFunc)drawCallback); UINT supportCount = supportMaterial->GetMaterialEffectCount(); UINT techCount = techMaterial->GetMaterialEffectCount(); glFrontFace(GL_CW); UpdateMatrixBuffers(); }
// Load the font for one character GLubyte* BitmapFont::loadTypeFace(const GLint index, const GLenum reverse) { // If no font to load, return if (fontMap[index] == 0) return 0; // Create the font file name const size_t FONTPATHNAME_LENGTH = 256; char fontPathname[FONTPATHNAME_LENGTH]; if (fontDirectory() != 0) lcStrcpy(fontPathname, FONTPATHNAME_LENGTH, fontDirectory()); else lcStrcpy(fontPathname, FONTPATHNAME_LENGTH, "./"); lcStrcat(fontPathname, FONTPATHNAME_LENGTH, fontMap[index]); // Open the font file FILE* fp = 0; if( (fp = fopen(fontPathname, "r")) ==0 ) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "BitmapFont::loadTypeFace: unable to open font file: " << fontPathname << std::endl; } return 0; } // used to store the num of input items successfully matched and assigned // by fscanf function int nItemsMatched; // Calculate the size of the font unsigned int width1; nItemsMatched = fscanf(fp, "%u\n", &width1); unsigned int height1; nItemsMatched = fscanf(fp, "%u\n", &height1); unsigned int numBytesWide = int(ceil(double(width1) / 8.0)); unsigned int numFileBytes = numBytesWide * height1; unsigned int numFontBytes = numBytesWide * getBitmapHeight(); GLubyte* bitmap = new GLubyte[numFontBytes]; unsigned int i; // index // Pad rest of the height unsigned int diff = numFontBytes - numFileBytes; for (i = 0; i < diff; i++) { bitmap[i] = reverse ? 255 : 0; } // Read in the bitmap bytes for (; i < numFontBytes; i++) { int value; nItemsMatched = fscanf(fp, "0x%x\n", &value); bitmap[i] = reverse ? GLubyte(~value) : GLubyte(value); } fclose(fp); // Reverse the bitmap reverseBitmapOrder(bitmap, numFontBytes, numBytesWide); return bitmap; }