void OpenGLUI::_putTexts(IGame const &game) { int const fontSize(_winSize.first / 19); double const padding(static_cast<double>(_winSize.first) / 19.); double const timeWidth(static_cast<double>(_winSize.first) / 19. * 8.); double const pausePadding( (static_cast<double>(_winSize.first) - static_cast<double>(_winSize.first) / 19. * 4.) / 2.); this->_font.FaceSize(fontSize); this->_font.Render( (std::string("Score: ") += std::to_string(game.getScore())).c_str(), -1, FTPoint(padding, padding)); this->_font.Render( (std::string("Played: ") += std::to_string(game.getPlayTime() / 60) += std::string(":") += std::string(game.getPlayTime() % 60 > 9 ? "" : "0") += std::to_string(game.getPlayTime() % 60)).c_str(), -1, FTPoint(static_cast<double>(_winSize.first) - timeWidth - padding, padding)); if (game.getSnake().isDie()) { this->_font.Render( std::string("Death!!").c_str(), -1, FTPoint(pausePadding, static_cast<double>(_winSize.second) / 2.)); } else if (game.isPaused()) { this->_font.Render( std::string("Paused").c_str(), -1, FTPoint(pausePadding, static_cast<double>(_winSize.second) / 2.)); } return ; }
void Font::print(float x, float y, float z, const String& text) { if (text.empty()) return; MutexLocker locker(pMutex); if (!font) return; glScalef(1.0f, -1.0f, 1.0f); for(int k = 0 ; k < (bBold ? 3 : 1) ; ++k) { #ifdef __FTGL__lower__ font->Render( text.c_str(), -1, FTPoint(x, -(y + 0.5f * (-font->Descender() + font->Ascender())), z), FTPoint(), FTGL::RENDER_ALL); #else glPushMatrix(); glTranslatef( x, -(y + 0.5f * (-font->Descender() + font->Ascender())), z ); # ifndef TA3D_PLATFORM_DARWIN WString wstr(text); font->Render(wstr.cw_str()); # else font->Render(text.c_str()); # endif glPopMatrix(); #endif } glScalef(1.0f, -1.0f, 1.0f); }
FTPoint FTFace::KernAdvance(unsigned int index1, unsigned int index2) { FTGL_DOUBLE x, y; if(!hasKerningTable || !index1 || !index2) { return FTPoint(0.0, 0.0); } if(kerningCache && index1 < FTFace::MAX_PRECOMPUTED && index2 < FTFace::MAX_PRECOMPUTED) { x = kerningCache[2 * (index2 * FTFace::MAX_PRECOMPUTED + index1)]; y = kerningCache[2 * (index2 * FTFace::MAX_PRECOMPUTED + index1) + 1]; return FTPoint(x, y); } FT_Vector kernAdvance; kernAdvance.x = kernAdvance.y = 0; err = FT_Get_Kerning(*ftFace, index1, index2, ft_kerning_unfitted, &kernAdvance); if(err) { return FTPoint(0.0f, 0.0f); } x = static_cast<float>(kernAdvance.x) / 64.0f; y = static_cast<float>(kernAdvance.y) / 64.0f; return FTPoint(x, y); }
// 描画 // text 表示文字列 // pos 表示位置 // color 表示色 void Font::draw(const std::string& text, const Vec2f& pos, const Color& color) { color.setToGl(); // OpenGLの行列スタックを利用 glPushMatrix(); font_->Render(text.c_str(), -1, FTPoint(pos.x(), pos.y()), FTPoint()); glPopMatrix(); }
FTGlyph::FTGlyph(FileStream & stream, char * data, int x_offset, int y_offset, int tex_width, int tex_height) : tex(0) { charcode = stream.read_uint32(); float x1, y1, x2, y2; x1 = stream.read_float(); y1 = stream.read_float(); x2 = stream.read_float(); y2 = stream.read_float(); bBox = FTBBox(x1, y1, x2, y2); float advance_x, advance_y; advance_x = stream.read_float(); advance_y = stream.read_float(); advance = FTPoint(advance_x, advance_y); float corner_x, corner_y; corner_x = stream.read_float(); corner_y = stream.read_float(); corner = FTPoint(corner_x, corner_y); width = stream.read_int32(); height = stream.read_int32(); char * glyph = new char[width*height]; stream.read(glyph, width * height); if (width && height) { if (y_offset + height > tex_height) { // copy subimage height = tex_height - y_offset; } if (height >= 0) { for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { char c = glyph[y * width + x]; data[(y + y_offset) * tex_width + x + x_offset] = c; } } } } #ifdef USE_OUTLINE uv[0].X(float(x_offset - 1) / float(tex_width)); uv[0].Y(float(y_offset - 1) / float(tex_height)); uv[1].X(float(x_offset + width + 1) / float(tex_width)); uv[1].Y(float(y_offset + height + 1) / float(tex_height)); #else uv[0].X(float(x_offset) / float(tex_width)); uv[0].Y(float(y_offset) / float(tex_height)); uv[1].X(float(x_offset + width) / float(tex_width)); uv[1].Y(float(y_offset + height) / float(tex_height)); #endif delete[] glyph; }
void FTExtrudeGlyphImpl::RenderSide() { int contourFlag = vectoriser->ContourFlag(); //LOG_INFO("RenderSide %d", contourFlag); GLfloat colors[4]; for(size_t c = 0; c < vectoriser->ContourCount(); ++c) { const FTContour* contour = vectoriser->Contour(c); size_t n = contour->PointCount(); if(n < 2) { continue; } glGetFloatv(GL_CURRENT_COLOR, colors); ftglBegin(GL_QUADS); ftglColor4f(colors[0]/2, colors[1]/2, colors[2]/2, colors[3]/2); for(size_t j = 0; j < n; j++ ) { size_t cur = j % n; size_t next = (j + 1) % n; FTPoint frontPt = contour->FrontPoint(cur); FTPoint frontPt1 = contour->FrontPoint(next); FTPoint backPt = contour->BackPoint(cur); FTPoint backPt1 = contour->BackPoint(next); FTPoint normal = FTPoint(0.f, 0.f, 1.f) ^ (frontPt - frontPt1); if(normal != FTPoint(0.0f, 0.0f, 0.0f)) { const FTGL_DOUBLE* pD = static_cast<const FTGL_DOUBLE*>(normal.Normalise()); glNormal3f( pD[0], pD[1], pD[2]); } ftglTexCoord2f(frontPt.Xf() / hscale, frontPt.Yf() / vscale); if(contourFlag & ft_outline_reverse_fill) { ftglVertex3f(backPt.Xf() / 64.0f, backPt.Yf() / 64.0f, 0.0f); ftglVertex3f(frontPt.Xf() / 64.0f, frontPt.Yf() / 64.0f, -depth); ftglVertex3f(frontPt1.Xf() / 64.0f, frontPt1.Yf() / 64.0f, -depth); ftglVertex3f(backPt1.Xf() / 64.0f, backPt1.Yf() / 64.0f, 0.0f); } else { ftglVertex3f(backPt.Xf() / 64.0f, backPt.Yf() / 64.0f, -depth); ftglVertex3f(frontPt.Xf() / 64.0f, frontPt.Yf() / 64.0f, 0.0f); ftglVertex3f(frontPt1.Xf() / 64.0f, frontPt1.Yf() / 64.0f, 0.f); ftglVertex3f(backPt1.Xf() / 64.0f, backPt1.Yf() / 64.0f, -depth); } } ftglEnd(); } }
void HudManager::renderPos(int X, int Y) { QString x,y; x.setNum(X); y.setNum(Y); FTGLPixmapFont textLife("/home/dragmaf/Sviluppo/build-GraficaProgetto-Desktop-Debug/data/font/SuperMario256.ttf"); textLife.FaceSize(30); textLife.Render("X",-1,FTPoint(70, height/2, 0)); textLife.Render(x.toStdString().c_str(),-1,FTPoint(120, height/2, 0)); textLife.Render("Y",-1,FTPoint(70, height/2-40, 0)); textLife.Render(y.toStdString().c_str(),-1,FTPoint(120, height/2-40, 0)); }
void HudManager::renderLose() { glEnable(GL_LIGHT1); FTGLPixmapFont lose("/home/dragmaf/Sviluppo/build-GraficaProgetto-Desktop-Debug/data/font/SuperMario256.ttf"); lose.FaceSize(72); lose.Render("HAI PERSO",-1,FTPoint(width/2-200, height-190, 0)); lose.FaceSize(30); lose.Render("Premi R per ricominciare a giocare.",-1,FTPoint(width/2-300, height/2-200, 0)); lose.Render("Premi ESC per chiudere.",-1,FTPoint(width/2-300, height/2-250, 0)); drawImage(textureLose,width/2-300,height/2-150,600,300); glDisable(GL_LIGHT1); }
void testGetPoint() { FTTesselation tesselation(1); CPPUNIT_ASSERT(tesselation.PointCount() == 0); tesselation.AddPoint(10, 3, 0.7); tesselation.AddPoint(-53, 2000, 23); tesselation.AddPoint(77, -2.4, 765); tesselation.AddPoint(117.5, 0.02, -99); CPPUNIT_ASSERT(tesselation.PointCount() == 4); CPPUNIT_ASSERT(tesselation.Point(2) == FTPoint(77, -2.4, 765)); CPPUNIT_ASSERT(tesselation.Point(20) != FTPoint(77, -2.4, 765)); }
void Font::renderText(const wchar_t* wText, float x, float y, float width, float height) throw(invalid_argument, runtime_error) { ASSERT( (wText != 0), invalid_argument("wText") ); std::lock_guard<std::mutex> guard(synchroMutex_); if(font_ == 0) { return; } size_t textLen = wcslen(wText); if(width >= 0.0f) { Font::FONT_RECT rect = measureText(wText); if(rect.width > width) { float pixPerChar = rect.width / textLen; float excess = rect.width - width; size_t charsForErase = static_cast<size_t>(lround(excess / pixPerChar)); textLen -= charsForErase; } } glPushMatrix(); glPushAttrib(GL_COLOR_BUFFER_BIT); glColor3fv(color_.c_array()); font_->Render(wText, textLen, FTPoint(static_cast<FTGL_FLOAT>(x), static_cast<FTGL_FLOAT>(y)), FTPoint(), FTGL::RENDER_ALL); glPopAttrib(); glPopMatrix(); }
void GUI::RenderPolyCount(){ //TODO: clean this up stringstream ss1; ss1 << "Quads: " << "10"; m_text->Render(ss1.str().c_str(), -1, FTPoint(m_width-200, m_height-115, 0)); stringstream ss2; ss2 << "Tri: " << "20"; m_text->Render(ss2.str().c_str(), -1, FTPoint(m_width-200, m_height-130, 0)); stringstream ss3; ss3 << "Vertices: " << "10"; m_text->Render(ss3.str().c_str(), -1, FTPoint(m_width-200, m_height-145, 0)); }
FTBBox FTSimpleLayout::BBox(const wchar_t *string, const int len) { FTBBox tmp; int lines; WrapTextI(string, len, FTPoint(), &tmp, lines); return tmp; }
ofRectangle ofxFTGLFont::getStringBoundingBox(const wstring& s, float x, float y){ if(loaded){ FTBBox bbox = font->BBox((wchar_t*)s.c_str(), -1, FTPoint(), trackingPoint); return ofRectangle(x + bbox.Lower().Xf(), y + bbox.Lower().Yf(), bbox.Upper().Xf(), bbox.Upper().Yf()); } return ofRectangle(); }
void Font::render(const vec3& pos, const std::string& text) const { if (simpleLayout_) { float delta = 0; std::string line; std::stringstream ss(text); std::getline(ss, line); FTPoint point(static_cast<double>(pos.x), static_cast<double>(pos.y), static_cast<double>(pos.z)); FTBBox box = font_->BBox(line.c_str(), -1, point); delta -= box.Upper().Yf() - box.Lower().Yf(); // height of first line Bounds bounds = getBounds(pos, text); float height = bounds.getURB().y - bounds.getLLF().y; switch(vAlign_) { case Font::Top: delta += height; break; case Font::Middle: delta += height * 0.5f; break; case Font::Bottom: break; } vec3 dpos = vec3(pos.x, pos.y + delta, pos.z); glPushMatrix(); glRasterPos3f(dpos.x, dpos.y, dpos.z); glTranslatef(dpos.x, dpos.y, dpos.z); simpleLayout_->Render(text.c_str(), -1, FTPoint(dpos.x, dpos.y, dpos.z)); glPopMatrix(); } }
void FTFont::BBox( const wchar_t* string, float& llx, float& lly, float& llz, float& urx, float& ury, float& urz) { FTBBox totalBBox; if((NULL != string) && ('\0' != *string)) { const wchar_t* c = string; float advance = 0; if(CheckGlyph( *c)) { totalBBox = glyphList->BBox( *c); advance = glyphList->Advance( *c, *(c + 1)); } while( *++c) { if(CheckGlyph( *c)) { FTBBox tempBBox = glyphList->BBox( *c); tempBBox.Move( FTPoint( advance, 0.0f, 0.0f)); totalBBox += tempBBox; advance += glyphList->Advance( *c, *(c + 1)); } } } llx = totalBBox.lowerX; lly = totalBBox.lowerY; llz = totalBBox.lowerZ; urx = totalBBox.upperX; ury = totalBBox.upperY; urz = totalBBox.upperZ; }
void FTFont::BBox( const char* string, float& llx, float& lly, float& llz, float& urx, float& ury, float& urz) { FTBBox totalBBox; if((NULL != string) && ('\0' != *string)) { const unsigned char* c = (unsigned char*)string; CheckGlyph( *c); totalBBox = glyphList->BBox( *c); float advance = glyphList->Advance( *c, *(c + 1)); ++c; while( *c) { CheckGlyph( *c); FTBBox tempBBox = glyphList->BBox( *c); tempBBox.Move( FTPoint( advance, 0.0f, 0.0f)); totalBBox += tempBBox; advance += glyphList->Advance( *c, *(c + 1)); ++c; } } llx = totalBBox.lowerX; lly = totalBBox.lowerY; llz = totalBBox.lowerZ; urx = totalBBox.upperX; ury = totalBBox.upperY; urz = totalBBox.upperZ; }
void CRenderingContext::RenderText(const tstring& sText, unsigned iLength, FTFont* pFont) { TAssert(m_pShader); if (!m_pShader) return; CRenderContext& oContext = GetContext(); if (iLength == -1) iLength = sText.length(); TAssert(m_pShader->m_iPositionAttribute >= 0); TAssert(m_pShader->m_aiTexCoordAttributes[0] >= 0); if (!oContext.m_bProjectionUpdated) SetUniform("mProjection", oContext.m_mProjection); if (!oContext.m_bViewUpdated) SetUniform("mView", oContext.m_mView); // Take the position out and let FTGL do it. It looks sharper that way. Matrix4x4 mTransformations = oContext.m_mTransformations; Vector vecPosition = mTransformations.GetTranslation(); mTransformations.SetTranslation(Vector()); SetUniform("mGlobal", mTransformations); oContext.m_bProjectionUpdated = oContext.m_bViewUpdated = oContext.m_bTransformUpdated = true; ftglSetAttributeLocations(m_pShader->m_iPositionAttribute, m_pShader->m_aiTexCoordAttributes[0]); pFont->Render(sText.c_str(), iLength, FTPoint(vecPosition.x, vecPosition.y, vecPosition.z)); }
ofRectangle ofxFTGLFont::getStringBoundingBox(wstring s, float x, float y){ if(loaded){ FTBBox bbox = font->BBox((wchar_t*)s.c_str(), -1, FTPoint(), trackingPoint); return ofRectangle(x, y-getAscender(), abs(bbox.Lower().Xf()-bbox.Upper().Xf()), abs(bbox.Upper().Yf()-bbox.Lower().Yf())); } return ofRectangle(); }
FTGlyph::FTGlyph (FT_GlyphSlot glyph) : err(0) { if (glyph) { bBox = FTBBox (glyph); advance = FTPoint (glyph->advance.x / 64.0f, glyph->advance.y / 64.0f, 0.0f); } }
int DKFont::GetWidth(DKString text) { if(texture_font != NULL){ return (int)texture_font->Advance(text.c_str(),-1,FTPoint()); } return 0; }
void testPlusEquals() { setUpFreetype(); FTBBox boundingBox1; FTBBox boundingBox2( face->glyph); boundingBox1 += boundingBox2; CPPUNIT_ASSERT_DOUBLES_EQUAL( 2, boundingBox2.lowerX, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, boundingBox2.lowerY, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox2.lowerZ, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 35, boundingBox2.upperX, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 38, boundingBox2.upperY, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox2.upperZ, 0.01); float advance = 40; boundingBox2.Move( FTPoint( advance, 0, 0)); boundingBox1 += boundingBox2; CPPUNIT_ASSERT_DOUBLES_EQUAL( 42, boundingBox2.lowerX, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, boundingBox2.lowerY, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox2.lowerZ, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 75, boundingBox2.upperX, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 38, boundingBox2.upperY, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, boundingBox2.upperZ, 0.01); tearDownFreetype(); }
FTBuffer::FTBuffer() : width(0), height(0), pixels(0), pos(FTPoint()) { }
void ofxFTGLFont::drawString(wstring s, float x, float y){ glPushMatrix(); glTranslatef(x, y, 0); glScalef(1,-1,1); font->Render((wchar_t*)s.c_str(), -1, FTPoint(), trackingPoint); glPopMatrix(); }
void HudManager::renderLife() { QString life; life.setNum(player->getNumberLife()); FTGLPixmapFont textLife("/home/dragmaf/Sviluppo/build-GraficaProgetto-Desktop-Debug/data/font/SuperMario256.ttf"); textLife.FaceSize(30); orthoMode(true); glPushMatrix(); textLife.Render("x",-1,FTPoint(100, height-55, 0)); textLife.FaceSize(40); textLife.Render(life.toStdString().c_str(),-1,FTPoint(125, height-55, 0)); glPopMatrix(); orthoMode(false); drawImage(textureLife,20,height-87,80,80); }
const FTPoint& Render(const FTPoint& pen, int renderMode) { FTGL_DOUBLE advancex, advancey; renderCallback(baseGlyph, data, pen.X(), pen.Y(), renderMode, &advancex, &advancey); advance = FTPoint(advancex, advancey); return advance; }
void FTExtrudeGlyphImpl::RenderSide() { int contourFlag = vectoriser->ContourFlag(); for(size_t c = 0; c < vectoriser->ContourCount(); ++c) { const FTContour* contour = vectoriser->Contour(c); size_t n = contour->PointCount(); if(n < 2) { continue; } glBegin(GL_QUAD_STRIP); for(size_t j = 0; j <= n; ++j) { size_t cur = (j == n) ? 0 : j; size_t next = (cur == n - 1) ? 0 : cur + 1; const FTPoint& frontPt = contour->FrontPoint(cur); const FTPoint& nextPt = contour->FrontPoint(next); const FTPoint& backPt = contour->BackPoint(cur); FTPoint normal = FTPoint(0.f, 0.f, 1.f) ^ (frontPt - nextPt); if(normal != FTPoint(0.0f, 0.0f, 0.0f)) { glNormal3dv(static_cast<const FTGL_DOUBLE*>(normal.Normalise())); } glTexCoord2f(frontPt.Xf() / hscale, frontPt.Yf() / vscale); if(contourFlag & ft_outline_reverse_fill) { glVertex3f(backPt.Xf() / 64.0f, backPt.Yf() / 64.0f, 0.0f); glVertex3f(frontPt.Xf() / 64.0f, frontPt.Yf() / 64.0f, -depth); } else { glVertex3f(backPt.Xf() / 64.0f, backPt.Yf() / 64.0f, -depth); glVertex3f(frontPt.Xf() / 64.0f, frontPt.Yf() / 64.0f, 0.0f); } } glEnd(); } }
void HudManager::renderVictory() { glEnable(GL_LIGHT1); drawImage(textureBackground,0,0,width,height); drawImage(marioHappy,100,100,300,600); drawImage(luigiHappy,width-350,100,300,600); drawImage(toadHappy,width/2-75,200,150,300); FTGLPixmapFont win("/home/dragmaf/Sviluppo/build-GraficaProgetto-Desktop-Debug/data/font/SuperMario256.ttf"); win.FaceSize(72); win.Render("HAI VINTO",-1,FTPoint(width/2-200, height-190, 0)); win.FaceSize(30); win.Render("Premi R per ricominciare a giocare.",-1,FTPoint(width/2-300, height/2-200, 0)); win.Render("Premi ESC per chiudere.",-1,FTPoint(width/2-300, height/2-250, 0)); glDisable(GL_LIGHT1); }
inline void FTSimpleLayoutImpl::RenderSpaceI(const T *string, const int len, FTPoint position, int renderMode, const float extraSpace) { float space = 0.0; // If there is space to distribute, count the number of spaces if(extraSpace > 0.0) { int numSpaces = 0; // Count the number of space blocks in the input FTUnicodeStringItr<T> prevItr(string), itr(string); for(int i = 0; ((len < 0) && *itr) || ((len >= 0) && (i <= len)); ++i, prevItr = itr++) { // If this is the end of a space block, increment the counter if((i > 0) && !iswspace(*itr) && iswspace(*prevItr)) { numSpaces++; } } space = extraSpace/numSpaces; } // Output all characters of the string FTUnicodeStringItr<T> prevItr(string), itr(string); for(int i = 0; ((len < 0) && *itr) || ((len >= 0) && (i <= len)); ++i, prevItr = itr++) { // If this is the end of a space block, distribute the extra space // inside it if((i > 0) && !iswspace(*itr) && iswspace(*prevItr)) { pen += FTPoint(space, 0); } /** * We want to minimise repeated calls to this function -- is it possible to * set up a cache using Advance? */ pen = currentFont->Render(itr.getBufferFromHere(), 1, pen, FTPoint(), renderMode); } }
FTGlyphImpl::FTGlyphImpl(FT_GlyphSlot glyph, bool /*useList*/) : err(0) { if(glyph) { bBox = FTBBox(glyph); advance = FTPoint(glyph->advance.x / 64.0f, glyph->advance.y / 64.0f); } }
void ofxFTGLFont::drawString(const wstring& s, float x, float y){ if(loaded){ ofPushMatrix(); ofTranslate(x, y, 0); ofScale(1, -1, 1); font->Render((wchar_t*)s.c_str(), -1, FTPoint(), trackingPoint); ofPopMatrix(); } }