Why won't my texture display?

Hi. I have some OpenGL code that displays characters stored within a TGA file on my PC and Mac which I have tried to get working with OpenGLES in the iPhone simulator. Instead of displaying a character, I just end up with an opaque square.

At first I thought it must be my TGA loading code thats not working but I have since confirmed with the debugger that the memory contents of the read file are the same as the hexdump of the TGA file on the Mac - so its loading OK I would say.

I'm running a 2D Ortho view - I can happily draw triangles, rectangles etc on the screen - I just can't get my font display function to work. Here's a stripped down version. Can anybody see whats wrong? Is there something special I need to do on the iPhone (and simulator) to get this to work?

(Apr 7, 2011 01:40 PM)OneSadCookie Wrote: You didn't paste the code that calls glGenTextures/glTexImage2D. Why are you calling glTextureParameteri each frame rather than when you create the texture object?

Hi Cookie. You'll noticed that some lines of code are not indented.. I became desperate trying to get this to work lastnight so I started copying and pasting GL function calls from other tutorials' examples etc. When using OpenGL on the Mac/PC, I never had the calls to glTextureParameter().

I also know there's massive room for optimisation in my code, but keep in mind that I'm still on the learning path and this code isn't for a cutting-edge game. :-)

The missing bits of code are below.. I can't remember where I grabbed the tga.cpp code from but its what I've been using - I see it makes the
glTextureParameter calls you mention.

I'd send you a complete Xcode project if I could but I'm at work at the moment.. and won't be home this evening.. I'd like to keep this open for other people to learn from, but PM me if you'd like me to ZIP up my project and send it to you when I can).

glGenTextures( NUM_TEXTURES, Texture );

LoadTexture("Paul1Fon8x9.tga",Texture[0]);

Code:

tga.cpp (Windows version copied below - I only changed the header files to get it working on the iPhone):

// VGA palette is the 768 bytes following the header
memcpy(pPalette,&pData[pData[0]+18],768);

// Palette entries are BGR ordered so we have to convert to RGB
for(iIndex=0,iPalPtr=0;iIndex!=256;++iIndex,iPalPtr+=3)
{
bTemp=pPalette[iPalPtr]; // Get Blue value
pPalette[iPalPtr]=pPalette[iPalPtr+2]; // Copy Red to Blue
pPalette[iPalPtr+2]=bTemp; // Replace Blue at the end
}

Woohoo! You're the best! It works! :-) I changed both 3 & 4 values in the glTexImage2D() function to GL_RGBA and its working. I'll go read up on what the change actually did when I can face another night of programming. Now I can get on porting the rest of my program.. but by the looks of things its probably best I have a night off.