diox8tony
diox8tony

Reputation: 346

glBindTextures returns GL_INVALID_OPERATION

here is some code

GLEnum gl_error;
CString sError = "";
gl_error = glGetError(); //clear the error code
glEnd(); // to make sure Im not between glBegin/glEnd pairing

GLuint tex1;
glGenTextures( 1, &tex1 );

gl_error = glGetError();
if(gl_error == GL_INVALID_VALUE){
    sError = "GL Gen Texture failed\r\n"; // << this does NOT get hit
}

glBindTexture( GL_TEXTURE_2D, tex1 );

gl_error = glGetError();
switch(gl_error){
case GL_INVALID_VALUE:
    sError = "GL Bind Texture failed, VALUE\r\n";
    break;
case GL_INVALID_ENUM:
    sError = "GL Bind Texture failed, ENUM\r\n";
    break;
case GL_INVALID_OPERATION:
    sError = "GL Bind Texture failed, OPERATION\r\n"; // <<< this DOES get hit
    break;
}

"GL_INVALID_OPERATION is generated if texture has a dimensionality which doesn't match that of target.

GL_INVALID_OPERATION is generated if glBindTexture is executed between the execution of glBegin and the corresponding execution of glEnd."

These are the causes of OPERATION error after glBindTexture(), or so I am told by many reference pages. I call a glEnd() by itself to make sure I am out of glBegin()/glEnd() pairs. So I must fall under the second error,,,my texture's dimensionality doesn't match that of the target, however I have been told these 2 functions are all that is needed to create(glGenTextures) a unique texture and bind it(glBindTexture).

ALSO:

GLuint tex1, tex2;
glGenTextures( 1, &tex1 );
glGenTextures( 1, &tex2 );
if(tex1 == tex2){
    sError = "GL Get Tecture failed\r\n";
}

I'm under the assumption that tex1 and tex2 should be unique. but they are not, could my creation of these texture names be my issue? These calls to glGenTexture do NOT return GL_INVALID_VALUE

Upvotes: 0

Views: 5158

Answers (2)

Vadim Karpenko
Vadim Karpenko

Reputation: 1

I also got the same issue, glBindTexture() didn't work.

I managed to fix it setting texture parameters prior to glTexImage2D()

glGenTextures(1, &texOGL);
glBindTexture(GL_TEXTURE_2D, texOGL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

Upvotes: 0

diox8tony
diox8tony

Reputation: 346

I was trying to run this code before even running my main() function, So all my OpenGL initialization calls had not been run yet.

I could have sworn I tried this in the past, but I definitely have more errors, that could have caused it not to run back then either.

Upvotes: 1

Related Questions