I have been writing a game which involves a ball moving around in a scene (which is renderd using OGL, not just a big texturemapped thing), up untill now I have been using a specific texture un the ball, but I would like to use environment mapping instead, to create a silvery ball. I have found out how to do this, providing the texture is provided, but I cannot work out how to generate a texture for the ball from the surrounding scene.
Any help would be much appreciated. Thanks.
If you want ‘true’ reflections of the surrounding scene, you are are in some trouble. This isn’t easy. But it can be done. You can take a ‘screen shot’ of the scene as it looks like as seen from the ball. I.e., place the viewpoint at the center of the sphere, direct the viewpoint towards the user, make a very wide field of view, and render the scene as normal (but NOT the sphere, since you are inside the sphere, it might occlude the whole scene), grab the backbuffer and make a texture out of it, and then use this texture as the enviroment texture.
It’s might sound complicated, I know, but ‘true’ reflections like this isn’t an easy task.
As soon as something changes (object or camera moves), you need to rebuild the texture.
If you use the cube environemnt mapping, you need to make all six textures, and update them only when the scene moves, not the camera. Or to make it slightly faster, only update the textures that is potentially visible from the current angle of view.
Mmm, hope I was clear enough on this one, else shout…
p.s. Forgot to mention it in my first version of my post, but I assumed that you are using sphere mapping in my first solution. And secondly, with the six cube textures, you should use a 90 degree field of view when rendering the textures.
[This message has been edited by Bob (edited 12-12-2000).]
What FOV angles are good for sphere mapping?
Dunno really, but I think ‘as large as possible’. Try with some large fov, like 170 or so. Haven’t tried this idea yet, so don’t even know if it works.
If someone tries, or already tried, please report your results
I got the basic idea but how do we take the back buffer and convert it to a texture, i mean the open GL commands, i have been playing aroud with this and iam all strung about, maybe you could help by posting a piece of code,
Use glReadPixels to grab the pixel data in the backbuffer for use in a texture. Might need to do some resizing after you read some pixels or else make sure you read an area so that the final results end up being dimensions that are a power of two. (e.g. 256x256, 512x256, 1024x512, etc.)
Hmm… okay now i know the logic of what to do, would you guide me as to where i can find te syntax of these commands, i mean i thought of using glTexImage2D to grab image and the glGetTexImage to grab and put it as a texture, suppose iam using two buffers, glReadPixels is going to read the pixels and put them as a texture and then i use getTex for converting this to texture map and use it… iam not sure if what iam saying is making sense, but what i really need is some sample code for the usage of these functions…
thanks for the help, itrealy helped.
Use glReadPixels to grab the pixel data in the backbuffer for use in a texture. Might need to do some resizing after you read some pixels or else make sure you read an area so that the final results end up being dimensions that are a power of two. (e.g. 256x256, 512x256, 1024x512, etc.)[/QUOTE]