glCopyTexImage2D error - GL_INVALID_ENUM

I have a problem with glCopyTexImage2D - look at this util method which is cutting previously rendered scene to the texture:

    public static Texture cutRenderToTexture(GL g, int width, int height) { 
        IntBuffer buff = Buffers.newDirectIntBuffer(1); 
        g.glGenTextures(1, buff); 
        int tex = buff.get(); 
        g.glBindTexture(GL.GL_TEXTURE_2D, tex); 
        checkGLError(g); 
        g.glCopyTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, 0, 0, width, height, 0); 
        checkGLError(g); 
        g.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); 
        return TextureIO.newTexture(tex, GL.GL_TEXTURE_2D, width, height, width, height, false); 
    } 

checkGLError is a simple method which is checking all possible OpenGL errors - in this example I am calling it twice to show that problem can be related only to glCopyTexImage2D call. I am getting GL_INVALID_ENUM error, but target is valid, GL_TEXTURE_2D enabled and OpenGL docs ( https://www.opengl.org/sdk/docs/man4/xhtml/glCopyTexImage2D.xml ) do not specify if this error can happen in any other case.

Any ideas what is wrong?

What are you trying to achieve? It would probably be better done through FBOs, since glCopyTexImage2D introduces pipeline stalls and can really impact performance.

You should set up min filter to NEAREST or LINEAR since the default expects mipmapping (which you aren’t using, i.e. it will cause an invalid operation somewhere down the line).

Perhaps the method is implemented incorrectly in LibGDX (this is LibGDX right?) You could check out the source code.

This is JOGL 2. I use this OpenGL call too but I don’t get this error.