PDA

View Full Version : Getting "Invalid Operation" on glTexStorage2D



PastryGood
08-09-2013, 03:35 PM
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\n", 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\n", glGetError());
glBindTexture(GL_TEXTURE_2D, textureHandle);
printf("Err: %d\n", 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\n", 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 :)

carsten neumann
08-09-2013, 04:23 PM
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 (http://www.opengl.org/sdk/docs/man/xhtml/glTexStorage2D.xml):



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.

PastryGood
08-09-2013, 04:39 PM
heh, I feel kind of silly now. This worked :) Sorry for that, but thank you for the help!

arekkusu
08-09-2013, 04:48 PM
GL_RED shouldn't be valid either. This function is only supposed to accept sized internalformats.

PastryGood
08-09-2013, 06:23 PM
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 :)

Alfonse Reinheart
08-09-2013, 07:37 PM
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.

PastryGood
08-10-2013, 11:48 AM
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 :) I think the forum did some weird conversion with smileys, you are correct.