   Texture in all?
  I have a very strange error, I looked on google and here on GameDev about on it. But unsuccessfully.When I start loading a texture (. Tag), before you even apply in a polygon (GL_QUADS), this texture is already applied to it by the coordinates passed (glTexCoord2f) and modify the colors of other polygons.tgaload.h/*  Definitions for bitflags  */typedef unsigned int tgaFLAG;#define TGA_DEFAULT  0x0000000000000000   /* In case we don't want any parameters */#define TGA_FREE0x0000000000000001   /* Bit flag 0 */#define TGA_NO_PASS  0x0000000000000010   /* Bit flag 1 */#define TGA_ALPHA    0x0000000000000100   /* Bit flag 2 */#define TGA_LUMINANCE0x0000000000001000   /* Bit flag 3 */#define TGA_NO_MIPMAPS    0x0000000000010000   /* Bit flag 4 */#define TGA_LOW_QUALITY   0x0000000000100000   /* Bit flag 5 */#define TGA_COMPRESS 0x0000000001000000   /* Bit flag 6 *//*** GL_ARB_texture_compression**** Support:**  GeForce**  Radeon**  ????   <- Any suggestions?*/#ifndef GL_ARB_texture_compression#define GL_ARB_texture_compression 1#define GL_COMPRESSED_ALPHA_ARB 0x84E9#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB#define GL_COMPRESSED_INTENSITY_ARB 0x84EC#define GL_COMPRESSED_RGB_ARB    0x84ED#define GL_COMPRESSED_RGBA_ARB 0x84EE#define GL_TEXTURE_COMPRESSION_HINT_ARB    0x84EF#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0#define GL_TEXTURE_COMPRESSED_ARB 0x86A1#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3typedef void (APIENTRY * PFNGLCOMPRESSEDTEXIMAGE3DARBPROC)(GLenum target, GLint level,    GLenum internalFormat, GLsizei width,   GLsizei height, GLsizei depth,   GLint border, GLsizei imageSize,   const GLvoid *data);typedef void (APIENTRY * PFNGLCOMPRESSEDTEXIMAGE2DARBPROC)(GLenum target, GLint level,   GLenum internalFormat, GLsizei width,   GLsizei height, GLint border,   GLsizei imageSize, const GLvoid *data);typedef void (APIENTRY * PFNGLCOMPRESSEDTEXIMAGE1DARBPROC)(GLenum target, GLint level,   GLenum internalFormat, GLsizei width,   GLint border, GLsizei imageSize,   const GLvoid *data);typedef void (APIENTRY * PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC)(GLenum target, GLint level,  GLint xoffset, GLint yoffset,  GLint zoffset, GLsizei width,  GLsizei height, GLsizei depth,  GLenum format, GLsizei imageSize,  const GLvoid *data);typedef void (APIENTRY * PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC)(GLenum target, GLint level,  GLint xoffset, GLint yoffset,  GLsizei width, GLsizei height,  GLenum format, GLsizei imageSize,  const GLvoid *data);typedef void (APIENTRY * PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC)(GLenum target, GLint level,  GLint xoffset, GLsizei width,  GLenum format, GLsizei imageSize,  const GLvoid *data);typedef void (APIENTRY * PFNGLGETCOMPRESSEDTEXIMAGEARBPROC)(GLenum target, GLint lod, GLvoid *img);#endif /* GL_ARB_texture_compression */typedef struct {   unsigned char id_length;   unsigned char colour_map_type;   unsigned char image_type;   // colourmap spec.  5 bytes   short intcolour_map_first_entry;  // Ignore   short intcolour_map_length;  // Usually 256   unsigned char colour_map_entry_size;   // Usually 24-bit   // image spec.  10 bytes   short intx_origin;  // Ignore   short inty_origin;  // Ignore   short intwidth;   short intheight;   unsigned char pixel_depth;  // Usually 24 or 32   unsigned char image_descriptor;  // Ignore   // Added for 'compeletness' :)   int   components;   int   bytes;   GLenum tgaColourType;} tgaHeader_t;typedef struct {   tgaHeader_tinfo;   unsigned char   *data; /* Image data */} image_t;/* 'Public' functions */void   tgaLoad   ( char *file_name, image_t *p, tgaFLAG mode );GLuint tgaLoadAndBind ( char *file_name, tgaFLAG mode );void tgaSetTexParams  ( unsigned int min_filter, unsigned int mag_filter, unsigned int application );void tgaFree ( image_t *p );tgaload.cpp/*   ...   From:  http://nehe.gamedev.net   Aug 19th:   Added support for runlength encoding - changed some stuff around to make this   possible.  Works well :)   Sept 7th:   Improved error trapping and recovery.   Oct 22nd:   Major source clearout & Can compress the image using S3_TC algorithm if the    driver supports it.Nov 10th:   'Settled' version of the code - traps for nearly all errors - added a    LoadAndBind function for even lazier people :)   TGA_NO_PASS was added in case you need to load an image and pass it yourself.   Finally exorcised all the paletted texture code...*/#include <windows.h>#include <GL\glu.h>#include <stdio.h>#include <stdlib.h>#include "tgaload.h"/* Extension Management */PFNGLCOMPRESSEDTEXIMAGE2DARBPROC  glCompressedTexImage2DARB  = NULL;PFNGLGETCOMPRESSEDTEXIMAGEARBPROC glGetCompressedTexImageARB = NULL;/* Default support - lets be optimistic! */bool tgaCompressedTexSupport = true;void tgaGetExtensions ( void ){glCompressedTexImage2DARB  = ( PFNGLCOMPRESSEDTEXIMAGE2DARBPROC  )wglGetProcAddress ( "glCompressedTexImage2DARB"  );   glGetCompressedTexImageARB = ( PFNGLGETCOMPRESSEDTEXIMAGEARBPROC )wglGetProcAddress ( "glGetCompressedTexImageARB" ); if ( glCompressedTexImage2DARB == NULL || glGetCompressedTexImageARB == NULL )   tgaCompressedTexSupport = false;}void tgaSetTexParams  ( unsigned int min_filter, unsigned int mag_filter, unsigned int application ){   glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter );   glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter );   glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, application );}unsigned char *tgaAllocMem ( tgaHeader_t info ){   unsigned char  *block;   block = (unsigned char*) malloc ( info.bytes );   if ( block == NULL ) return 0;   memset ( block, 0x00, info.bytes );   return block;}void tgaPutPacketTuples ( image_t *p, unsigned char *temp_colour, int &current_byte ){   if ( p->info.components == 3 )   { p->data[current_byte]   = temp_colour[2]; p->data[current_byte+1] = temp_colour[1]; p->data[current_byte+2] = temp_colour[0]; current_byte += 3;   }   if ( p->info.components == 4 )    // Because its BGR(A) not (A)BGR :(   { p->data[current_byte]   = temp_colour[2]; p->data[current_byte+1] = temp_colour[1]; p->data[current_byte+2] = temp_colour[0]; p->data[current_byte+3] = temp_colour[3]; current_byte += 4;   }}void tgaGetAPacket ( int &current_byte, image_t *p, FILE *file ){   unsigned char  packet_header;   int  run_length;   unsigned char  temp_colour[4] = { 0x00, 0x00, 0x00, 0x00 };   fread   ( &packet_header, ( sizeof ( unsigned char )), 1, file );   run_length = ( packet_header&0x7F ) + 1;   if ( packet_header&0x80 )  // RLE packet   { fread ( temp_colour, ( sizeof ( unsigned char )* p->info.components ), 1, file ); if ( p->info.components == 1 )  // Special optimised case :) {    memset ( p->data + current_byte, temp_colour[0], run_length );    current_byte += run_length; } else for ( int i = 0; i < run_length; i++ )    tgaPutPacketTuples ( p, temp_colour, current_byte );   }   if ( !( packet_header&0x80 ))  // RAW packet   { for ( int i = 0; i < run_length; i++ ) {    fread ( temp_colour, ( sizeof ( unsigned char )* p->info.components ), 1, file );    if ( p->info.components == 1 )    {  memset ( p->data + current_byte, temp_colour[0], run_length );  current_byte += run_length;    } else  tgaPutPacketTuples ( p, temp_colour, current_byte ); }   }} void tgaGetPackets ( image_t *p, FILE *file ){  int current_byte = 0;  while ( current_byte < p->info.bytes )    tgaGetAPacket ( current_byte, p, file );}void tgaGetImageData ( image_t *p, FILE *file ){   unsigned char  temp;   p->data = tgaAllocMem ( p->info );   /* Easy unRLE image */   if ( p->info.image_type == 1 || p->info.image_type == 2 || p->info.image_type == 3 )   {    fread ( p->data, sizeof (unsigned char), p->info.bytes, file ); /* Image is stored as BGR(A), make it RGB(A)*/ for (int i = 0; i < p->info.bytes; i += p->info.components ) {    temp = p->data;    p->data = p->data;<br>    p-&gt;data = temp;<br> }<br>   }<br>   <br>   <span class="cpp-comment">/* RLE compressed image */</span><br>   <span class="cpp-keyword">if</span> ( p-&gt;info.image_type == <span class="cpp-number">9</span> || p-&gt;info.image_type == <span class="cpp-number">10</span> )<br> tgaGetPackets ( p, file );<br>}<br><br><br><span class="cpp-keyword">void</span> tgaUploadImage ( image_t *p, tgaFLAG mode )<br>{<br>   <span class="cpp-comment">/*  Determine TGA_LOWQUALITY  internal format<br>  This directs OpenGL to upload the textures at half the bit<br>  precision - saving memory<br>    */</span><br>   GLenum internal_format = p-&gt;info.tgaColourType;<br><br><span class="cpp-keyword">if</span> ( mode&amp;TGA_LOW_QUALITY )<br>   {<br> <span class="cpp-keyword">switch</span> ( p-&gt;info.tgaColourType )<br> {<br>    <span class="cpp-keyword">case</span> GL_RGB  : internal_format = GL_RGB4; <span class="cpp-keyword">break</span>;<br>    <span class="cpp-keyword">case</span> GL_RGBA : internal_format = GL_RGBA4; <span class="cpp-keyword">break</span>; <br>    <span class="cpp-keyword">case</span> GL_LUMINANCE : internal_format = GL_LUMINANCE4; <span class="cpp-keyword">break</span>;<br>    <span class="cpp-keyword">case</span> GL_ALPHA: internal_format = GL_ALPHA4; <span class="cpp-keyword">break</span>;<br> }<br>   }<br><br>   <span class="cpp-comment">/*  Let OpenGL decide what the best compressed format is each case. */</span>   <br>   <span class="cpp-keyword">if</span> ( mode&amp;TGA_COMPRESS &amp;&amp; tgaCompressedTexSupport )<br>   {  <br> <span class="cpp-keyword">switch</span> ( p-&gt;info.tgaColourType )<br> {<br>    <span class="cpp-keyword">case</span> GL_RGB  : internal_format = GL_COMPRESSED_RGB_ARB; <span class="cpp-keyword">break</span>;<br>    <span class="cpp-keyword">case</span> GL_RGBA : internal_format = GL_COMPRESSED_RGBA_ARB; <span class="cpp-keyword">break</span>; <br>    <span class="cpp-keyword">case</span> GL_LUMINANCE : internal_format = GL_COMPRESSED_LUMINANCE_ARB; <span class="cpp-keyword">break</span>; <br>    <span class="cpp-keyword">case</span> GL_ALPHA: internal_format = GL_COMPRESSED_ALPHA_ARB; <span class="cpp-keyword">break</span>;<br> }<br>   }  <br>    <br>   <span class="cpp-comment">/*  Pass OpenGL Texture Image */</span><br>   <span class="cpp-keyword">if</span> ( !( mode&amp;TGA_NO_MIPMAPS ))<br> gluBuild2DMipmaps ( GL_TEXTURE_2D, internal_format, p-&gt;info.width,<br> p-&gt;info.height, p-&gt;info.tgaColourType, GL_UNSIGNED_BYTE, p-&gt;data );<br>   <span class="cpp-keyword">else</span><br> glTexImage2D ( GL_TEXTURE_2D, <span class="cpp-number">0</span>, internal_format, p-&gt;info.width,<br> p-&gt;info.height, <span class="cpp-number">0</span>, p-&gt;info.tgaColourType, GL_UNSIGNED_BYTE, p-&gt;data );  <br>}<br><br><br><span class="cpp-keyword">void</span> tgaFree ( image_t *p )<br>{<br>   <span class="cpp-keyword">if</span> ( p-&gt;data != NULL )<br> free ( p-&gt;data );<br>}<br><br><br><span class="cpp-keyword">void</span> tgaChecker ( image_t *p )<br>{<br>  <span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span> TGA_CHECKER[<span class="cpp-number">16384</span>];<br>  <span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span> *pointer;<br><br>  <span class="cpp-comment">// 8bit image</span><br>  p-&gt;info.image_type = <span class="cpp-number">3</span>;<br><br>  p-&gt;info.width  = <span class="cpp-number">128</span>;<br>  p-&gt;info.height = <span class="cpp-number">128</span>;<br><br>  p-&gt;info.pixel_depth = <span class="cpp-number">8</span>;<br><br>  <span class="cpp-comment">// Set some stats</span><br>  p-&gt;info.components = <span class="cpp-number">1</span>;<br>  p-&gt;info.bytes = p-&gt;info.width * p-&gt;info.height * p-&gt;info.components;<br><br>  pointer = TGA_CHECKER;<br><br>  <span class="cpp-keyword">for</span> ( <span class="cpp-keyword">int</span> j = <span class="cpp-number">0</span>; j &lt; <span class="cpp-number">128</span>; j++ )<br>  {<br>    <span class="cpp-keyword">for</span> ( <span class="cpp-keyword">int</span> i = <span class="cpp-number">0</span>; i &lt; <span class="cpp-number">128</span>; i++ )<br>    {<br> <span class="cpp-keyword">if</span> ((i ^ j) &amp; 0x10 )<br>   pointer[<span class="cpp-number">0</span>] = 0x00;<br> <span class="cpp-keyword">else</span><br>   pointer[<span class="cpp-number">0</span>] = 0xff;<br> pointer ++;<br>    }<br>  }<br><br>  p-&gt;data = TGA_CHECKER;<br><br>  glTexImage2D ( GL_TEXTURE_2D, <span class="cpp-number">0</span>, GL_LUMINANCE4, p-&gt;info.width,<br>  p-&gt;info.height, <span class="cpp-number">0</span>, GL_LUMINANCE, GL_UNSIGNED_BYTE, p-&gt;data );<br><br><span class="cpp-comment">/*  Should we free?  I dunno.  The scope of TGA_CHECKER _should_ be local, so it<br>    probably gets destroyed automatically when the function completes… */</span><br><span class="cpp-comment">//  tgaFree ( p );</span><br>}<br><br><br><span class="cpp-keyword">void</span> tgaError ( <span class="cpp-keyword">char</span> *error_string, <span class="cpp-keyword">char</span> *file_name, FILE *file, image_t *p )<br>{<br>   printf  ( <span class="cpp-literal">"%s - %s\n"</span>, error_string, file_name );<br>   tgaFree ( p );<br><br>   fclose ( file );<br><br>   tgaChecker ( p );<br>}<br><br><br><span class="cpp-keyword">void</span> tgaGetImageHeader ( FILE *file, tgaHeader_t *info )<br>{<br>   <span class="cpp-comment">/*   Stupid byte alignment means that we have to fread each field<br>   individually.  I tried splitting tgaHeader into 3 structures, no matter<br>   how you arrange them, colour_map_entry_size comes out as 2 bytes instead<br>   1 as it should be.  Grrr.  Gotta love optimising compilers - theres a pragma<br>   for Borland, but I dunno the number for MSVC or GCC :(<br>    */</span><br>   fread ( &amp;info-&gt;id_length,  ( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span> )), <span class="cpp-number">1</span>, file );<br>   fread ( &amp;info-&gt;colour_map_type, ( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span> )), <span class="cpp-number">1</span>, file );<br>   fread ( &amp;info-&gt;image_type, ( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span> )), <span class="cpp-number">1</span>, file );<br><br>   fread ( &amp;info-&gt;colour_map_first_entry, ( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">short</span> <span class="cpp-keyword">int</span> )), <span class="cpp-number">1</span>, file );<br>   fread ( &amp;info-&gt;colour_map_length, ( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">short</span> <span class="cpp-keyword">int</span> )), <span class="cpp-number">1</span>, file );<br>   fread ( &amp;info-&gt;colour_map_entry_size , ( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span> )), <span class="cpp-number">1</span>, file );<br><br>   fread ( &amp;info-&gt;x_origin , ( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">short</span> <span class="cpp-keyword">int</span> )), <span class="cpp-number">1</span>, file );<br>   fread ( &amp;info-&gt;y_origin , ( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">short</span> <span class="cpp-keyword">int</span> )), <span class="cpp-number">1</span>, file );<br>   fread ( &amp;info-&gt;width,( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">short</span> <span class="cpp-keyword">int</span> )), <span class="cpp-number">1</span>, file );<br>   fread ( &amp;info-&gt;height,    ( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">short</span> <span class="cpp-keyword">int</span> )), <span class="cpp-number">1</span>, file );<br><br>   fread ( &amp;info-&gt;pixel_depth,( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span> )), <span class="cpp-number">1</span>, file );<br>   fread ( &amp;info-&gt;image_descriptor,( <span class="cpp-keyword">sizeof</span> (<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span> )), <span class="cpp-number">1</span>, file );<br><br>   <span class="cpp-comment">// Set some stats</span><br>   info-&gt;components = info-&gt;pixel_depth / <span class="cpp-number">8</span>;<br>   info-&gt;bytes = info-&gt;width * info-&gt;height * info-&gt;components;<br>}<br><br><span class="cpp-keyword">int</span> tgaLoadTheImage ( <span class="cpp-keyword">char</span> *file_name, image_t *p, tgaFLAG mode )<br>{<br>   FILE   *file;<br><br>   tgaGetExtensions ( );<br><br>   p-&gt;data = NULL;<br><br>   <span class="cpp-keyword">if</span> (( file = fopen ( file_name, <span class="cpp-literal">"rb"</span> )) == NULL )<br>   {<br>   tgaError ( <span class="cpp-literal">"File not found"</span>, file_name, file, p );<br> <span class="cpp-keyword">return</span> <span class="cpp-number">0</span>;<br>   }<br><br>   tgaGetImageHeader ( file, &amp;p-&gt;info );<br><br>   <span class="cpp-keyword">switch</span> ( p-&gt;info.image_type )<br>   {<br> <span class="cpp-keyword">case</span> <span class="cpp-number">1</span> :<br>    tgaError ( <span class="cpp-literal">"8-bit colour no longer supported"</span>, file_name, file, p );<br>    <span class="cpp-keyword">return</span> <span class="cpp-number">0</span>;<br><br> <span class="cpp-keyword">case</span> <span class="cpp-number">2</span> :<br>    <span class="cpp-keyword">if</span> ( p-&gt;info.pixel_depth == <span class="cpp-number">24</span> )<br>  p-&gt;info.tgaColourType = GL_RGB;<br>    <span class="cpp-keyword">else</span> <span class="cpp-keyword">if</span> ( p-&gt;info.pixel_depth == <span class="cpp-number">32</span> )<br>  p-&gt;info.tgaColourType = GL_RGBA;<br><span class="cpp-keyword">else</span><br> {<br>    tgaError ( <span class="cpp-literal">"Unsupported RGB format"</span>, file_name, file, p );<br>    <span class="cpp-keyword">return</span> <span class="cpp-number">0</span>;<br>    }<br>    <span class="cpp-keyword">break</span>;<br><br> <span class="cpp-keyword">case</span> <span class="cpp-number">3</span> :<br>    <span class="cpp-keyword">if</span> ( mode&amp;TGA_LUMINANCE )<br>  p-&gt;info.tgaColourType = GL_LUMINANCE;<br>    <span class="cpp-keyword">else</span> <span class="cpp-keyword">if</span> ( mode&amp;TGA_ALPHA )<br>  p-&gt;info.tgaColourType = GL_ALPHA;<br> <span class="cpp-keyword">else</span><br> {<br>    tgaError ( <span class="cpp-literal">"Must be LUMINANCE or ALPHA greyscale"</span>, file_name, file, p );<br><span class="cpp-keyword">return</span> <span class="cpp-number">0</span>;<br>    }<br>    <span class="cpp-keyword">break</span>;<br><br> <span class="cpp-keyword">case</span> <span class="cpp-number">9</span> :<br>    tgaError ( <span class="cpp-literal">"8-bit colour no longer supported"</span>, file_name, file, p );<br>    <span class="cpp-keyword">return</span> <span class="cpp-number">0</span>;<br><br> <span class="cpp-keyword">case</span> <span class="cpp-number">10</span> :<br>    <span class="cpp-keyword">if</span> ( p-&gt;info.pixel_depth == <span class="cpp-number">24</span> )<br>  p-&gt;info.tgaColourType = GL_RGB;<br>    <span class="cpp-keyword">else</span> <span class="cpp-keyword">if</span> ( p-&gt;info.pixel_depth == <span class="cpp-number">32</span> )<br>  p-&gt;info.tgaColourType = GL_RGBA;<br>    <span class="cpp-keyword">else</span><br> {<br>    tgaError ( <span class="cpp-literal">"Unsupported compressed RGB format"</span>, file_name, file, p );<br>    <span class="cpp-keyword">return</span> <span class="cpp-number">0</span>;<br>    }<br>   }<br><br>   tgaGetImageData ( p, file );<br><br>   fclose  ( file );<br><br>   <span class="cpp-keyword">return</span> <span class="cpp-number">1</span>;<br>}<br><br><span class="cpp-keyword">void</span> tgaLoad ( <span class="cpp-keyword">char</span> *file_name, image_t *p, tgaFLAG mode )<br>{<br><span class="cpp-keyword">if</span> ( tgaLoadTheImage ( file_name, p, mode ))<br>   {<br>   <span class="cpp-keyword">if</span>  ( !( mode&amp;TGA_NO_PASS ))<br> tgaUploadImage  ( p, mode );<br><br>   <span class="cpp-keyword">if</span> ( mode&amp;TGA_FREE )<br>tgaFree ( p );<br>   }<br><br>}<br><br>GLuint tgaLoadAndBind ( <span class="cpp-keyword">char</span> *file_name, tgaFLAG mode )<br>{<br>   GLuint   texture_id;<br>   image_t  *p;<br><br>   glGenTextures ( <span class="cpp-number">1</span>, &amp;texture_id );<br>   glBindTexture ( GL_TEXTURE_2D, texture_id );<br><br>   <span class="cpp-keyword">if</span> ( tgaLoadTheImage ( file_name, p, mode ))<br>{<br>   tgaUploadImage  ( p, mode );<br>   tgaFree  ( p );<br>   }<br><br>   <span class="cpp-keyword">return</span> texture_id;<br>}<br><br><br><br><br><br><br></pre></div><!–ENDSCRIPT–><br><br><b>Part of the main code responsible for loading the texture:</b><br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><br><span class="cpp-directive">#define</span> MAX_NO_TEXTURES <span class="cpp-number">1</span><br><span class="cpp-directive">#define</span> TEXTURE_FPS <span class="cpp-number">0</span><br><span class="cpp-comment">// vector with the numbers of textures</span><br>GLuint texture_id[MAX_NO_TEXTURES];<br><br><span class="cpp-keyword">void</span> World::setup()<br>{<br><br>    <span class="cpp-comment">//===================================================================</span><br>    <span class="cpp-comment">// Load Texture</span><br>    <span class="cpp-comment">//===================================================================</span><br>image_t temp_image; <span class="cpp-comment">// variable that will store the texture to be used</span><br><br><span class="cpp-comment">// Enables the use of texture</span><br>glEnable ( GL_TEXTURE_2D );<br><br><span class="cpp-comment">// Defines how to store the pixels in texture (1 = byte-alignment)</span><br>glPixelStorei ( GL_UNPACK_ALIGNMENT, <span class="cpp-number">1</span> );<br><br><span class="cpp-comment">// Define quantas texturas serão usadas no programa</span><br>glGenTextures (<span class="cpp-number">1</span>, texture_id);  <span class="cpp-comment">// 1 = one texture</span><br><span class="cpp-comment">// texture_id = vector that guards the numbers of textures</span><br><br><span class="cpp-comment">//Sets the numbers of the texture</span><br>texture_id[TEXTURE_FPS] = <span class="cpp-number">1</span>;<br><br><span class="cpp-comment">// ****</span><br><span class="cpp-comment">// Sets the texture</span><br><span class="cpp-comment">// ****</span><br><br><span class="cpp-comment">// Defines what type of texture will be used</span><br><span class="cpp-comment">// GL_TEXTURE_2D ==&gt; that defines a 2D texture is used (bitmaps)</span><br><span class="cpp-comment">// texture_id[TEXTURE_FPS]  ==&gt; define the number of texture</span><br>glBindTexture ( GL_TEXTURE_2D, texture_id[TEXTURE_FPS] );<br><span class="cpp-comment">// Load the image .TGA</span><br>tgaLoad  ( <span class="cpp-literal">"fps.tga"</span>, &amp;temp_image, TGA_FREE | TGA_LOW_QUALITY );<br><br>}<br><br><br><br><br></pre></div><!–ENDSCRIPT–><br><br>main game loop:<br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre>    <span class="cpp-keyword">try</span><br>    {<br>   game-&gt;setup(); <span class="cpp-comment">//Here init texture</span><br>   <span class="cpp-keyword">while</span> (!game-&gt;ended())<br>   {<br><br>  processEvents(game);<br>  game-&gt;processLogics();<br>  game-&gt;draw();<br><br>  SDL_GL_SwapBuffers();<br><br>   }<br><br>    }<br><br><br><br><br></pre></div><!–ENDSCRIPT–><br><br>The texture should be applied when it was called:<br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre>glBindTexture ( GL_TEXTURE_2D, <span class="cpp-number">1</span> ); <span class="cpp-comment">// define texture 1 to use</span><br><br><br><br><br></pre></div><!–ENDSCRIPT–><br><br>Exemple:<br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre>    <span class="cpp-comment">//</span><br>    <span class="cpp-comment">// Polygon</span><br>    <span class="cpp-comment">//</span><br>glPushMatrix();<br>   glScalef(<span class="cpp-number">0</span>.<span class="cpp-number">1</span>,<span class="cpp-number">0</span>.<span class="cpp-number">2</span>,<span class="cpp-number">0</span>.<span class="cpp-number">0</span>);<br>   glColor3f(<span class="cpp-number">1</span>.<span class="cpp-number">0</span>,<span class="cpp-number">1</span>.<span class="cpp-number">0</span>,<span class="cpp-number">1</span>.<span class="cpp-number">0</span>);<br>   glBindTexture ( GL_TEXTURE_2D, <span class="cpp-number">1</span> ); <span class="cpp-comment">// HERE!! define texture 1 to use</span><br>   glBegin(GL_QUADS);<span class="cpp-comment">// Draw A Quad</span><br>    glTexCoord2f(<span class="cpp-number">0</span>.0f, <span class="cpp-number">1</span>.0f); glVertex3f(-<span class="cpp-number">1</span>.0f, <span class="cpp-number">1</span>.0f, <span class="cpp-number">0</span>.0f);<span class="cpp-comment">// Top Left</span><br>    glTexCoord2f(<span class="cpp-number">1</span>.0f, <span class="cpp-number">1</span>.0f); glVertex3f( <span class="cpp-number">1</span>.0f, <span class="cpp-number">1</span>.0f, <span class="cpp-number">0</span>.0f);<span class="cpp-comment">// Top Right</span><br>    glTexCoord2f(<span class="cpp-number">1</span>.0f, <span class="cpp-number">0</span>.0f); glVertex3f( <span class="cpp-number">1</span>.0f,-<span class="cpp-number">1</span>.0f, <span class="cpp-number">0</span>.0f);<span class="cpp-comment">// Bottom Right</span><br>    glTexCoord2f(<span class="cpp-number">0</span>.0f, <span class="cpp-number">0</span>.0f); glVertex3f(-<span class="cpp-number">1</span>.0f,-<span class="cpp-number">1</span>.0f, <span class="cpp-number">0</span>.0f);<span class="cpp-comment">// Bottom Left</span><br>   glEnd();<span class="cpp-comment">// Done Drawing The Quad</span><br>    glPopMatrix();<br><br><br><br><br></pre></div><!–ENDSCRIPT–><br><br>But even without calling the function to apply the texture, it is applied to it and leaving the other strange polygons<br><br> <br>Only the polygon in the middle of the screen that should receive the texture<br><img src="http://img37.imageshack.us/img37/7727/antesq.png" alt="After" /> <br><br>If I remove the code that loads the texture, it back to normal<br><br><img src="http://img714.imageshack.us/img714/6517/depoisp.png" alt="Normal" /> <br><br>Thus we note that there was a change in all polygons drawn &#111;n the screen (which should not happen)<br><br>Thanks!
  openGL is a state machine. There's no such thing as applying texture.You enable texturing, thus everything (points, lines, quads, everything) will be textured.If you disable texturing, nothing will be textured.If you bind a texture (what you refer as "applying") that texture will be active: that particular texture will be "applied" to everything, until another texture is bound. So if you have only one texture, you don't have to bind it over and over again.Texture settings (every settings) apply to the currently bound texture.This state machine thing applies to pretty much everything in openGL. Texture coordinates too. So texture coordinates are always valid, and the values are always the values set last time. That's why you have to call it before the glVertex calls.The same applies to color, blending, fog, almost everything.I hope that helps.   ;  Thanks szecs, I understand your explanation.In short, I will not be able to apply the texture only to a polygon?Leaving the rest without texture?Sorry for the stubbornness :)ThanksI looked at your videos on youtube, great job! congratulations!Regarding the "Tank simulator openGL demo III" as you did to show the fps onscreen?I have an fps counter, but do not know how to show it. I'm using Opengl (and SDL for window-manager and control of events)   ;  Um.., you haven't understood the explanation...Maybe this:"openGL is a state machine. There's no such thing as applying texture.You enable texturing, thus everything (points, lines, quads, everything) will be textured."Is a bit fishy. Sorry, I'm not a native speaker, and I1m sleepy, I can't express it better...glEnable(GL_TEXTURE_2D);draw_that_you_want_to_be_textured();glDisable(GL_TEXTURE_2D);draw_untextured_stuff();Thanks for you comment on the demos.FPS counter: look into "render text" or "render fonts" it's a pretty commonly asked question here.   ;  szecs thanks!As for your demo, it is very professional! I hope to get there someday![Edited by - VitaliBR on July 8, 2010 9:04:06 PM];Quote:Original post by VitaliBRszecs thanks!as you can not see? lolsorry!As for your demo, it is very professional! I hope to get there someday!HugsUm... What?There's nothing to hope on it. It's a pretty demo, and pretty useless (it's not a big deal to throw some effects and physics, I never did the real and hard stuff). You will get there probably soon.   ;Quote:Original post by szecsQuote:Original post by VitaliBRszecs thanks!as you can not see? lolsorry!As for your demo, it is very professional! I hope to get there someday!HugsUm... What?There's nothing to hope on it. It's a pretty demo, and pretty useless (it's not a big deal to throw some effects and physics, I never did the real and hard stuff). You will get there probably soon.Okay, I'm gone to sleep [grin]   ;  #define TGA_DEFAULT  0x0000000000000000   /* In case we don't want any parameters */#define TGA_FREE0x0000000000000001   /* Bit flag 0 */#define TGA_NO_PASS  0x0000000000000010   /* Bit flag 1 */#define TGA_ALPHA    0x0000000000000100   /* Bit flag 2 */These defines are not correct. You don't address single bits because it's a hexadecimal formatting. That means 0x0000000000000010 is not bit 1, it's bit 5.Use (1<<0), (1<<1), (1<<2) etc. to address bits.   ;Quote:Original post by Clausomat#define TGA_DEFAULT  0x0000000000000000   /* In case we don't want any parameters */#define TGA_FREE0x0000000000000001   /* Bit flag 0 */#define TGA_NO_PASS  0x0000000000000010   /* Bit flag 1 */#define TGA_ALPHA    0x0000000000000100   /* Bit flag 2 */These defines are not correct. You don't address single bits because it's a hexadecimal formatting. That means 0x0000000000000010 is not bit 1, it's bit 5.Use (1<<0), (1<<1), (1<<2) etc. to address bits.Sorry, I didn't understandThanks szecs, I solved the problem :Dhow to show FPS on screen, I found an interesting GLFT_font lib. if someone already used it and can tell if it's goodEDIT: I link the librarie FreeType in my project to use the GLFT, But at compile, appears the following errors:D:\...\GLFT_Font.cpp||In member function 'void GLFT_Font::open(const std::string&, unsigned int)':|D:\...\GLFT_Font.cpp|165|error: 'memset' is not a member of 'std'|D:\...\GLFT_Font.cpp||In member function 'void GLFT_Font::drawText(float, float, const char*, ...) const':|D:\...\GLFT_Font.cpp|270|error: 'vsnprintf' is not a member of 'std'|D:\...\GLFT_Font.cpp|276|error: 'strlen' is not a member of 'std'|||=== Build finished: 3 errors, 0 warnings ===| [Edited by - VitaliBR on July 8, 2010 8:37:22 PM];  To be honest, I don't understand Clausomat either.Start a new thread with fonts. I use the NEHE method. Look NEHE up.   