Problem multitexture/shaders: GL_INVALID_OPERATION

Hi!!

I’m a relative new on OpenGL (I’m working with jogl, but i think there are not so many differences), and I must do a video transformation from YUV to RGB, creating the 3 textures for shading and using VBO. So each time the screen is displayed I must create a new 3 textures, bind over a mesh structure and pass them to the shaders. But I get an GL_INVALID_OPERATION before anything… Could anyone take a look and tell me where is my problem, Please? (Shaders are compiled without errors)

  

// init
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL.GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

glGenTextures(3, textures, 0);
    yTex = textures[0];
    uTex = textures[1];
    vTex = textures[2];

//display function

glUseProgramObjectARB(programVertexOBJ);
glUseProgramObjectARB(programFragmentOBJ);

glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
glLoadIdentity();							

glEnable(GL.GL_TEXTURE_RECTANGLE_ARB);
   	int offset = 0;

offset += updateTexture(yTex, GL_TEXTURE0, "yTex", offset, text.getWidth(), text.getHeight());
offset += updateTexture(uTex, GL_TEXTURE1, "uTex", offset, text.getWidth() / 2, text.getHeight() / 2);
offset += updateTexture(vTex, GL_TEXTURE2, "vTex", offset, text.getWidth() / 2, text.getHeight() / 2);

displayGlCuadrad();

glUseProgramObjectARB(0);

// updateTexture
checkErrors();    // Here is the error found 
int i;
glActiveTexture(glTextureUnit);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);

i = glGetUniformLocationARB(programFragmentOBJ, variableName);
    glUniform1fARB(i, glTextureUnit);

glTexEnvf(GL_TEXTURE_RECTANGLE_ARB,GL.GL_TEXTURE_ENV_MODE,GL.GL_DECAL);

glTexImage2D (GL_TEXTURE_RECTANGLE_ARB,
	      0,
	      1,
	      width , height,
	      0,
	      GL_LUMINANCE,
              GL_UNSIGNED_BYTE,
	      pixels);

glTexParameterf (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

//displayGLcuadrad()

gl.glBegin(GL.GL_QUADS);

gl.glMultiTexCoord3f(GL.GL_TEXTURE0, 0, VIDEO_HEIGHT,1f);
gl.glMultiTexCoord3f (GL.GL_TEXTURE1, 0, VIDEO_HEIGHT / 2,1f);
gl.glMultiTexCoord3f (GL.GL_TEXTURE2, 0, VIDEO_HEIGHT / 2,1f);
gl.glVertex3f(-VIDEO_WIDTH/2, -VIDEO_HEIGHT/2, 0f);

gl.glMultiTexCoord3f(GL.GL_TEXTURE0, VIDEO_WIDTH, VIDEO_HEIGHT,1f);
gl.glMultiTexCoord3f(GL.GL_TEXTURE1, VIDEO_WIDTH / 2, VIDEO_HEIGHT / 2,1f);
gl.glMultiTexCoord3f(GL.GL_TEXTURE2, VIDEO_WIDTH / 2, VIDEO_HEIGHT / 2,1f);
gl.glVertex3f(VIDEO_WIDTH/2, -VIDEO_HEIGHT/2, 0f);

gl.glMultiTexCoord3f(GL.GL_TEXTURE0, VIDEO_WIDTH, 0,1f);
gl.glMultiTexCoord3f(GL.GL_TEXTURE1, VIDEO_WIDTH / 2, 0,1f);
gl.glMultiTexCoord3f(GL.GL_TEXTURE2, VIDEO_WIDTH / 2, 0,1f);
gl.glVertex3f(VIDEO_WIDTH/2, VIDEO_HEIGHT/2, 0f);

gl.glMultiTexCoord3f (GL.GL_TEXTURE0, 0, 0 ,1f);
gl.glMultiTexCoord3f (GL.GL_TEXTURE1, 0, 0,1f);
gl.glMultiTexCoord3f (GL.GL_TEXTURE2, 0, 0,1f);
gl.glVertex3f(-VIDEO_WIDTH/2, VIDEO_HEIGHT/2, 0f);

gl.glEnd();


There is a lot of stuff missing to say where the error comes from. Just add more error calls to identify the first call which fires it. (Just don’t add one between glBegin-glEnd, that’s an error in itself.)

1.)
glUseProgramObjectARB(programVertexOBJ);
glUseProgramObjectARB(programFragmentOBJ);

That looks weird. A GLSL program is a single program linked from shaders compiled for the different domains it uses.
Above means use the programFragmentOBJ only. Intended?

2.)
glEnable(GL.GL_TEXTURE_RECTANGLE_ARB);

You don’t need to enable texturing for usage inside shaders.

3.)
glTexEnvf(GL_TEXTURE_RECTANGLE_ARB,GL.GL_TEXTURE_ENV_MODE,GL.GL_DECAL);

glTexEnv is replaced by fragment shaders. The above call is irrelevant.

4.) Since you’re using shaders there is no need to setup multiple identical MultiTexCoords.

Hi and Thanks!!

I changed the things you said and I already found the problem. It came because I was using

glUniform1fARB(i, glTextureUnit);

Instead of integer (glUniform1iARB ) and glTextureUnit was GL_TEXTURE0, when it should be the pointer to the texture.

Thank you again

That parameter needs to be the zero based texture unit index, so integers 0, 1, 2, 3, and so forth; not a pointer to a texture (object).

Nevermind if you meant that, just for others who ran into this. This is one of the OpenGL Wiki topics on GLSL: http://www.opengl.org/wiki/index.php/GLSL_:_common_mistakes