My Texture disappear (became black) and glBindTexture isn't called

I have a terrible behavior with one of my textures on OpenGL.

The texture is correctly displayed on the first frame, but after a few renders, it turns black.

After analyzing the opengl call stack, it seems that the “glBindTexture” method is called on the first frame but is no longer called when the texture turns black.

If the “glbindtexture” is not called, the texture is logically black, but I don’t understand why the “glbindtexture” is not called after some rendering .

////////////////
Setup texture :
////////////////

//SET UNPRESSED BUTTON TEXTURE
glBindTexture(GL_TEXTURE_2D, 0);
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);

// Decode image into its raw image data
if (convertImageToRawImage(buttonImage))
{

//if decompression was successful, set the texture parameters

// set the texture wrapping parameters
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// set the texture magnification/minification parameters
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

// load the image data into the current bound texture buffer
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                 &image[0]);

}

image.clear();

/////////////////
Draw Texture :
/////////////////

ViewerContext->browser->ButtonShader->use();

setTransformation();

// Bind the VAO
glBindVertexArray(vertexArrayObject);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);

// If the isPressed value is true, then update the state of the button
if (isPressed == true)
{

    glUniform1i(ButtonStateUniformLocation, 1);

    glBindTexture(GL_TEXTURE_2D, 0);
    glActiveTexture(GL_TEXTURE0 + 1);
    glBindTexture(GL_TEXTURE_2D, texturePID);
    glEnable(GL_TEXTURE_2D);

    glUniform1i(ButtonAPressedTextureUniformLocation, 1);

}
else
{

    glUniform1i(ButtonStateUniformLocation, 0);

    glBindTexture(GL_TEXTURE_2D, 0);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, textureID);
    glEnable(GL_TEXTURE_2D);

    glUniform1i(ButtonATextureUniformLocation, 0);

}

// Start the rendering process

// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);

// 2nd attribute buffer : UVs
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, UVBufferObject);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);


// Draw call
glDrawArrays(GL_TRIANGLES, 0, buttonVertices.size());

Images :

Call Stack When texture display:

Call Stack When texture not display:

Render:

Am I correct in assuming that one of the glUniform1i calls is setting a sampler2D uniform to select which texture to use? If so, why are you unbinding textures rather than just leaving them bound? Or rather than just binding the appropriate texture to a specific unit and leaving the uniform alone?

Also, glEnable(GL_TEXTURE_2D) is meaningless if you’re using a shader. That isn’t even a valid argument to glEnable in the core profile.

And you shouldn’t be calling glEnableVertexAttribArray or glVertexAttribPointer as part of the rendering process if you’re using VAOs. You’d use those to initialise the VAO state then just call glBindVertexArray during rendering.

In any case, it’s impossible to determine the cause of the problem from the fragments which have been posted.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.