I have an object with a camera pointed at it. I want to move the camera to the object’s location, point it at the old camera position, render the image into a buffer for use as a texture, and then put the camera back where it was. Can someone give help me out with the specifics? For example, how can I store the first cam position so that it’ll know where to point, and where to return to? How do I select a certain buffer to render to, which one should I use, and how can I turn it into something I can make a texture from? (I know how to load a texture from an RGB file, but this is a little complicated for me.) I’d really appreciate any help, cause I can’t seem to get started.
Matrix can be easily stored with glPushMatrix, looking to an object - by gluLookAt. You can obtain camera location from matrix(four “bottom” values are 4d vector).
As for buffers… It seems to me that there are no buffers except front and back in Macrohard implementation. Try glDrawBuffer with aux buffer, but it will not work probably. So better render to backbuffer as usual and then clear it again.
You can obtain texture by glReadPixels - it will be in needed format. But it is not very fast.
Are you creating smth like mirror?
Yeah, it’s for a mirror. So what’s the syntax for pulling values out of the modelview matrix like that? And when I was talking about buffers, I meant color buffer and depth buffer and all that. Our prof was talking about something like this the other day, and he said something about rendering it to the color buffer and not the depth buffer, or the other way around or something. I didn’t really follow it. Speed doesn’t matter, just generating a static image.
Matrix can be get by glGetdoublev(GL_MODELVIEW_MATRIX)
Mirror can be made without textures. By Stencil.
1)CLear stencil, render mirror and mark it with stencil
2)clear depth buffer, restrict rendering to stenciled region and create clipping plane
3)multiply matrix by mirroring matrix and ,change polygon face to CW render scene again
4) change mode back to CCW
You can find sources(for Delphi, but they are pretty clear) in http://www.geocities.com/udodenko/glcl.zip
unzip, you’ll find glclAux18. In it procedure is called tglReflector.hidecolor
If something is still unclear ask again
Thanks for all the responses guys. Sorry I didn’t check this sooner, but I was crashed out asleep after a 40 hour programming session. I ended up using the exact same method that J outlines above. I stored it in a texture, and mapped it onto my fishbowl - looked pretty good after I set a decent transparency. Then, to get the refraction, I did the same texture trick, but instead of the original cam position, I looked at that position’s inverse from the bowl (so along the same line of sight). So the two textures made semi-transparent and blended together made a pretty decent effect. Not perfect, because I don’t really have a refracting angle calculated anywhere, but the final image looks pretty much like you would expect a fish bowl to look. Using those methods is pretty damn slow though - I’d never recommend it for real-time. Thanks again for the help!
-PM