📄 basefontrendering.cpp
字号:
// ___ ___ ___ ___ ___ // /\__\ ___ /\__\ /\ \ /\__\ /\ \. // /::| | /\ \ /::| | /::\ \ /:/ / /::\ \. // /:|:| | \:\ \ /:|:| | /:/\:\ \ /:/ / /:/\:\ \. // /:/|:|__|__ /::\__\ /:/|:| |__ /:/ \:\ \ /:/ / /::\~\:\ \. // /:/ |::::\__\ __/:/\/__/ /:/ |:| /\__\ /:/__/_\:\__\ /:/__/ /:/\:\ \:\__\.// \/__/~~/:/ / /\/:/ / \/__|:|/:/ / \:\ /\ \/__/ \:\ \ \:\~\:\ \/__/// /:/ / \::/__/ |:/:/ / \:\ \:\__\ \:\ \ \:\ \:\__\. // /:/ / \:\__\ |::/ / \:\/:/ / \:\ \ \:\ \/__/ // /:/ / \/__/ /:/ / \::/ / \:\__\ \:\__\. // \/__/ \/__/ \/__/ \/__/ \/__/ // // =============================================================================// Minimalist OpenGL Environment// =============================================================================//// This file is part of Minimalist OpenGL Environment (MinGLE)//// Version: 0.2.0// Author: Balazs Domonkos// Filename: src/fontrendering/include/BaseFontRendering.cpp// Creation Date: January 25th 2008// Revision Date: January 25th 2008////// The Minimalist OpenGL Environment is free software: you can// redistribute it and/or modify it under the terms of the GNU// General Public License as published by the Free Software// Foundation, either version 3 of the License, or (at your// option) any later version.//// The Minimalist OpenGL Environment is distributed in the hope// that it will be useful, but WITHOUT ANY WARRANTY; without// even the implied warranty of MERCHANTABILITY or FITNESS FOR// A PARTICULAR PURPOSE. See the GNU General Public License// for more details.//// You should have received a copy of the GNU General Public License// along with Minimalist OpenGL Environment. If not, see // <http://www.gnu.org/licenses/>. See the COPYING file included // with this distribution file for license details.///// @file BaseFontRendering.cpp/// Basic, image atlas based font rendering implementation// Header that contains the declaration#include <BaseFontRendering.h>// MinGLE headers#include <Exception.h>#include <System.h>#include <MathUtils.h>#include <Atlas.h>// System headers#include <math.h>namespace MinGLE {// Dynamic library loader functionextern "C"void loadDynLib(void) { // Create and register FreeType2 font rendering implementation FontRendering::registerImplementation(BaseFontRendering::IMPLEMENTATION_NAME, new BaseFontRendering()); FontRendering::registerFunctionality(FileFormatFunctionality("xml", FileFormatFunctionality::READ_WRITE), BaseFontRendering::IMPLEMENTATION_NAME);}// Dynamic library unloader functionextern "C" void unloadDynLib(void) { // Nothing to do}// =============================================================================BaseFont::BaseFont(const std::string& filename, VirtualFileSystem *vfs, GLenum format, GLenum type) :RasterFont(DEFAULT_FONT_HEIGHT, DEFAULT_FONT_WIDTH, 0, DEFAULT_FIRST_CHARACTER, DEFAULT_LAST_CHARACTER, format, type, DEFAULT_IMAGE_SCALE_MODE){ // Load image atlas mImageAtlas = new ImageAtlas<int>(filename, vfs); // TODO find out mFirstCharacter and mLastCharacter // Retrieve glyph sizes ImageAtlas<int>::CoordSet2D *coordSet = mImageAtlas->getCoordSet(mFirstCharacter); mWidth = coordSet->u2 - coordSet->u1; mHeight = coordSet->v2 - coordSet->v1; // TODO convert image to format, type}// =============================================================================const std::string BaseFontRendering::IMPLEMENTATION_NAME = "base";BaseFontRendering::BaseFontRendering() { // Nothing to do}BaseFontRendering::~BaseFontRendering() { // Nothing to do}Font *BaseFontRendering::_createFont(const std::string& filename, VirtualFileSystem *vfs, size_t height, size_t width, long faceIndex, size_t firstCharacter, size_t lastCharacter, GLenum format, GLenum type, RasterFont::ImageScaleMode imageScaleMode) { return new BaseFont(filename, vfs, format, type);}void BaseFontRendering::_saveFont(Font *font, const std::string& filename, VirtualFileSystem *vfs) { RasterFont *rasterFont = dynamic_cast<RasterFont *>(font); Assert(rasterFont, "BaseFontRendering::_saveFont"); std::string extension = VirtualFileSystem::getExtension(filename); if(extension == "xml") rasterFont->getImageAtlas()->saveToFile(filename, vfs); else Except("BaseFontRendering::_saveFont", "Extension " + extension + " is not supported.");}} // namespace MinGLE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -