void ewol::compositing::Text::drawMT(const mat4& _transformationMatrix, bool _enableDepthTest) { // draw BG in any case: m_vectorialDraw.draw(); if (m_coord.size() <= 0 || m_font == nullptr) { // TODO : a remÃtre ... //EWOL_WARNING("Nothink to draw..."); return; } if (m_font == nullptr) { EWOL_WARNING("no font..."); return; } if (m_GLprogram == nullptr) { EWOL_ERROR("No shader ..."); return; } if (_enableDepthTest == true) { gale::openGL::enable(gale::openGL::flag_depthTest); } // set Matrix : translation/positionMatrix mat4 projMatrix = gale::openGL::getMatrix(); mat4 camMatrix = gale::openGL::getCameraMatrix(); mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix; m_GLprogram->use(); m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // Texture : m_GLprogram->setTexture0(m_GLtexID, m_font->getRendererId()); m_GLprogram->uniform1i(m_GLtextWidth, m_font->getOpenGlSize().x()); m_GLprogram->uniform1i(m_GLtextHeight, m_font->getOpenGlSize().x()); // position : m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z*/, &m_coord[0]); // Texture : m_GLprogram->sendAttribute(m_GLtexture, 2/*u,v*/, &m_coordTex[0]); // color : m_GLprogram->sendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]); // Request the draw od the elements : gale::openGL::drawArrays(gale::openGL::renderMode::triangle, 0, m_coord.size()); m_GLprogram->unUse(); if (_enableDepthTest == true) { gale::openGL::disable(gale::openGL::flag_depthTest); } }
bool ewol::resource::TexturedFont::addGlyph(const char32_t& _val) { std::unique_lock<std::recursive_mutex> lock(m_mutex); bool hasChange = false; // for each font : for (int32_t iii=0; iii<4 ; iii++) { if (m_font[iii] == nullptr) { continue; } // add the curent "char" GlyphProperty tmpchar; tmpchar.m_UVal = _val; if (true == m_font[iii]->getGlyphProperty(m_size, tmpchar)) { //EWOL_DEBUG("load char : '" << _val << "'=" << _val.get()); hasChange = true; // change line if needed ... if (m_lastGlyphPos[iii].x()+tmpchar.m_sizeTexture.x()+3 > m_data.getSize().x()) { m_lastGlyphPos[iii].setX(1); m_lastGlyphPos[iii] += ivec2(0, m_lastRawHeigh[iii]); m_lastRawHeigh[iii] = 0; } while(m_lastGlyphPos[iii].y()+tmpchar.m_sizeTexture.y()+3 > m_data.getSize().y()) { ivec2 size = m_data.getSize(); size.setY(size.y()*2); m_data.resize(size, etk::Color<>(0)); // note : need to rework all the lyer due to the fact that the texture is used by the faur type... for (size_t kkk=0; kkk<4 ; kkk++) { // change the coordonate on the element in the texture for (size_t jjj=0 ; jjj<m_listElement[kkk].size() ; ++jjj) { m_listElement[kkk][jjj].m_texturePosStart *= vec2(1.0f, 0.5f); m_listElement[kkk][jjj].m_texturePosSize *= vec2(1.0f, 0.5f); } } } // draw the glyph m_font[iii]->drawGlyph(m_data, m_size, m_lastGlyphPos[iii], tmpchar, iii); // set video position tmpchar.m_texturePosStart.setValue( (float)m_lastGlyphPos[iii].x() / (float)m_data.getSize().x(), (float)m_lastGlyphPos[iii].y() / (float)m_data.getSize().y() ); tmpchar.m_texturePosSize.setValue( (float)tmpchar.m_sizeTexture.x() / (float)m_data.getSize().x(), (float)tmpchar.m_sizeTexture.y() / (float)m_data.getSize().y() ); // update the maximum of the line hight : if (m_lastRawHeigh[iii]<tmpchar.m_sizeTexture.y()) { // note : +1 is for the overlapping of the glyph (Part 2) m_lastRawHeigh[iii] = tmpchar.m_sizeTexture.y()+1; } // note : +1 is for the overlapping of the glyph (Part 3) // update the Bitmap position drawing : m_lastGlyphPos[iii] += ivec2(tmpchar.m_sizeTexture.x()+1, 0); } else { EWOL_WARNING("Did not find char : '" << _val << "'=" << _val); tmpchar.setNotExist(); } m_listElement[iii].push_back(tmpchar); //m_font[iii]->display(); // generate the kerning for all the characters : if (tmpchar.exist() == true) { // TODO : set the kerning back ... //m_font[iii]->generateKerning(m_size, m_listElement[iii]); } } if (hasChange == true) { flush(); //egami::store(m_data, "fileFont.bmp"); // ==> for debug test only ... } return hasChange; }
bool ewol::resource::DistanceFieldFont::addGlyph(const char32_t& _val) { std11::unique_lock<std11::recursive_mutex> lock(m_mutex); bool hasChange = false; if (m_font == nullptr) { return false; } // add the curent "char" GlyphProperty tmpchar; tmpchar.m_UVal = _val; egami::ImageMono imageGlyphRaw; egami::Image imageGlyphDistanceField; EWOL_DEBUG("Generate Glyph : " << _val); if (m_font->getGlyphProperty(SIZE_GENERATION, tmpchar) == true) { //EWOL_DEBUG("load char : '" << _val << "'=" << _val.get()); hasChange = true; // change line if needed ... if (m_lastGlyphPos.x() + tmpchar.m_sizeTexture.x()+m_borderSize*2.0 > m_data.getSize().x()) { m_lastGlyphPos.setX(1); m_lastGlyphPos += ivec2(0, m_lastRawHeigh); m_lastRawHeigh = 0; } while(m_lastGlyphPos.y()+tmpchar.m_sizeTexture.y()+m_borderSize*2.0 > m_data.getSize().y()) { ivec2 size = m_data.getSize(); size.setY(size.y()*2); m_data.resize(size, etk::Color<>(0)); // change the coordonate on the element in the texture for (size_t jjj = 0; jjj < m_listElement.size(); ++jjj) { m_listElement[jjj].m_texturePosStart *= vec2(1.0f, 0.5f); m_listElement[jjj].m_texturePosSize *= vec2(1.0f, 0.5f); } } m_textureBorderSize = vec2(m_borderSize/(float)m_data.getSize().x(), m_borderSize/(float)m_data.getSize().y() ); // draw the glyph m_font->drawGlyph(imageGlyphRaw, SIZE_GENERATION, tmpchar, m_borderSize); generateDistanceField(imageGlyphRaw, imageGlyphDistanceField); /* if (_val == 'Z') { for (int32_t yyy = 0; yyy < imageGlyphDistanceField.getSize().y(); ++yyy) { for (int32_t xxx = 0; xxx < imageGlyphDistanceField.getSize().x(); ++xxx) { std::cout << (int)(imageGlyphDistanceField.get(ivec2(xxx, yyy)).r()) << " "; } //std::cout << std::endl; } } */ m_data.insert(m_lastGlyphPos, imageGlyphDistanceField); // set image position tmpchar.m_texturePosStart.setValue( ((float)m_lastGlyphPos.x()+(m_borderSize*0.5f)) / (float)m_data.getSize().x(), ((float)m_lastGlyphPos.y()+(m_borderSize*0.5f)) / (float)m_data.getSize().y() ); tmpchar.m_texturePosSize.setValue( ((float)imageGlyphRaw.getSize().x()-m_borderSize) / (float)m_data.getSize().x(), ((float)imageGlyphRaw.getSize().y()-m_borderSize) / (float)m_data.getSize().y() ); // update the maximum of the line hight : if (m_lastRawHeigh < imageGlyphRaw.getSize().y()) { // note : +1 is for the overlapping of the glyph (Part 2) m_lastRawHeigh = imageGlyphRaw.getSize().y()+1; } // note : +1 is for the overlapping of the glyph (Part 3) // update the Bitmap position drawing : m_lastGlyphPos += ivec2(imageGlyphRaw.getSize().x()+1, 0); } else { EWOL_WARNING("Did not find char : '" << _val << "'=" << _val); tmpchar.setNotExist(); } m_listElement.push_back(tmpchar); //m_font[iii]->display(); // generate the kerning for all the characters : if (tmpchar.exist() == true) { // TODO : set the kerning back ... //m_font[iii]->generateKerning(m_size, m_listElement[iii]); } if (hasChange == true) { flush(); //egami::store(m_data, "fileFont.bmp"); // ==> for debug test only ... } return hasChange; }