title: sdl surface to opengl texture
body: <p>How can I convert a .png image to an OpenGL surface, with SDL? what I have now:</p>
  
  <pre><code>typedef GLuint texture;
  
  texture load_texture(std::string fname){
      SDL_Surface *tex_surf = IMG_Load(fname.c_str());
      if(!tex_surf){
              return 0;
      }
      texture ret;
      glGenTextures(1, &amp;ret);
      glBindTexture(GL_TEXTURE_2D, ret);
      glTexImage2D(GL_TEXTURE_2D, 0, 3, tex_surf-&gt;w, tex_surf-&gt;h, 0, GL_RGB,          GL_UNSIGNED_BYTE, tex_surf-&gt;pixels);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      SDL_FreeSurface(tex_surf);
      return ret;
  }
  </code></pre>
  
  <p>and my code to draw the thing:</p>
  
  <p>glEnable(GL_TEXTURE_2D);
              glBindTexture(GL_TEXTURE_2D, tex);</p>
  
  <pre><code>        //Use blurry texture mapping (replace GL_LINEAR with GL_NEAREST for blocky)
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  
          glColor4f( 1.0, 1.0, 1.0, 1.0 ); //Don't use special coloring
  
          glBegin(GL_QUADS);
  
          glTexCoord2f(0.0f, 0.0f);
          glVertex3f(0.0f, 0.0f, 0.0f);
          glTexCoord2f(1.0f, 0.0f);
          glVertex3f(128.0f, 0.0f, 0.0f);
          glTexCoord2f(1.0f, 1.0f);
          glVertex3f(128.0f, 128.0f, 0.0f);
          glTexCoord2f(0.0f, 1.0f);
          glVertex3f(0.0f, 128.0f, 0.0f);
  
          glEnd();
  
          glDisable(GL_TEXTURE_2D);
  </code></pre>
  
  <p>The problem is that it only works with .bmp files, and they turn bluish, so what is wrong?
  Also, when I try to load a .png, it shows up really weird.</p>