My question is very similar to this one but the answers there did not help me.

I am trying to use the DSA approach to bind textures and it is not working.

Here is my attempt at the DSA code, which leads too all black in as my output:

GLuint samplerName;
glCreateSamplers(1, &samplerName);
glSamplerParameteri(samplerName, GL_TEXTURE_WRAP_S, GL_REPEAT);
glSamplerParameteri(samplerName, GL_TEXTURE_WRAP_T, GL_REPEAT);
glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindSampler(0, samplerName);

// Create texture
GLuint texture;
glCreateTextures(GL_TEXTURE_2D, 1, &texture);
glTextureStorage2D(texture, 1, GL_RGB, width, height);
glTextureSubImage2D(texture, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTextureUnit(0, texture);

If I add these two lines from the older approach:

glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

it works so I do not think it is an issue with my sampler or my data. Does anybody have any advice here?


1 Answer 1


My issue was in the call to glTextureStorage2D(texture, 1, GL_RGB, width, height);

From the man page

internalformat must be one of the sized internal formats given in Table 1 below, one of the sized depth-component formats GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT24, or GL_DEPTH_COMPONENT16, one of the combined depth-stencil formats, GL_DEPTH32F_STENCIL8, or GL_DEPTH24_STENCIL8, or the stencil-only format, GL_STENCIL_INDEX8

Changing GL_RGB to GL_RGB8 fixed my issue.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.