Commit 89cdae80 authored by Sylvain Thery's avatar Sylvain Thery

enhancement of text rendering (updating & change color)

parent 2433e28a
......@@ -134,6 +134,12 @@ public:
*/
void predraw(const Geom::Vec3f& color);
/**
* call just before a draw
* @param color the color of text
*/
void changeColor(const Geom::Vec3f& color);
/**
* call once after several draw(id,pos)
*/
......@@ -150,6 +156,14 @@ public:
*/
void setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& oy);
/**
* Update string content
* @warning size can not be changed
* @param idSt string id
* @param str new string content
*/
void updateString(unsigned int idSt, const std::string& str);
void toSVG(Utils::SVG::SVGOut& svg);
};
......
......@@ -236,6 +236,12 @@ void Strings3D::predraw(const Geom::Vec3f& color)
enableVertexAttribs();
}
void Strings3D::changeColor(const Geom::Vec3f& color)
{
bind();
glUniform3fv(*m_uniform_color, 1, color.data());
}
void Strings3D::postdraw()
{
disableVertexAttribs();
......@@ -266,6 +272,56 @@ void Strings3D::drawAll(const Geom::Vec3f& color)
postdraw();
}
void Strings3D::updateString(unsigned int idSt, const std::string& str)
{
unsigned int firstIndex = m_strpos[idSt].first;
unsigned int nbIndices = m_strpos[idSt].second;
unsigned int nbc = std::min((unsigned int)(str.length()), nbIndices/4);
m_vbo1->bind();
float* buffer = reinterpret_cast<float*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
buffer += firstIndex*4;
float x = 0.0f;
for(unsigned int j = 0; j < nbc; ++j)
{
unsigned int ci = str[j]-32;
float u = float(ci % CHARSPERLINE) / float(CHARSPERLINE);
float v = float(ci / CHARSPERLINE) / float(CHARSPERCOL) + 1.0f / HEIGHTTEXTURE;
float u2 = u + float(REALWIDTHFONT) / float(WIDTHTEXTURE);
float v2 = v + float(WIDTHFONT - 1) / float(HEIGHTTEXTURE);
*buffer++ = x;
*buffer++ = 0;
*buffer++ = u;
*buffer++ = v2;
float xf = x + float(REALWIDTHFONT) / 25.f;
*buffer++ = xf;
*buffer++ = 0;
*buffer++ = u2;
*buffer++ = v2;
*buffer++ = xf;
*buffer++ = float(WIDTHFONT) / 25.f;
*buffer++ = u2;
*buffer++ = v;
*buffer++ = x;
*buffer++ = float(WIDTHFONT) / 25.f;
*buffer++ = u;
*buffer++ = v;
x = xf; // + space ?
}
glUnmapBuffer(GL_ARRAY_BUFFER);
}
void Strings3D::toSVG(Utils::SVG::SVGOut& svg)
{
svg.beginStrings(m_scale);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment