(static) Background image in Open GL

I'm slowly making my little game working
Now I'm trying to us a simple 480x320 (i'm in landscape) shape textured with a 480x320 image as the background.
It seems that the iphone want texture dimensions to be square & power of 2.

Allright... but what is the proper, simple, clean and easy way to display static image in the background then?

I know I could make my Open GL layer transparent and set another layer with the background image, but I can feel people going "bad bad bad".

Easy, use a 512*512 texture, and paste it to a square, after render that square, render or update your scene graph, so the square will not be affected by opengl transformations.

If you are using a orthographic camera, it is easy to calculate your square dimensions and position (put it far), however, if you are going to use perspective camera, you have to put your square just in over the far plane, so use tangent and fov angle to calculate its coordinates.

Definitely not necessary, but if you're short on RAM and need to find some then it's an idea. The slight performance hit comes from the fact that you have to draw eight different textures for your background instead of just one.

The best idea would be to use 512 x 512 PVRTC if you can accept the quality.

riruilo Wrote:...however, if you are going to use perspective camera, you have to put your square just in over the far plane, so use tangent and fov angle to calculate its coordinates.

Simply use an ortho camera for the background and then switch to perspective afterwards. No sense in sizing it to fit in perspective when you don't have to.

Also, in ortho, no need to use depth testing for a background image, since everything else in the scene will logically be drawn on top of it.

512x512. It's the smallest, power-of-two texture you can make (square or not) that will fit a full resolution iPhone screen background in.

What I did was simply draw a fullscreen textured quad and adjusted the texture coordinates. I placed my 320x480 image in the top left corner of a 512x512 texture and then used 320.0f/512.0f as the maximum U texture coordinate and (480.0f/512.0f) as the maximum V texture coordinate. I lose out on some wasted memory, but the rendering is fairly straightforward.

AnotherJake Wrote:The original poster did:
If you want to save some memory (at the expense of a small performance hit) you can store a 480 x 320 image to use up exact memory by slicing it into 8 POT texture slices:

riruilo Wrote:Yes, I didn't try it but powervr docs say is not a good idea to use more textures than required or binds.

Yes, you want to avoid extra binds for performance' sake, but it is also very important to save memory on iPhone. There are trade-offs to all the approaches, as I listed. Use whichever one fits your situation.

riruilo Wrote:I agree with you, but that is a bit difficult if you are a beginner.

Not really. If you can load a texture and bind it, which is as basic as it gets, then you know all you need. It is only very slightly more difficult if you slice it on load, but you can slice it in Photoshop as eight separate textures to load from disk instead.

The 512 x 512 uncompressed approach is arguably the most *intuitive*, if that's what you're looking for, but none of the other approaches are any more *difficult* in practice. I would say, if you have lots of memory to spare, just use the uncompressed 512 x 512 approach at first. But if you're looking to save some memory, look at the others.