Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions Sofa/GL/src/sofa/gl/glText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void GlText::initTexture()
}
if (s_asciiTexture == nullptr && s_asciiImage != nullptr)
{
s_asciiTexture = new sofa::gl::Texture(s_asciiImage, false, true, false );
s_asciiTexture = new sofa::gl::Texture(s_asciiImage, false, true, true );
}
}

Expand Down Expand Up @@ -170,7 +170,7 @@ void GlText::textureDraw_Overlay(const char* text, const double scale)

}

void GlText::textureDraw_Indices(const type::vector<type::Vec3>& positions, const float& scale)
void GlText::textureDraw_Indices(const type::vector<type::Vec3>& positions, const float& scale, bool enableDepthTest)
{
if (!s_asciiTexture)
{
Expand Down Expand Up @@ -211,8 +211,17 @@ void GlText::textureDraw_Indices(const type::vector<type::Vec3>& positions, cons
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

if(!enableDepthTest)
glDisable(GL_DEPTH_TEST);

glDisable(GL_LIGHTING);

s_asciiTexture->bind();

// Save the caller-set color for the main text pass
GLfloat textColor[4];
glGetFloatv(GL_CURRENT_COLOR, textColor);

for (std::size_t i = 0; i < positions.size(); i++)
{
std::ostringstream oss;
Expand All @@ -223,8 +232,6 @@ void GlText::textureDraw_Indices(const type::vector<type::Vec3>& positions, cons
std::vector<Vec3f> vertices;
std::vector<Vec2f> UVs;

glDisable(GL_LIGHTING);

glPushMatrix();

// Makes text always face the viewer by removing the scene rotation
Expand All @@ -248,11 +255,7 @@ void GlText::textureDraw_Indices(const type::vector<type::Vec3>& positions, cons
autoScale = baseFontPixelHeight * scale * 2.0f / (p11 * viewportHeight);
}

glLoadIdentity();
//translate a little bit to center the text on the position (instead of starting from a top-left position)
glTranslatef(temp[0] - (worldWidth*length*autoScale)*0.5f, temp[1] + worldHeight*autoScale*0.5f, temp[2]);
glScalef(autoScale, autoScale, autoScale);
glRotatef(180.0, 1, 0, 0);
// Build quads for this label
for (std::size_t j = 0; j < length; j++)
{
Vec3f vertex_up_left = Vec3f(j*worldWidth, worldHeight, 0.0f);
Expand Down Expand Up @@ -281,6 +284,31 @@ void GlText::textureDraw_Indices(const type::vector<type::Vec3>& positions, cons
UVs.push_back(uv_up_right);
}

// Shadow offset: 1.5 pixels in view space
const float shadowOffset = 1.5f * autoScale / baseFontPixelHeight;

// Drop shadow pass (dark, offset down-right)
glColor4f(0.0f, 0.0f, 0.0f, textColor[3] * 0.7f);
glLoadIdentity();
glTranslatef(temp[0] - (worldWidth*length*autoScale)*0.5f + shadowOffset,
temp[1] + worldHeight*autoScale*0.5f - shadowOffset,
temp[2]);
glScalef(autoScale, autoScale, autoScale);
glRotatef(180.0, 1, 0, 0);
glBegin(GL_QUADS);
for (std::size_t j = 0; j < vertices.size(); j++)
{
glTexCoord2fv(UVs[j].data());
glVertex3fv(vertices[j].data());
}
glEnd();

// Main text pass
glColor4fv(textColor);
glLoadIdentity();
glTranslatef(temp[0] - (worldWidth*length*autoScale)*0.5f, temp[1] + worldHeight*autoScale*0.5f, temp[2]);
glScalef(autoScale, autoScale, autoScale);
glRotatef(180.0, 1, 0, 0);
glBegin(GL_QUADS);
for (std::size_t j = 0; j < vertices.size(); j++)
{
Expand All @@ -295,9 +323,9 @@ void GlText::textureDraw_Indices(const type::vector<type::Vec3>& positions, cons
s_asciiTexture->unbind();
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glPopAttrib();


glEnable(GL_LIGHTING);
}

Expand Down
2 changes: 1 addition & 1 deletion Sofa/GL/src/sofa/gl/glText.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SOFA_GL_API GlText
static void draw ( const T& text, const type::Vec3& position = type::Vec3(0.0,0.0,0.0), const double& scale = 1.0);

static void textureDraw_Overlay(const char* text, const double scale = 1.0);
static void textureDraw_Indices(const type::vector<type::Vec3>& positions, const float& scale);
static void textureDraw_Indices(const type::vector<type::Vec3>& positions, const float& scale, bool enableDepthTest = true);

private:
static void initTexture();
Expand Down
Loading