glText icon indicating copy to clipboard operation
glText copied to clipboard

Black background

Open ramboza opened this issue 6 years ago • 5 comments

Hello MrVallentin,

Nice and useful library! Just one quick question: how to set transparent background for text instead of black ?

Thanks, Jev.

ramboza avatar Sep 06 '18 11:09 ramboza

Currently you can change the text color with gltColor. If you change the color, then it is only applied to the fill of the text, however changing the transparency would also affect the outline. Since the color is only multiplied with the font texels in the shader.

https://github.com/MrVallentin/glText/blob/2a2802ad161d30356413fbeb0e591e27ff7a565a/gltext.h#L523-L527

What is the exact use case? Do you simply want to be be able to apply different fill and outline colors? I'll at least look into that in the near future, have a few other ideas I want to implement as well.

Sorry it took a month to respond, didn't realize my mail filtering meant I wouldn't get notifications.

vallentin avatar Oct 10 '18 12:10 vallentin

Nice lib, and easy to use. Thanks. But same here, just want the text background can set to transparent.

trlsmax avatar Oct 20 '18 04:10 trlsmax

just figure it out

#define _gltDrawText() \
	glUseProgram(_gltText2DShader); \
	\
	glActiveTexture(GL_TEXTURE0); \
	glBindTexture(GL_TEXTURE_2D, _gltText2DFontTexture); \
	\
	glUniformMatrix4fv(_gltText2DShaderMVPUniformLocation, 1, GL_FALSE, mvp); \
	\
    GLboolean last_enable_blend = glIsEnabled(GL_BLEND);\
    glEnable(GL_BLEND);\
    glBlendEquation(GL_FUNC_ADD);\
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\
    \
	glBindVertexArray(text->_vao); \
	glDrawArrays(GL_TRIANGLES, 0, text->vertexCount); \
	glBindVertexArray(0); \
    \
    if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);

trlsmax avatar Oct 20 '18 08:10 trlsmax

Thank you, trlsmax, nice method

loveq007 avatar Jun 27 '19 09:06 loveq007

@vallentin Any news on this?

orbea avatar Sep 14 '22 02:09 orbea