rougier / freetype-gl

OpenGL text using one vertex buffer, one texture and FreeType
Other
1.65k stars 266 forks source link

Why texture data is wrong? #194

Open JaroMalonoar opened 6 years ago

JaroMalonoar commented 6 years ago

Hi. I am trying to render text, unfortulately only what I can see are rectangles.

image

formats like png, bmp, jpg loaded with SDL_image renders without any problems. It seems to me that font data is very very wrong. I am attaching source code and render doc scan.

Why is it wrong? How to fix this? I tried to use different depth valeus, but it returns same result.

https://drive.google.com/file/d/1O4P2_2vySYEIfS1DRjuM8w2_Dvq2Ox2p/view?usp=sharing https://pastebin.com/T9gc4jky

cforfang commented 6 years ago

The RenderDoc capture works if I change this line line in the fragment shader: float texColor = texture(u_textureSampler, v_texUV).a; to this: float texColor = texture(u_textureSampler, vec2(v_texUV.x, 1.0 - v_texUV.y)).r;

.a should be .r since it's a GL_RED texture (.r has data while .a is always returned as 1.0), and V is flipped in the vertex shader so I had to flip it back to see the text. Text is still upside down though, but this should hopefully get you back on track. :)

JaroMalonoar commented 6 years ago

Wow! Thank you so much man! I have never thought that I'd be problem with this. Why does it work like this? Also, when I change my projection matrix to be (-16.0f, 16.0f, -9.0f, 9.0f, -1.0f, 1.0f) or (-1.0f, 1.0f, -1.0f, 1.0f) - more similar to NDC text makes faded
image