   Image Troubles
  Hi, I seem to be experiencing some very weird problems when I load an image.I am rendering some squares to the screen like:glBegin(GL_QUADS);// Draw Our QuadglTexCoord2f(0.0f, 1.0f); glVertex3f(-10.0f,  10.0f, 0.0f);glTexCoord2f(1.0f, 1.0f); glVertex3f( 10.0f,  10.0f, 0.0f);glTexCoord2f(1.0f, 0.0f); glVertex3f( 10.0f, -10.0f, 0.0f);glTexCoord2f(0.0f, 0.0f); glVertex3f(-10.0f, -10.0f, 0.0f);glEnd();And since I do not have an image bound it appears as a white square.  All good.  However when I try to load an image 1 of 2 things happens.  I of course bind the image first....1) When I load the image as a gluBuild2DMipmaps nothing gets rendered to the screen its just the clear color black (i've also tested it with a clear color of red) but the same as before nothing appears to be rendered2) If i try to load it as a glTexImage2D no images appears just the white squares do, just as if I did not bind a texture.Nothing else in my code has changed except those two lines of code.  I have no idea what is wrong since I pretty much used the exact same code as the tutorial for loading a TGA and it worked perfect.   
Quote:Original post by starfleetrp2) If i try to load it as a glTexImage2D no images appears just the white squares do, just as if I did not bind a texture.You can try:1) Check if the image is power-of-two2) Post your glTexImage2D call and your source image's data type   ;  glTexImage2D (GL_TEXTURE_2D, 0, texture->channels, texture->sizeX, texture->sizeY, 0, textureType, GL_UNSIGNED_BYTE, texture->data);The image is a TGA and I cant check if its to the power of 2 since I can not make/read them.  However it is the same image as from the tutorial.   ;Quote:Original post by starfleetrpglTexImage2D (GL_TEXTURE_2D, 0, texture->channels, texture->sizeX, texture->sizeY, 0, textureType, GL_UNSIGNED_BYTE, texture->data);The image is a TGA and I cant check if its to the power of 2 since I can not make/read them.You are passing the dimensions right there in your glTexImage2D call.  Throw in a break point and check the values.Quote:Original post by starfleetrpHowever it is the same image as from the tutorial.There are (too) many tutorials out there.  Which one are you talking about?It would also help to see all of your texture creation code and possibly your whole rendering loop.   ;  Here is my texture creation/usage class its kinda hacked together for now :(#include "StdAfx.h"#include ".\textureresource.h"#include "Prerefequites.h"#include "Log.h"TextureResource::TextureResource(void) : textureBound(false),resourceID(0),Resources(){mType = RESOURCE_TEXTURE;}//------------------------------------------------------------------------------------TextureResource::~TextureResource(void){_clear();}//------------------------------------------------------------------------------------bool TextureResource::load(const std::string& name){std::string extension;Texture *texture = NULL;if (textureBound){// This resource is already in useLog::GetSingleton().addRecord("Texture resource already has a texture <b>" + mName + "</b> bound to it.  You were trying to bind: <b>" + name + "</b>", LOG_ERROR);return false;}if ( name.length() <= 4 ){// File name is too short or was not entered// Needs to be atleast 5 characters in length "a.tga"Log::GetSingleton().addRecord("Texture resource can not load a file that has a name less that 5 characters.  You were trying to load: <b>" + name + "</b>", LOG_ERROR);return false;}// Get the extension of the file (last 3 characters)extension = name.substr(name.length() - 3);//Load the imageif (extension == "tga"){texture = loadTGA(name);}else{// Invalid file extensionLog::GetSingleton().addRecord("Could not load texture: Unknown extention.  You were trying to load: <b>" + name + "</b>", LOG_ERROR);return false;}if(texture == NULL){Log::GetSingleton().addRecord("Could not load texture.  You were trying to load: <b>" + name + "</b>", LOG_ERROR);return false;}// Add texture to video memoryglGenTextures(1, &resourceID);glBindTexture(GL_TEXTURE_2D, resourceID);int textureType = GL_RGB;if(texture->channels == 4)textureType = GL_RGBA;//GLenum errCode = gluBuild2DMipmaps(GL_TEXTURE_2D, texture->channels, texture->sizeX, texture->sizeY, textureType, GL_UNSIGNED_BYTE, texture->data);glTexImage2D (GL_TEXTURE_2D, 0, texture->channels, texture->sizeX, texture->sizeY, 0, textureType, GL_UNSIGNED_BYTE, texture->data);/*if (errCode != 0){//Log::GetSingletonPtr()->addRecord(gluErrorString(errCode), LOG_ERROR);Log::GetSingletonPtr()->addRecord("gluBuild2DMipmaps error - TextureResource.cpp", LOG_ERROR);//MessageBox(NULL,"glBuild2dMipmaps error","",MB_OK);}*/glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);if (texture){if (texture->data){free(texture->data);}free(texture);}Log::GetSingleton().addRecord("Texture loaded. <b>" + name + "</b>", LOG_SUCCESS);textureBound = true;mName = name;return true;}//------------------------------------------------------------------------------------Texture* TextureResource::loadTGA(const std::string& name){// From APRON tutorial - replace at later date if need arisesTexture *texture= NULL;FILE *pFile= NULL;unsigned short width= 0;unsigned short height= 0;byte length= 0;byte imgType= 0;byte bits= 0;int channels= 0;int stride= 0;int i= 0;if((pFile = fopen(name.c_str(), "rb")) == NULL) {//MessageBox(NULL, "Error loading tga file.", "ERROR", MB_OK);Log::GetSingleton().addRecord("Error loading TGA. File not found: <b>" + name + "</b>", LOG_ERROR);return NULL;}texture = (Texture*)malloc(sizeof(Texture));fread(&length, sizeof(byte), 1, pFile);fseek(pFile,1,SEEK_CUR); fread(&imgType, sizeof(byte), 1, pFile);fseek(pFile, 9, SEEK_CUR); fread(&width,  sizeof(WORD), 1, pFile);fread(&height, sizeof(WORD), 1, pFile);fread(&bits,   sizeof(byte), 1, pFile);fseek(pFile, length + 1, SEEK_CUR); if(imgType != TGA_RLE){// Check for 24 or 32 Bitif(bits == 24 || bits == 32){channels = bits / 8;stride = channels * width;texture->data = new unsigned char[stride * height];for(int y = 0; y < height; y++){unsigned char *pLine = &(texture->data[stride * y]);fread(pLine, stride, 1, pFile);for(i = 0; i < stride; i += channels){int temp= pLine;pLine= pLine;<br>pLine = temp;<br>}<br>}<br>}<br><br><span class="cpp-comment">// Check for 16 Bit</span><br><span class="cpp-keyword">else</span> <span class="cpp-keyword">if</span>(bits == <span class="cpp-number">16</span>)<br>{<br><span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">short</span> pixels = <span class="cpp-number">0</span>;<br><span class="cpp-keyword">int</span> r=<span class="cpp-number">0</span>, g=<span class="cpp-number">0</span>, b=<span class="cpp-number">0</span>;<br><br>channels = <span class="cpp-number">3</span>;<br>stride = channels * width;<br>texture-&gt;data = <span class="cpp-keyword">new</span> <span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span>[stride * height];<br><br><span class="cpp-keyword">for</span>(<span class="cpp-keyword">int</span> i = <span class="cpp-number">0</span>; i &lt; width*height; i++)<br>{<br>fread(&amp;pixels, <span class="cpp-keyword">sizeof</span>(<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">short</span>), <span class="cpp-number">1</span>, pFile);<br><br>b = (pixels &amp; 0x1f) &lt;&lt; <span class="cpp-number">3</span>;<br>g = ((pixels &gt;&gt; <span class="cpp-number">5</span>) &amp; 0x1f) &lt;&lt; <span class="cpp-number">3</span>;<br>r = ((pixels &gt;&gt; <span class="cpp-number">10</span>) &amp; 0x1f) &lt;&lt; <span class="cpp-number">3</span>;<br><br>texture-&gt;data = r;<br>texture-&gt;data = g;<br>texture-&gt;data = b;<br>}<br>}<br><br><span class="cpp-keyword">else</span><br><span class="cpp-keyword">return</span> NULL;<br>}<br><br><span class="cpp-keyword">else</span><br>{<br><br>byte rleID = <span class="cpp-number">0</span>;<br><span class="cpp-keyword">int</span> colorsRead = <span class="cpp-number">0</span>;<br>channels = bits / <span class="cpp-number">8</span>;<br>stride = channels * width;<br><br>texture-&gt;data = <span class="cpp-keyword">new</span> <span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span>[stride * height];<br>byte *pColors = <span class="cpp-keyword">new</span> byte [channels];<br><br><span class="cpp-keyword">while</span>(i &lt; width*height)<br>{<br><br>fread(&amp;rleID, <span class="cpp-keyword">sizeof</span>(byte), <span class="cpp-number">1</span>, pFile);<br><br><br><span class="cpp-keyword">if</span>(rleID &lt; <span class="cpp-number">128</span>)<br>{<br>rleID++;<br><br><span class="cpp-keyword">while</span>(rleID)<br>{<br>fread(pColors, <span class="cpp-keyword">sizeof</span>(byte) * channels, <span class="cpp-number">1</span>, pFile);<br><br>texture-&gt;data[colorsRead + <span class="cpp-number">0</span>] = pColors[<span class="cpp-number">2</span>];<br>texture-&gt;data[colorsRead + <span class="cpp-number">1</span>] = pColors[<span class="cpp-number">1</span>];<br>texture-&gt;data[colorsRead + <span class="cpp-number">2</span>] = pColors[<span class="cpp-number">0</span>];<br><br><span class="cpp-keyword">if</span>(bits == <span class="cpp-number">32</span>)texture-&gt;data[colorsRead + <span class="cpp-number">3</span>] = pColors[<span class="cpp-number">3</span>];<br><br>i++;<br>rleID–;<br>colorsRead += channels;<br>}<br>}<br><br><span class="cpp-keyword">else</span><br>{<br>rleID -= <span class="cpp-number">127</span>;<br><br>fread(pColors, <span class="cpp-keyword">sizeof</span>(byte) * channels, <span class="cpp-number">1</span>, pFile);<br><br><span class="cpp-keyword">while</span>(rleID)<br>{<br>texture-&gt;data[colorsRead + <span class="cpp-number">0</span>] = pColors[<span class="cpp-number">2</span>];<br>texture-&gt;data[colorsRead + <span class="cpp-number">1</span>] = pColors[<span class="cpp-number">1</span>];<br>texture-&gt;data[colorsRead + <span class="cpp-number">2</span>] = pColors[<span class="cpp-number">0</span>];<br><br><span class="cpp-keyword">if</span>(bits == <span class="cpp-number">32</span>)texture-&gt;data[colorsRead + <span class="cpp-number">3</span>] = pColors[<span class="cpp-number">3</span>];<br><br>i++;<br>rleID–;<br>colorsRead += channels;<br>}<br>}<br>}<br><span class="cpp-keyword">delete</span>[] pColors;<br>}<br><br>fclose(pFile);<br><br><br>texture-&gt;channels  = channels;<br>texture-&gt;sizeX= width;<br>texture-&gt;sizeY= height;<br><br><span class="cpp-keyword">return</span> texture;<br>}<br><span class="cpp-comment">//————————————————————————————</span><br><span class="cpp-keyword">void</span> TextureResource::_clear()<br>{<br><span class="cpp-keyword">if</span> (textureBound)<br>{<br><span class="cpp-comment">// Remove this texture from video memory</span><br>glDeleteTextures(<span class="cpp-number">1</span>, &amp;resourceID);<br><br>Log::GetSingleton().addRecord(<span class="cpp-literal">"Unloaed texture &lt;b&gt;"</span> + mName + <span class="cpp-literal">"&lt;/b&gt;"</span>, LOG_SUCCESS);<br>}<br>textureBound = <span class="cpp-keyword">false</span>;<br>}<br><span class="cpp-comment">//————————————————————————————</span><br><span class="cpp-keyword">void</span> TextureResource::render()<br>{<br><span class="cpp-comment">// Change to our texture so it can be rendered</span><br>glBindTexture(GL_TEXTURE_2D, resourceID);<span class="cpp-comment">// ( CHANGE )</span><br><span class="cpp-keyword">if</span>(resourceID == <span class="cpp-number">0</span>)<br>Log::GetSingleton().addRecord(<span class="cpp-literal">"Tried to call TextureResource::render() when not resourceID was defined."</span>, LOG_ERROR);<br>}<br><br></pre></div><!–ENDSCRIPT–><br><br>I beleive that it was based off of the apron tutorials (I forget since I looked at a few but im almost 90% sure)<br><br>Now my rendering loop is pretty much<br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><br>(*test_tga)-&gt;render(); <span class="cpp-comment">// Binds the texture</span><br><span class="cpp-keyword">for</span> (each node) <span class="cpp-comment">// Calls node::render or something like that for testing which does the below</span><br>{<br>glLoadIdentity();<br>glTranslatef(mDerivedPosition.x, mDerivedPosition.y,-<span class="cpp-number">500</span>);<span class="cpp-comment">// mDerivedPosition.z);</span><br>glRotatef(angle, axis.x, axis.y, axis.z);<br>ResourceManager::GetSingleton().getResource(<span class="cpp-literal">"images\\test.tga"</span>)-&gt;render();<br>glBegin(GL_QUADS);<span class="cpp-comment">// Draw Our Quad</span><br>glTexCoord2f(<span class="cpp-number">0</span>.0f, <span class="cpp-number">1</span>.0f); glVertex3f(-<span class="cpp-number">10</span>.0f,  <span class="cpp-number">10</span>.0f, <span class="cpp-number">0</span>.0f);<br>glTexCoord2f(<span class="cpp-number">1</span>.0f, <span class="cpp-number">1</span>.0f); glVertex3f( <span class="cpp-number">10</span>.0f,  <span class="cpp-number">10</span>.0f, <span class="cpp-number">0</span>.0f);<br>glTexCoord2f(<span class="cpp-number">1</span>.0f, <span class="cpp-number">0</span>.0f); glVertex3f( <span class="cpp-number">10</span>.0f, -<span class="cpp-number">10</span>.0f, <span class="cpp-number">0</span>.0f);<br>glTexCoord2f(<span class="cpp-number">0</span>.0f, <span class="cpp-number">0</span>.0f); glVertex3f(-<span class="cpp-number">10</span>.0f, -<span class="cpp-number">10</span>.0f, <span class="cpp-number">0</span>.0f);<br>glEnd();<br>}<br><br></pre></div><!–ENDSCRIPT–><br>;  Okay, I noticed a couple things that might be problematic.Quote:glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);The magnification filter can't accept any mipmapping filter types, so use either GL_NEAREST or GL_LINEAR for that.  The minification filter should only use a mipmapping filter type if you are using mipmaps (creating the entire mipmap chain).  So if you use gluBuild2DMipmaps (which creates the mipmap chain for you) you should use one of the GL_*_MIPMAP_* filter types but if you use glTexImage2D to create just the 0th level of the mipmap chain (ie: no mipmapping), you have to use GL_NEAREST or GL_LINEAR.The other thing is I don't see you enabling texturing anywhere (although I may have overlooked it).  Make sure that it is enabled when you want to render with texturing and disabled when you want to render without texturing.   ;  Ok I am now experiencing a different problem.  Now nothing appears on the screen, not even the white squares.  glEnable(GL_TEXTURE_2D); is in my initGl() section.The only thing that I have changed is:Quote:glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);to Quote:glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);