Fix text drawing with core profile
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 18 Apr 2017 14:41:07 +0000 (16:41 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 18 Apr 2017 14:42:16 +0000 (16:42 +0200)
The issue was going to the fact that GL_ALPHA was deprecated in core profile
and common solution online is to use GL_RED instead. That is what is done in
this commit.

source/blender/blenfont/intern/blf_glyph.c
source/blender/gpu/shaders/gpu_shader_text_frag.glsl

index f99f1bf0d6dbe45a9d26180e859244215651666a..a7d52e968006e7090755c0bfa9a1af6cdf8e820c 100644 (file)
@@ -183,7 +183,7 @@ static void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-       glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, gc->p2_width, gc->p2_height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, gc->p2_width, gc->p2_height, 0, GL_RED, GL_UNSIGNED_BYTE, NULL);
 }
 
 GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c)
@@ -459,7 +459,7 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
                glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
                glBindTexture(GL_TEXTURE_2D, g->tex);
-               glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap);
+               glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_RED, GL_UNSIGNED_BYTE, g->bitmap);
 
                glPixelStorei(GL_UNPACK_LSB_FIRST, lsb_first);
                glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length);
index 9283d6827678018dcb1c105c0dd4a073aee3d08d..e0a1991252051d6b66e86da95e604ffccd264b82 100644 (file)
@@ -18,5 +18,5 @@ void main()
        fragColor.rgb = color_flat.rgb;
 
        // modulate input alpha & texture alpha
-       fragColor.a = color_flat.a * texture2D(glyph, texCoord_interp).a;
+       fragColor.a = color_flat.a * texture2D(glyph, texCoord_interp).r;
 }