openGL single channel texture always samples 0

  alpha, c++, opengl

I’m trying to render font on screen using freetype. For that, I implemented single channel texture but it always samples 0.

cpp

unsigned char *blankData = new unsigned char[8 * 8];
for(int i = 0; i < 8 * 8; i++){
    blankData[i] = 126;
}
    
glActiveTexture(GL_TEXTURE0);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

GLuint m_texture2D;
glGenTextures(1, &m_texture2D);
glBindTexture(GL_TEXTURE_2D, m_texture2D);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, 8, 8, 0, GL_RED, GL_UNSIGNED_BYTE, blankData);

glUniform1i(glGetUniformLocation(m_program, "texture2D"), 0);

checkGLError();

glGetError() returns GL_NO_ERROR

fragment Shader

#version 330 core

in vec2 texCoord;
in vec4 color;

uniform sampler2D texture2D;
out vec4 outColor;


void main()
{
    vec4 texColor = texture(texture2D, texCoord);
    outColor = vec4(texColor.r, texColor.r, texColor.r, 1.0f);

}

result
enter image description here

ff00ff: clear color

black: fragment shader output texcoord bottomLeft(0, 0) to topRight(1, 1)

Source: Windows Questions C++

LEAVE A COMMENT