# how to apply a texture to a 3d scene background?

i don't really know the exact term for that (i thought it was hdr but no...).

i want to put a texture as a background in opengl-es , and when we rotate the view , the background rotate too (obviously) but when there is translation , the background doesn't change.

like if i was inside a sphere and the texture are stick to it.

(and i don't think the sphere idea is the best way to do it).

I have certainly not explained the problem correctly , I'm sorry for that and thanks a lot if you understand me (even more if you have the answer :p)

There are three ways to do this:

• Sky box
• Sky dome
• Sky plane

With a sky box, you have a giant box that is surrounding your scene. This will make it seem as if you are in a 'box'. With a sky dome, you have the same box, but this time the projection of the texture onto the cube is spherical. Problem with this technique is that the projection does not cover the bottom of the cube (which is not a problem in most cases). You can also go with a literal dome, that is, a sphere (which Kromster suggested), although it comes with its own share of problems (pinch points). Then there is the sky plane where only one (very large) plane is rendered. The drawback here is that you will see the horizon, so you can only use this technique in closed areas.

As for keeping the sky where it is when you move etc. Kromster suggestion is correct. You will want to, however, make sure that all your objects are rendered on top of the sky. This is very easy to do, simply render your sky first, then without swapping buffers, render your scene.

NOTE: All the sky types have their polygon normals inverted. So if you have a box or a sphere mesh, invert the normals otherwise you will not see anything.

• in my case i will render a space environment (only stars and eventually some planet sometimes , so i guess sphere will be ok concerning the pinch points. But i'll test first box , the less polygon there is , the better it is. Now i just need to dig inside texture mapping that i didn't try to learn yet ! Thanks for the advices – eephyne Nov 26 '10 at 9:10

I guess you mean some sort of a environment map, skybox, environment sphere, cubemap.

Simplest way would be to make a big low-poly sphere (or a segment of it, depending on view area restrictions), face its polygons inside and attach to camera position, so wherever your camera is going the sphere will remain around it. And map texture to this sphere.

• i just look for skybox and yes that exactly what i'm looking for. Does a skybox is sufficient of it's better to take a sphere? – eephyne Nov 25 '10 at 15:32
• Try and see how it looks, if the lightning and perspective distortions are ok - use a box. If you notice texture disproportions - switch to a sphere. It depends on how much freedom you/player have over camera rotation. Obviously if you restricted to look up/down you don't need to create/render upper/lower parts of the sphere. If you can look only left-right you can have a"ring" instead of sphere. And finally - don't forget to disable lighting and enable normals smoothing (so that there were no lighting flaws on polygon edges of a box/sphere) – Krom Nov 26 '10 at 6:25