I'm trying to use stb_truetype "header-only" library for rendering glyphs from TrueType fonts (.ttf) into bitmaps, so I can use them further, but something goes wrong, and bitmap empty
Here include of library:
#define STB_TRUETYPE_IMPLEMENTATION
#include <stb_truetype.h>
And code, that should load font, render glyph of "1" (I guess?) into bitmap and use it to create OpenGL texture:
std::ifstream file(path, std::ios::binary);
if (file.is_open())
{
std::vector<unsigned char> file_data;
char file_data_char;
while (file.get(file_data_char))
{
file_data.push_back(file_data_char);
}
file.close();
stbtt_fontinfo font;
stbtt_InitFont(&font, file_data.data(), 0);
unsigned char* bitmap = stbtt_GetCodepointBitmap(&font, 100, 100, 49, 0, 0, 0, 0);
unsigned int texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, 100, 100, 0, GL_RED, GL_UNSIGNED_BYTE, bitmap);
}
As result, font file loads fine, and seems initialization of font is fine as well, but bitmap empty, and texture is just nothing
I checked examples and discriptions in header (but maybe miss something important, not sure), tried to rewrite by some different ways and for some different glyph, and this still doesn't work