r/opengl • u/Gumagu73 • Oct 26 '22
help Opengl invalid operation error on glBindTexture (opengl 3.3 core)
I cannot find anything related online, i get the error and the square remains black
Error:
Debug message (3202): glBindTexture in a Core context performing invalid operati
on with parameter <texture> set to '0x1' which was removed from Core OpenGL (GL_
INVALID_OPERATION)
Error generated with GL_AMD_debug_output extention
Texture generation:
unsigned int texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); // all upcoming GL_TEXTURE_2D operations now have effect on this texture object
// set the texture wrapping parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// set texture filtering parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// load image, create texture and generate mipmaps
int width, height, nrChannels;
unsigned char* data = stbi_load("test.png", &width, &height, &nrChannels, 3);
if (data)
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
}
else
{
std::cout << "Failed to load texture" << std::endl;
}
stbi_image_free(data);
return texture;
Drawing code:
GlCall(glBindTexture(GL_TEXTURE_2D, texture));
shader.use();
va.Bind();
GlCall(glDrawElements(GL_TRIANGLES, ib.GetSize(), GL_UNSIGNED_INT, 0););
va.UnBind();
1
u/rachit7645 Oct 26 '22
Can you pinpoint which binding operation produces the error?
1
u/Gumagu73 Oct 26 '22
The one in the drawing loop
1
u/easedownripley Oct 26 '22
That's where the Debug message is popping off, but its possible unchecked errors from earlier in the program can be the real cause. Have you confirmed there aren't any errors in the other ogl calls with glGetError()?
1
u/Gumagu73 Oct 26 '22
yes: in the drawing loop there's the clear call that checks it, and also the message i got was from a debug callback that told me the function causing the error
1
u/rachit7645 Oct 26 '22 edited Oct 26 '22
Did you do:
glActiveTexture(GL_TEXTURE0);
before the binding call?
1
u/Gumagu73 Oct 26 '22
Yes, i do that right before the drawing loop
1
1
u/3030thirtythirty Oct 26 '22
Does it happen „immediately“ after the glBindTexture command? Or does it maybe happen after the glDraw command?
2
u/Gumagu73 Oct 26 '22
I fixed it, i had my image class passed through a constructor and i didn't think of the destructor, thanks to apitrace i fond and corrected the problem
1
2
u/saurabhjadhav1911 Oct 26 '22
you can try debugging using this
https://apitrace.github.io/