00001 //////////////////////////////////////////////////////////////////////////////// 00002 // Scorched3D (c) 2000-2009 00003 // 00004 // This file is part of Scorched3D. 00005 // 00006 // Scorched3D is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // Scorched3D is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with Scorched3D; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 //////////////////////////////////////////////////////////////////////////////// 00020 00021 #include <GLEXT/GLFont2dStorage.h> 00022 #include <common/DefinesAssert.h> 00023 #include <stdio.h> 00024 #include <stdlib.h> 00025 00026 unsigned int GLFont2dStorage::totalCharacterBlocks_(0); 00027 00028 GLFont2dStorage::CharEntry::CharEntry() : 00029 texture(0), displaylist(0) 00030 { 00031 00032 } 00033 00034 GLFont2dStorage::CharEntry::~CharEntry() 00035 { 00036 if (displaylist != 0) glDeleteLists(displaylist, 1); 00037 if (texture != 0) glDeleteTextures(1, &texture); 00038 } 00039 00040 GLFont2dStorage::StorageBlock::StorageBlock() 00041 { 00042 entries = new CharEntry[256]; 00043 } 00044 00045 GLFont2dStorage::StorageBlock::~StorageBlock() 00046 { 00047 delete [] entries; 00048 } 00049 00050 GLFont2dStorage::GLFont2dStorage() 00051 { 00052 blocks_ = new StorageBlock*[40]; 00053 for (int i=0; i<40; i++) blocks_[i] = 0; 00054 } 00055 00056 GLFont2dStorage::~GLFont2dStorage() 00057 { 00058 for (int i=0; i<40; i++) delete blocks_[i]; 00059 delete [] blocks_; 00060 } 00061 00062 GLFont2dStorage::CharEntry *GLFont2dStorage::getEntry(unsigned int character) 00063 { 00064 unsigned int blockCount = character >> 8; 00065 unsigned int remainderCount = character & 0xFF; 00066 00067 if (blockCount >= 40) return getEntry('?'); 00068 00069 // Get storage block 00070 StorageBlock *block = blocks_[blockCount]; 00071 if (!block) 00072 { 00073 block = new StorageBlock(); 00074 blocks_[blockCount] = block; 00075 totalCharacterBlocks_++; 00076 } 00077 00078 // Get character 00079 CharEntry *entry = &block->entries[remainderCount]; 00080 return entry; 00081 }
1.5.3