title: glTexSubImage2D does not work correctly
body: <p>I've written a very simple OpenGL application. Its goal is to load a texture and draw it on a plane. If I use the function 'glTexSubImage2D' the plane is not textured and the function 'glGetError' returns the error '1281' (invalid value). However if I use the function 'glTexImage2D' my plane plane is textured correctly (and I have no error).</p>
  
  <p>Here's a piece of my code :</p>
  
  <pre><code>void core::RootDevice::LoadTexture(char const *pFileName)
  {
      SDL_Surface *pSurface = IMG_Load(pFileName);
      char *pPixels = reinterpret_cast&lt;char*&gt;(pSurface-&gt;pixels);
      uint32_t bytePerPixel = pSurface-&gt;format-&gt;BitsPerPixel;
  
      glGenTextures(1, &amp;textureId);
      glBindTexture(GL_TEXTURE_2D, textureId);
      {
          glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboID);
          {
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  
              //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pSurface-&gt;w,       //NO ERROR : All is ok
                  //pSurface-&gt;h, 0, GL_RGB, GL_UNSIGNED_BYTE, pPixels);
  
              glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, pSurface-&gt;w,        //ERROR : 1281
                  pSurface-&gt;h, GL_RGB, GL_UNSIGNED_BYTE, pPixels);
  
              std::cout &lt;&lt; glGetError() &lt;&lt; std::endl;
              getchar();
          }
          glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
      }
      glBindTexture(GL_TEXTURE_2D, 0);
  }
  </code></pre>
  
  <p>And the rendering code :</p>
  
  <pre><code>void core::RootDevice::Render(void)
  {
      glActiveTexture(GL_TEXTURE0);
      glBindTexture(GL_TEXTURE_2D, textureId);
      {
          glBegin(GL_QUADS);
              glTexCoord2f(0.0f, 0.0f);
              glVertex3f(-1.0f, -1.0f, 0.0f);
              glTexCoord2f(1.0f, 0.0f);
              glVertex3f(1.0f, -1.0f, 0.0f);
              glTexCoord2f(1.0f, 1.0f);
              glVertex3f(1.0f, 1.0f, 0.0f);
              glTexCoord2f(0.0f, 1.0f);
              glVertex3f(-1.0f, 1.0f, 0.0f);
          glEnd();
      }
      glBindTexture(GL_TEXTURE_2D, 0);
  }
  </code></pre>
  
  <p>And the result is the followings:</p>
  
  <p><img src="https://i.stack.imgur.com/nhWVu.jpg" alt="enter image description here"></p>
  
  <p>Does anyone can help me?</p>