void HighScoreList::AddHighScore( HighScore hs, int &iIndexOut, bool bIsMachine ) { int i; for( i=0; i<(int)vHighScores.size(); i++ ) { if( hs >= vHighScores[i] ) break; } const int iMaxScores = bIsMachine ? PREFSMAN->m_iMaxHighScoresPerListForMachine : PREFSMAN->m_iMaxHighScoresPerListForPlayer; if( i < iMaxScores ) { vHighScores.insert( vHighScores.begin()+i, hs ); iIndexOut = i; // Delete extra machine high scores in RemoveAllButOneOfEachNameAndClampSize // and not here so that we don't end up with less than iMaxScores after // removing HighScores with duplicate names. // if( !bIsMachine ) ClampSize( bIsMachine ); } HighGrade = min( hs.GetGrade(), HighGrade ); }
void FTTextureFontImpl::CalculateTextureSize() { if(!maximumGLTextureSize) { maximumGLTextureSize = 1024; glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&maximumGLTextureSize); assert(maximumGLTextureSize); // Indicates an invalid OpenGL context } // Texture width required for numGlyphs glyphs. Will probably not be // large enough, but we try to fit as many glyphs in one line as possible textureWidth = ClampSize(glyphWidth * numGlyphs + padding * 2, maximumGLTextureSize); // Number of lines required for that many glyphs in a line int tmp = (textureWidth - (padding * 2)) / glyphWidth; tmp = tmp > 0 ? tmp : 1; tmp = (numGlyphs + (tmp - 1)) / tmp; // round division up // Texture height required for tmp lines of glyphs textureHeight = ClampSize(glyphHeight * tmp + padding * 2, maximumGLTextureSize); }
FTTextureFont::FTTextureFont(FileStream & stream) : textureWidth(0), textureHeight(0), xOffset(0), yOffset(0), padding(3) { glyphList = new FTGlyphContainer(this); size = stream.read_uint16(); flags = stream.read_uint16(); width = stream.read_float(); height = stream.read_float(); ascender = stream.read_float(); descender = stream.read_float(); numGlyphs = stream.read_int32(); glyphHeight = std::max(1, int(height + 0.5f)); glyphWidth = std::max(1, int(width + 0.5f)); int tex_size = 1024; // Texture width required for numGlyphs glyphs. Will probably not be // large enough, but we try to fit as many glyphs in one line as possible textureWidth = ClampSize(glyphWidth * numGlyphs + padding * 2, tex_size); // Number of lines required for that many glyphs in a line int tmp = (textureWidth - (padding * 2)) / glyphWidth; tmp = tmp > 0 ? tmp : 1; tmp = (numGlyphs + (tmp - 1)) / tmp; // round division up // Texture height required for tmp lines of glyphs textureHeight = ClampSize(glyphHeight * tmp + padding * 2, tex_size); char * data = new char[textureWidth*textureHeight](); xOffset = yOffset = padding; for (int i = 0; i < numGlyphs; i++) { FTGlyph * glyph = new FTGlyph(stream, data, xOffset, yOffset, textureWidth, textureHeight); glyphList->Add(glyph, glyph->charcode); if (xOffset > (textureWidth - glyphWidth)) { xOffset = padding; yOffset += glyphHeight; if (yOffset > (textureHeight - glyphHeight)) { std::cout << "Cannot fit glyphs in texture!" << std::endl; break; } } xOffset += int(glyph->BBox().Upper().X() - glyph->BBox().Lower().X() + padding + 0.5); } tex = Render::create_tex(data, Render::L, textureWidth, textureHeight); Render::set_filter(tex, true); GlyphVector::iterator it; for (it = glyphList->glyphs.begin(); it != glyphList->glyphs.end(); ++it) { FTGlyph * glyph = *it; if (glyph == NULL) continue; glyph->tex = tex; } delete[] data; }