View Full Version : how to render to texture?
09-04-2002, 05:37 PM
How can I render to a texture in OpenGL? Can I do it normally? Or do I need some extension?
09-05-2002, 02:14 AM
To render TO a texture? That is, you want to render a screen and then save it and load it as a texture?
That can be done with normal OpenGL - it's the glReadPixels() call. This will read a rectangular array of pixels at the position and dimensions you specify, and store it in main memory at the buffer that you provide, using the current glReadBuffer and glPixelStore parameters.
Then, you can check to see whether that image satisfies texture requirement (that is, that each dimension is a power of 2 and neither of them exceeds the maximum allowed texture size for your OpenGL implementation (obtained with glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize) http://www.opengl.org/discussion_boards/ubb/wink.gif. If these conditions are not met, scale the image using gluScaleImage() call.
Then, use glTexImage2D() call to load your image as a texture, as usual.
Be aware though, that glReadPixels, glDrawPixels and glCopyPixels are broken in many hardware OpenGL implementations... Also, glReadPixels is slow (just think about the size of the image that needs to be sent over PCI bus), so it's not a good idea to do that every darn single frame of your animation.
[This message has been edited by Pa3PyX (edited 09-05-2002).]
Visit nehe for a tutorial on that topic, or my home page for an "for dummies" render to texture class..
hope it helps...
you can render to a pbuffer and bind the pbuffer as an texture
09-05-2002, 04:35 AM
Thanks for the responses, I have to look into them. I will say though that whatever I end up doing, it will in fact need to be done every frame since what I'm trying to do is image feedback. But I won't be doing much else. That's like what a lot of winamp visualizations do, but I'm looking to do it myself rather than by pugging into winamp. I know this sort of thing isn't very hard in DirectX, but I'd rather use OpenGL.
[This message has been edited by rhmazza (edited 09-05-2002).]
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.