Distance field display work corectly (generation is slow but it work)
This commit is contained in:
parent
022055b86e
commit
0a8b887984
@ -1 +1 @@
|
|||||||
Subproject commit bfba3999b5cee49bd9a556f51170193849228a46
|
Subproject commit b3f1a97a28cce551e8685216a68e77a68904dde5
|
@ -55,6 +55,7 @@ static int32_t simpleSQRT(int32_t value)
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SPECIAL_BORDER (5)
|
||||||
|
|
||||||
ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) :
|
ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) :
|
||||||
ewol::Texture(fontName),
|
ewol::Texture(fontName),
|
||||||
@ -92,7 +93,7 @@ ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) :
|
|||||||
freeTypeFontElement_ts tmpchar1;
|
freeTypeFontElement_ts tmpchar1;
|
||||||
tmpchar1.property.m_UVal = 0;
|
tmpchar1.property.m_UVal = 0;
|
||||||
m_listElement.PushBack(tmpchar1);
|
m_listElement.PushBack(tmpchar1);
|
||||||
for (int32_t iii=0x20; iii<0xFF; iii++) {
|
for (int32_t iii=0x20/*'A'*/; iii</*'Z'*/0xFF; iii++) {
|
||||||
freeTypeFontElement_ts tmpchar;
|
freeTypeFontElement_ts tmpchar;
|
||||||
tmpchar.property.m_UVal = iii;
|
tmpchar.property.m_UVal = iii;
|
||||||
m_listElement.PushBack(tmpchar);
|
m_listElement.PushBack(tmpchar);
|
||||||
@ -110,8 +111,8 @@ ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) :
|
|||||||
int32_t nbElement = 0xFF - 0x20 + 1;
|
int32_t nbElement = 0xFF - 0x20 + 1;
|
||||||
int32_t coter = simpleSQRT(nbElement);
|
int32_t coter = simpleSQRT(nbElement);
|
||||||
// note : +1 is for the overlapping of the glyph (Part 1)
|
// note : +1 is for the overlapping of the glyph (Part 1)
|
||||||
int32_t glyphMaxWidth = tmpproperty.m_advance.x +1;
|
int32_t glyphMaxWidth = tmpproperty.m_advance.x +1 + SPECIAL_BORDER*2;
|
||||||
int32_t glyphMaxHeight = tmpproperty.m_advance.y +1;
|
int32_t glyphMaxHeight = tmpproperty.m_advance.y +1 + SPECIAL_BORDER*2;
|
||||||
int32_t textureWidth = nextP2(coter*glyphMaxWidth);
|
int32_t textureWidth = nextP2(coter*glyphMaxWidth);
|
||||||
int32_t nbRaws = textureWidth / glyphMaxWidth;
|
int32_t nbRaws = textureWidth / glyphMaxWidth;
|
||||||
if (nbRaws <= 0) {
|
if (nbRaws <= 0) {
|
||||||
@ -134,10 +135,16 @@ ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) :
|
|||||||
|
|
||||||
m_height = m_font->GetHeight(m_size);
|
m_height = m_font->GetHeight(m_size);
|
||||||
|
|
||||||
|
draw::Image tmpUpScaledImage(Vector2D<int32_t>(1024,1024));
|
||||||
|
|
||||||
int32_t CurrentLineHigh = 0;
|
int32_t CurrentLineHigh = 0;
|
||||||
Vector2D<int32_t> glyphPosition(1,1);
|
Vector2D<int32_t> glyphPosition(1,1);
|
||||||
for (int32_t iii=0; iii<m_listElement.Size(); iii++) {
|
for (int32_t iii=0; iii<m_listElement.Size(); iii++) {
|
||||||
if (true == m_font->GetGlyphProperty(m_size, m_listElement[iii].property)) {
|
if (true == m_font->GetGlyphProperty(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:
|
// check internal property:
|
||||||
// enought in the texture :
|
// enought in the texture :
|
||||||
@ -157,12 +164,12 @@ ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) :
|
|||||||
CurrentLineHigh = 0;
|
CurrentLineHigh = 0;
|
||||||
}
|
}
|
||||||
// draw the glyph
|
// draw the glyph
|
||||||
m_font->DrawGlyph(m_data, m_size, glyphPosition, m_listElement[iii].property);
|
m_font->DrawGlyph(tmpUpScaledImage, m_size*8, Vector2D<int32_t>(SPECIAL_BORDER*8,SPECIAL_BORDER*8), m_listElement[iii].property);
|
||||||
// set video position
|
// set video position
|
||||||
m_listElement[iii].posStart.u = (float)(glyphPosition.x) / (float)textureWidth;
|
m_listElement[iii].posStart.u = (float)(glyphPosition.x) / (float)textureWidth;
|
||||||
m_listElement[iii].posStart.v = (float)(glyphPosition.y) / (float)textureHeight;
|
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.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) / (float)textureHeight;
|
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("generate '" << (char)m_listElement[iii].property.m_UVal << "'");
|
||||||
EWOL_DEBUG(" in tex : " << glyphPosition << " ==> " << m_listElement[iii].posStart.u<< "," << m_listElement[iii].posStart.v );
|
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_bearing =" << m_listElement[iii].property.m_bearing );
|
||||||
EWOL_DEBUG(" m_advance =" << m_listElement[iii].property.m_advance );
|
EWOL_DEBUG(" m_advance =" << m_listElement[iii].property.m_advance );
|
||||||
*/
|
*/
|
||||||
|
// generate the distance field from this element ...
|
||||||
|
tmpUpScaledImage.DistanceField(Vector2D<int32_t>(0,0), m_listElement[iii].property.m_sizeTexture*Vector2D<int32_t>(8,8)+Vector2D<int32_t>(2*SPECIAL_BORDER*8,2*SPECIAL_BORDER*8));
|
||||||
|
// copy data with downscaling : (subSampling)
|
||||||
|
Vector2D<int32_t> tmpPos(0,0);
|
||||||
|
for (tmpPos.y = 0; tmpPos.y<m_listElement[iii].property.m_sizeTexture.y+2*SPECIAL_BORDER; tmpPos.y++) {
|
||||||
|
for (tmpPos.x = 0; tmpPos.x<m_listElement[iii].property.m_sizeTexture.x+2*SPECIAL_BORDER; tmpPos.x++) {
|
||||||
|
m_data.Set(glyphPosition + tmpPos, tmpUpScaledImage.Get(tmpPos*Vector2D<int32_t>(8,8) + Vector2D<int32_t>(4,4)) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// update the maximum of the line hight :
|
// update the maximum of the line hight :
|
||||||
if (CurrentLineHigh<m_listElement[iii].property.m_sizeTexture.y) {
|
if (CurrentLineHigh<m_listElement[iii].property.m_sizeTexture.y+1+2*SPECIAL_BORDER) {
|
||||||
// note : +1 is for the overlapping of the glyph (Part 2)
|
// note : +1 is for the overlapping of the glyph (Part 2)
|
||||||
CurrentLineHigh = m_listElement[iii].property.m_sizeTexture.y+1;
|
CurrentLineHigh = m_listElement[iii].property.m_sizeTexture.y+1 + 2*SPECIAL_BORDER;
|
||||||
}
|
}
|
||||||
// note : +1 is for the overlapping of the glyph (Part 3)
|
// note : +1 is for the overlapping of the glyph (Part 3)
|
||||||
// update the Bitmap position drawing :
|
// update the Bitmap position drawing :
|
||||||
glyphPosition.x += m_listElement[iii].property.m_sizeTexture.x+1;
|
glyphPosition.x += m_listElement[iii].property.m_sizeTexture.x+1 + 2*SPECIAL_BORDER;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -196,8 +212,7 @@ ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) :
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
EWOL_DEBUG("End generation of the Fond bitmap, start adding texture");
|
EWOL_DEBUG("End generation of the Fond bitmap, start adding texture");
|
||||||
// generate the distance field from this element ...
|
//m_data.DistanceField();
|
||||||
m_data.DistanceField();
|
|
||||||
Flush();
|
Flush();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -234,7 +249,7 @@ int32_t ewol::DistantFieldFont::Draw(Vector2D<float> textPos,
|
|||||||
totalSize += ret;
|
totalSize += ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
// To display the texture ...
|
// To display the texture ...
|
||||||
{
|
{
|
||||||
/* Bitmap position
|
/* Bitmap position
|
||||||
|
@ -110,32 +110,20 @@ bool ewol::Shader::CompileAndSendShader(void)
|
|||||||
m_shader = 0;
|
m_shader = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EWOL_DEBUG(" --> Create");
|
|
||||||
m_shader = glCreateShader(m_type);
|
m_shader = glCreateShader(m_type);
|
||||||
EWOL_DEBUG(" <-- Create");
|
|
||||||
if (!m_shader) {
|
if (!m_shader) {
|
||||||
EWOL_ERROR("glCreateShader return error ...");
|
EWOL_ERROR("glCreateShader return error ...");
|
||||||
EWOL_DEBUG(" --> checkGlError");
|
|
||||||
checkGlError("glCreateShader");
|
checkGlError("glCreateShader");
|
||||||
EWOL_DEBUG(" <-- checkGlError");
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
EWOL_DEBUG(" --> glShaderSource");
|
|
||||||
glShaderSource(m_shader, 1, (const char**)&m_fileData, NULL);
|
glShaderSource(m_shader, 1, (const char**)&m_fileData, NULL);
|
||||||
EWOL_DEBUG(" <-- glShaderSource");
|
|
||||||
EWOL_DEBUG(" --> glCompileShader");
|
|
||||||
glCompileShader(m_shader);
|
glCompileShader(m_shader);
|
||||||
EWOL_DEBUG(" <-- glCompileShader");
|
|
||||||
GLint compiled = 0;
|
GLint compiled = 0;
|
||||||
EWOL_DEBUG(" --> glGetShaderiv");
|
|
||||||
glGetShaderiv(m_shader, GL_COMPILE_STATUS, &compiled);
|
glGetShaderiv(m_shader, GL_COMPILE_STATUS, &compiled);
|
||||||
EWOL_DEBUG(" <-- glGetShaderiv");
|
|
||||||
if (!compiled) {
|
if (!compiled) {
|
||||||
GLint infoLen = 0;
|
GLint infoLen = 0;
|
||||||
l_bufferDisplayError[0] = '\0';
|
l_bufferDisplayError[0] = '\0';
|
||||||
EWOL_DEBUG(" --> glGetShaderInfoLog");
|
|
||||||
glGetShaderInfoLog(m_shader, LOG_OGL_INTERNAL_BUFFER_LEN, &infoLen, l_bufferDisplayError);
|
glGetShaderInfoLog(m_shader, LOG_OGL_INTERNAL_BUFFER_LEN, &infoLen, l_bufferDisplayError);
|
||||||
EWOL_DEBUG(" <-- glGetShaderInfoLog");
|
|
||||||
const char * tmpShaderType = "GL_FRAGMENT_SHADER";
|
const char * tmpShaderType = "GL_FRAGMENT_SHADER";
|
||||||
if (m_type == GL_VERTEX_SHADER){
|
if (m_type == GL_VERTEX_SHADER){
|
||||||
tmpShaderType = "GL_VERTEX_SHADER";
|
tmpShaderType = "GL_VERTEX_SHADER";
|
||||||
|
@ -277,8 +277,9 @@ void ewol::Widget::GenDraw(DrawProperty displayProp)
|
|||||||
#ifdef __VIDEO__OPENGL_ES_2
|
#ifdef __VIDEO__OPENGL_ES_2
|
||||||
#if 1
|
#if 1
|
||||||
etk::Matrix tmpTranslate = etk::matrix::Translate(-m_size.x/2, -m_size.y/2, -1.0);
|
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 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
|
#else
|
||||||
etk::Matrix tmpMat = etk::matrix::Perspective(0, m_size.x, 0, m_size.y, -1, 1);
|
etk::Matrix tmpMat = etk::matrix::Perspective(0, m_size.x, 0, m_size.y, -1, 1);
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,6 +12,7 @@ varying vec4 f_color;
|
|||||||
void main(void) {
|
void main(void) {
|
||||||
vec4 tmpcolor = texture2D(EW_texID, f_texcoord);
|
vec4 tmpcolor = texture2D(EW_texID, f_texcoord);
|
||||||
vec4 outColor = vec4(0,0,0,0);
|
vec4 outColor = vec4(0,0,0,0);
|
||||||
|
/*
|
||||||
// compare distance with 0.5 that represent the middle ...
|
// compare distance with 0.5 that represent the middle ...
|
||||||
if (tmpcolor[3]>0.5) {
|
if (tmpcolor[3]>0.5) {
|
||||||
outColor = f_color;
|
outColor = f_color;
|
||||||
@ -21,6 +22,11 @@ void main(void) {
|
|||||||
outColor = f_color;
|
outColor = f_color;
|
||||||
outColor[3] = (tmpcolor[3]-0.49)*1.0/0.02;
|
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;
|
gl_FragColor = outColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user