我想要做的是从单个通道数据阵列将纹理加载到硬件中,并使用它的alpha通道将文本绘制到对象上.我正在使用opengl 4.
如果我尝试使用4通道RGBA纹理这样做,它可以很好地工作,但无论出于何种原因,当我尝试加载单个通道时,我只会得到一个乱码图像,我无法找出原因.我通过将一系列字形的纹理位图数据与以下代码组合成单个纹理来创建纹理:
int texture_height = max_height * new_font->num_glyphs;
int texture_width = max_width;
new_texture->datasize = texture_width * texture_height;
unsigned char* full_texture = new unsigned char[new_texture->datasize];
// prefill texture as transparent
for (unsigned int j = 0; j < new_texture->datasize; j++)
full_texture[j] = 0;
for (unsigned int i = 0; i < glyph_textures.size(); i++) {
// set height offset for glyph
new_font->glyphs[i].height_offset = max_height * i;
for (unsigned int j = 0; j < new_font->glyphs[i].height; j++) {
int full_disp = (new_font->glyphs[i].height_offset …Run Code Online (Sandbox Code Playgroud)