7
\$\begingroup\$

I've spent the past couple of days just desperately trying to get stb_truetype to render anything using the simple example provided https://github.com/nothings/stb/blob/master/stb_truetype.h#L242-L281, however, no matter what I tried, the texture being loaded always ends up being completely black.

I've tried writing the generated texture data back to a .png file as

lodepng::encode("foopng", temp_bitmap, 512, 512, LCT_GREY);

and the font actually gets rendered properly

However, when I inspect the loaded texture in Nsight (or CodeXL), it looks completely black, and upon inspection of the actual data in the texture in CodeXL, it shows zeros basically everywhere, except for one small blob of a few non-zero numbers (which is nothing like the saved PNG).

I also tried changing to a different font and the generated quad geometry does change, as do the generated texture coordintes by stbtt_GetBakedQuad(...) (I even tried to manually set the texture coordinates all the way from 0 to 1 on the edges of the quad).

I'm not sure if it's CodeXL and Nsight both mis-interpreting the contents of the texture, even though the data view in the screenshot shows each byte, but when rendering I also get everything rendered with this texture completely black.

Is the texture being loaded incorrectly, or am I doing something else wrong? I'm using OpenGL 4.4.

\$\endgroup\$
2
  • \$\begingroup\$ The uploaded picture from Nsight is so blurred you cannot distinguish a single digit. \$\endgroup\$
    – Andreas
    Commented May 5, 2016 at 12:29
  • \$\begingroup\$ @Andreas sorry about that, I thought it'd link to a high res version. Anyway, everyhting on the screenshot is zeros, except for a few numbers on the bottom right, which are just some random numbers. \$\endgroup\$ Commented May 5, 2016 at 14:51

1 Answer 1

5
\$\begingroup\$

Recently I've had the same problem using LWJGL/STB and modern OpenGL.

Changing font texture format helped in my case. Try changing:

glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 512,512, 0, GL_ALPHA, GL_UNSIGNED_BYTE, temp_bitmap);

to:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, 512,512, 0, GL_RED, GL_UNSIGNED_BYTE, temp_bitmap);

I think it works same way as

lodepng::encode("foopng", temp_bitmap, 512, 512, LCT_GREY);

did, representing the alpha value as GREY(RED) color.

\$\endgroup\$
1
  • \$\begingroup\$ Also try to enable blending... \$\endgroup\$ Commented Aug 21, 2016 at 15:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .