From 0a8b88798459af7c9e769a5602932fc59acd7b78 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 6 Sep 2012 18:42:06 +0200 Subject: [PATCH] Distance field display work corectly (generation is slow but it work) --- Sources/libagg | 2 +- .../libewol/ewol/font/DistantFieldFont.cpp | 39 +++++++++++++------ Sources/libewol/ewol/openGL/Shader.cpp | 12 ------ Sources/libewol/ewol/widget/Widget.cpp | 3 +- share/fontDistanceField/font1.frag | 6 +++ 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Sources/libagg b/Sources/libagg index bfba3999..b3f1a97a 160000 --- a/Sources/libagg +++ b/Sources/libagg @@ -1 +1 @@ -Subproject commit bfba3999b5cee49bd9a556f51170193849228a46 +Subproject commit b3f1a97a28cce551e8685216a68e77a68904dde5 diff --git a/Sources/libewol/ewol/font/DistantFieldFont.cpp b/Sources/libewol/ewol/font/DistantFieldFont.cpp index 40dd071d..5efeecb6 100644 --- a/Sources/libewol/ewol/font/DistantFieldFont.cpp +++ b/Sources/libewol/ewol/font/DistantFieldFont.cpp @@ -55,6 +55,7 @@ static int32_t simpleSQRT(int32_t value) return val; } +#define SPECIAL_BORDER (5) ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) : ewol::Texture(fontName), @@ -92,7 +93,7 @@ ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) : freeTypeFontElement_ts tmpchar1; tmpchar1.property.m_UVal = 0; m_listElement.PushBack(tmpchar1); - for (int32_t iii=0x20; iii<0xFF; iii++) { + for (int32_t iii=0x20/*'A'*/; iiiGetHeight(m_size); + draw::Image tmpUpScaledImage(Vector2D(1024,1024)); + int32_t CurrentLineHigh = 0; Vector2D glyphPosition(1,1); for (int32_t iii=0; iiiGetGlyphProperty(m_size, m_listElement[iii].property)) { + EWOL_DEBUG("Generate Font Element : '" << m_listElement[iii].property.m_UVal << "'= '" << (char)m_listElement[iii].property.m_UVal << "'"); + // clean the temporary image : + tmpUpScaledImage.SetFillColor(draw::Color(0xFFFFFF00)); + tmpUpScaledImage.Clear(); /* // check internal property: // enought in the texture : @@ -157,12 +164,12 @@ ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) : CurrentLineHigh = 0; } // draw the glyph - m_font->DrawGlyph(m_data, m_size, glyphPosition, m_listElement[iii].property); + m_font->DrawGlyph(tmpUpScaledImage, m_size*8, Vector2D(SPECIAL_BORDER*8,SPECIAL_BORDER*8), m_listElement[iii].property); // set video position m_listElement[iii].posStart.u = (float)(glyphPosition.x) / (float)textureWidth; m_listElement[iii].posStart.v = (float)(glyphPosition.y) / (float)textureHeight; - m_listElement[iii].posStop.u = (float)(glyphPosition.x + m_listElement[iii].property.m_sizeTexture.x) / (float)textureWidth; - m_listElement[iii].posStop.v = (float)(glyphPosition.y + m_listElement[iii].property.m_sizeTexture.y) / (float)textureHeight; + m_listElement[iii].posStop.u = (float)(glyphPosition.x + m_listElement[iii].property.m_sizeTexture.x+2*SPECIAL_BORDER) / (float)textureWidth; + m_listElement[iii].posStop.v = (float)(glyphPosition.y + m_listElement[iii].property.m_sizeTexture.y+2*SPECIAL_BORDER) / (float)textureHeight; /* EWOL_DEBUG("generate '" << (char)m_listElement[iii].property.m_UVal << "'"); EWOL_DEBUG(" in tex : " << glyphPosition << " ==> " << m_listElement[iii].posStart.u<< "," << m_listElement[iii].posStart.v ); @@ -170,15 +177,24 @@ ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) : EWOL_DEBUG(" m_bearing =" << m_listElement[iii].property.m_bearing ); EWOL_DEBUG(" m_advance =" << m_listElement[iii].property.m_advance ); */ + // generate the distance field from this element ... + tmpUpScaledImage.DistanceField(Vector2D(0,0), m_listElement[iii].property.m_sizeTexture*Vector2D(8,8)+Vector2D(2*SPECIAL_BORDER*8,2*SPECIAL_BORDER*8)); + // copy data with downscaling : (subSampling) + Vector2D tmpPos(0,0); + for (tmpPos.y = 0; tmpPos.y(8,8) + Vector2D(4,4)) ); + } + } // update the maximum of the line hight : - if (CurrentLineHigh textPos, totalSize += ret; } - #if 0 + #if 1 // To display the texture ... { /* Bitmap position diff --git a/Sources/libewol/ewol/openGL/Shader.cpp b/Sources/libewol/ewol/openGL/Shader.cpp index 441f1156..22e692a6 100644 --- a/Sources/libewol/ewol/openGL/Shader.cpp +++ b/Sources/libewol/ewol/openGL/Shader.cpp @@ -110,32 +110,20 @@ bool ewol::Shader::CompileAndSendShader(void) m_shader = 0; return false; } - EWOL_DEBUG(" --> Create"); m_shader = glCreateShader(m_type); - EWOL_DEBUG(" <-- Create"); if (!m_shader) { EWOL_ERROR("glCreateShader return error ..."); - EWOL_DEBUG(" --> checkGlError"); checkGlError("glCreateShader"); - EWOL_DEBUG(" <-- checkGlError"); return false; } else { - EWOL_DEBUG(" --> glShaderSource"); glShaderSource(m_shader, 1, (const char**)&m_fileData, NULL); - EWOL_DEBUG(" <-- glShaderSource"); - EWOL_DEBUG(" --> glCompileShader"); glCompileShader(m_shader); - EWOL_DEBUG(" <-- glCompileShader"); GLint compiled = 0; - EWOL_DEBUG(" --> glGetShaderiv"); glGetShaderiv(m_shader, GL_COMPILE_STATUS, &compiled); - EWOL_DEBUG(" <-- glGetShaderiv"); if (!compiled) { GLint infoLen = 0; l_bufferDisplayError[0] = '\0'; - EWOL_DEBUG(" --> glGetShaderInfoLog"); glGetShaderInfoLog(m_shader, LOG_OGL_INTERNAL_BUFFER_LEN, &infoLen, l_bufferDisplayError); - EWOL_DEBUG(" <-- glGetShaderInfoLog"); const char * tmpShaderType = "GL_FRAGMENT_SHADER"; if (m_type == GL_VERTEX_SHADER){ tmpShaderType = "GL_VERTEX_SHADER"; diff --git a/Sources/libewol/ewol/widget/Widget.cpp b/Sources/libewol/ewol/widget/Widget.cpp index fe71758f..eadc98e0 100644 --- a/Sources/libewol/ewol/widget/Widget.cpp +++ b/Sources/libewol/ewol/widget/Widget.cpp @@ -277,8 +277,9 @@ void ewol::Widget::GenDraw(DrawProperty displayProp) #ifdef __VIDEO__OPENGL_ES_2 #if 1 etk::Matrix tmpTranslate = etk::matrix::Translate(-m_size.x/2, -m_size.y/2, -1.0); + /*etk::Matrix tmpScale = etk::matrix::Scale(5, 5, 1.0);*/ etk::Matrix tmpProjection = etk::matrix::Perspective(-m_size.x/2, m_size.x/2, -m_size.y/2, m_size.y/2, -1, 1); - etk::Matrix tmpMat = tmpProjection * tmpTranslate; + etk::Matrix tmpMat = tmpProjection * /*tmpScale * */ tmpTranslate; #else etk::Matrix tmpMat = etk::matrix::Perspective(0, m_size.x, 0, m_size.y, -1, 1); #endif diff --git a/share/fontDistanceField/font1.frag b/share/fontDistanceField/font1.frag index d6b403dd..d4bbe9cd 100644 --- a/share/fontDistanceField/font1.frag +++ b/share/fontDistanceField/font1.frag @@ -12,6 +12,7 @@ varying vec4 f_color; void main(void) { vec4 tmpcolor = texture2D(EW_texID, f_texcoord); vec4 outColor = vec4(0,0,0,0); + /* // compare distance with 0.5 that represent the middle ... if (tmpcolor[3]>0.5) { outColor = f_color; @@ -21,6 +22,11 @@ void main(void) { outColor = f_color; outColor[3] = (tmpcolor[3]-0.49)*1.0/0.02; } + */ + outColor = f_color;// * tmpcolor[3]; + outColor[3] = smoothstep(0.45, 0.55, tmpcolor[3]); + //outColor = vec4(0,0,0,0); + //outColor[3] = tmpcolor[3]; gl_FragColor = outColor; }