title: rendering SDL_TTF text onto openGL Red Square instead of text
body: <p>I've been attempting to render text onto an openGL window using SDL and the SDL_TTF library on windows XP, VS2010.<br>
  Versions:<br>
  SDL version 1.2.14<br>
  SDL TTF devel 1.2.10<br>
  openGL (version is at least 2-3 years old).</p>
  
  <p>I have successfully created an openGL window using SDL / SDL_image and can render lines / polygons onto it with no problems.</p>
  
  <p>However, moving onto text it appears that there is some flaw in my current program, I am getting the following result when trying <a href="http://pastebin.com/9WJ5B8v0" rel="nofollow noreferrer">this code here</a></p>
  
  <p><img src="https://i.stack.imgur.com/kktt1.png" alt="enter image description here"></p>
  
  <p>for those not willing to pastebin here are only the crutial code segments:</p>
  
  <pre><code>void drawText(char * text) {
      glLoadIdentity();
      SDL_Color clrFg = {0,0,255,0}; // set colour to blue (or 'red' for BGRA)
      SDL_Surface *sText = TTF_RenderUTF8_Blended( fntCourier, text, clrFg );
      GLuint * texture = create_texture(sText);
      glBindTexture(GL_TEXTURE_2D, *texture);
      // draw a polygon and map the texture to it, may be the source of error
      glBegin(GL_QUADS); {
          glTexCoord2i(0, 0); glVertex3f(0, 0, 0);
          glTexCoord2i(1, 0); glVertex3f(0 + sText-&gt;w, 0, 0);
          glTexCoord2i(1, 1); glVertex3f(0 + sText-&gt;w, 0 + sText-&gt;h, 0);
          glTexCoord2i(0, 1); glVertex3f(0, 0 + sText-&gt;h, 0);
      } glEnd();
      // free the surface and texture, removing this code has no effect
      SDL_FreeSurface( sText );
      glDeleteTextures( 1, texture );
  }
  </code></pre>
  
  <p>segment 2:</p>
  
  <pre><code>// create GLTexture out of SDL_Surface
  GLuint * create_texture(SDL_Surface *surface) {
      GLuint texture = 0;
  
      glGenTextures(1, &amp;texture);
      glBindTexture(GL_TEXTURE_2D, texture);
      // The SDL_Surface appears to have BGR_A formatting, however this ends up with a 
      // white rectangle no matter which colour i set in the previous code.
      int Mode = GL_RGB;
  
      if(surface-&gt;format-&gt;BytesPerPixel == 4) {
          Mode = GL_RGBA;
      }
  
      glTexImage2D(GL_TEXTURE_2D, 0, Mode, surface-&gt;w, surface-&gt;h, 0, Mode, 
                   GL_UNSIGNED_BYTE, surface-&gt;pixels);
  
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  
      return &amp;texture;
  }
  </code></pre>
  
  <p>Is there an obvious bit of code I am missing?<br>
  Thank you for any help on this subject.<br>
  I've been trying to learn openGL and SDL for 3 days now, so please forgive any misinformation on my part.</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>I notice that using<br>
  <code>TTF_RenderUTF8_Shaded</code><br>
  <code>TTF_RenderUTF8_Solid</code></p>
  
  <p>Throw a null pointer exception, meaning that there is an error within the actual text rendering function (I suspect), I do not know how this means <code>TTF_RenderUTF8_Blended</code> returns a red square but I suspect all troubles hinge on this.</p>