Getting "Invalid Operation" on glTexStorage2D

Hey everyone,

I’m attempting to apply textures in OpenGL. The problem is that this line:

   
glTexStorage2D(GL_TEXTURE_2D, 0, GL_RED, 4, 4);
printf("Err at glTextStorage2D: %d
", glGetError());

Returns error code 1282, invalid operation. I read on the wiki that a beginners mistake is to set the “levels” to 0, but I’m not at all interested in using mipmaps. Therefore, I attempted to change the texture parameters to disable mipmapping like this:

    
glActiveTexture(GL_TEXTURE0);
printf("Err: %d
", glGetError());
glBindTexture(GL_TEXTURE_2D, textureHandle);
printf("Err: %d
", glGetError());

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexStorage2D(GL_TEXTURE_2D, 0, GL_RED, 4, 4);
printf("Err at glTextStorage2D: %d
", glGetError());

Still, when I get to “glTexStorage2D”, I get the same error code 1282. Does anyone know what’s going on here?

Thank you all for your help :slight_smile:

I read on the wiki that a beginners mistake is to set the “levels” to 0, but I’m not at all interested in using mipmaps.

Ok, but the wiki also says in that case you should set levels to 1, because:

From glTexStorage2D:

GL_INVALID_VALUE is generated if width or levels are less than 1.

You need at least the base level, otherwise there is no space for any texels.

heh, I feel kind of silly now. This worked :slight_smile: Sorry for that, but thank you for the help!

GL_RED shouldn’t be valid either. This function is only supposed to accept sized internalformats.

GL_RED shouldn’t be valid either. This function is only supposed to accept sized internalformats.

Absolutely correct, I had to change it to GL_RGB :slight_smile:

That’s not a sized internal format either. Unless you meant GL_RGB8, and the forum merged your 8 with some punctuation to turn it into a smilie.

That’s not a sized internal format either. Unless you meant GL_RGB8, and the forum merged your 8 with some punctuation to turn it into a smilie.

Yes I meant to say GL_RGB8 :slight_smile: I think the forum did some weird conversion with smileys, you are correct.