title: SDL2 with OpenGL texture displaying incorrectly
body: <p>I have searched for this but unfortunately the only answers I find are those that deal with the issue of textures not being mapped, in this case the texture is mapped but does not look like the loaded surface.</p>
  
  <p>Anyway, ignoring the fact that power of 2 square images aren't required (which I've yet to properly look into yet) I've made a functional script for expanding the surface to power of 2 dimensions and a structure for storing the resized surface, the old dimensions of the surface and the ID for the texture.</p>
  
  <p>My surface to texture code is (arguments are SDL_Surface* surf, antTex* tex):</p>
  
  <pre><code>tex-&gt;w=surf-&gt;w;
  tex-&gt;h=surf-&gt;h;
  tex-&gt;surf=resizeToNearestPow2(surf);
  glGenTextures(1, &amp;tex-&gt;id);
  glBindTexture(GL_TEXTURE_2D, tex-&gt;id);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex-&gt;surf-&gt;w, tex-&gt;surf-&gt;h, 0, GL_BGRA, GL_UNSIGNED_BYTE, tex-&gt;surf-&gt;pixels);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glBindTexture(GL_TEXTURE_2D, NULL);
  </code></pre>
  
  <p>The antTex struct is:</p>
  
  <pre><code>GLuint id;          //Texture ID
  int w, h;           //Original Image Size
  int rw, rh;         //Resized Canvas Size
  SDL_Surface* surf;  //Resized Surface
  </code></pre>
  
  <p>Everything about resizing the image appears to be working fine (having used SDL's SDL_SaveBMP function to check the resulting image), I used SDL2_image.h's IMG_Load for loading the original image.</p>
  
  <p>When I draw a plane with the texture mapped to it while GL_BLEND is enabled nothing shows up at all, when I disable it I get this (the red is the window's background colour): </p>
  
  <p><a href="http://i1200.photobucket.com/albums/bb336/DarknessXeagle/error_zps03e1e5a1.png" rel="nofollow">http://i1200.photobucket.com/albums/bb336/DarknessXeagle/error_zps03e1e5a1.png</a></p>
  
  <p>The original image was this:</p>
  
  <p><a href="http://i1200.photobucket.com/albums/bb336/DarknessXeagle/d_zpsc8b9af6f.png" rel="nofollow">http://i1200.photobucket.com/albums/bb336/DarknessXeagle/d_zpsc8b9af6f.png</a></p>
  
  <p>This is my function for drawing plane with the texture mapped to it (arguments are antTex* tex, int x, int y):</p>
  
  <pre><code>glBindTexture(GL_TEXTURE_2D, tex-&gt;id);
  int w, h;
  w=tex-&gt;w;
  h=tex-&gt;h;
  GLfloat tw, th;
  th=(GLfloat)tex-&gt;h/(GLfloat)tex-&gt;rh;
  tw=(GLfloat)tex-&gt;w/(GLfloat)tex-&gt;rw;
  glPushMatrix();
      glTranslatef(x, y, 0);
      glBegin(GL_QUADS);
          glNormal3f(0, 0, 1);
          glTexCoord2f(0, th);    glVertex2f(0, h);
          glTexCoord2f(tw, th);   glVertex2f(w, h);
          glTexCoord2f(tw, 0);    glVertex2f(w, 0);
          glTexCoord2f(0, 0);     glVertex2f(0, 0);
      glEnd();
  glPopMatrix();
  glBindTexture(GL_TEXTURE_2D, NULL);
  </code></pre>