Jump to content
  • Advertisement
Sign in to follow this  
redbaran

OpenGL Rendering to a texture

This topic is 4484 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, as a relative newbie to openGL, whenever I've had to render to a texture, I've just gone and used a Framebuffer Object (FBO) and this has worked great! The only snag I hit was when I tried to share a texture between multiple video cards, and then I found out the obvious fact that the texture I created using the FBO was only on the card where the texture was created, duh! Anyway, I'm finding that the FBO doesn't work on some computer, even if I update to the latest video drivers for them. So, I need to pay my dues and learn other methods of rendering to a texture. The method that I'm trying now is the same one that is used in NeHe Tutorial 36. Here's my problem if someone out there smarter then me would be so kind to enlighten me: I have a fairly small window, like 339x128 pixels and I need to render to a texture that is 512x512. Is this possible using glCopyTexImage2D? So far, I haven't been able to, though what I've done does work if I increase my window size. Is there any way around this because I really like the simplicity of just reading from the back buffer and clearing it. I guess I could read up on pbuffers, but I feel that there should be another way. Here's the order of things I do: - create my texture with some size, such as 512x512 - push the matrix - set my viewport using glViewport(0, 0, 512, 512); - set my ortho so the top left is (0, 0) using glOrtho(0.0, 512, 512, 0.0, 1.0, -1.0); - Draw whatever I need to draw - bind my texture and read from the back buffer using glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 512, 512, 0); - clear the color and depth buffer - reset my viewport - pop the matrix Any ideas? I spent an hour or two looking for info on this here and on google, but didn't find anything, but I'm sure there's something out there, post a link if I missed something.

Share this post


Link to post
Share on other sites
Advertisement
AFAIK you can't render to a texture thats bigger than the viewport with standard RTT methods such as glCopyTexImage and such, but what you could try is make your texture 512x512 and use glCopyTexSubImage and try to have that spread the smaller viewport over the 512x512, by using texture coordinates. Don't quote me on this, just an idea. I haven't tried it, for as I use FBO's. Most likely you don't have a videocard that's OpenGL2.0 compliant, for you would be able to use NPOT textures, and that is nice for non standard viewport sizes. And for the videocard situation AFAIK ATI and Nvidia both support FBO's since x700 and 6 series...

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
AFAIK you can't render to a texture thats bigger than the viewport with standard RTT methods such as glCopyTexImage and such, but what you could try is make your texture 512x512 and use glCopyTexSubImage and try to have that spread the smaller viewport over the 512x512, by using texture coordinates. Don't quote me on this, just an idea. I haven't tried it, for as I use FBO's. Most likely you don't have a videocard that's OpenGL2.0 compliant, for you would be able to use NPOT textures, and that is nice for non standard viewport sizes. And for the videocard situation AFAIK ATI and Nvidia both support FBO's since x700 and 6 series...


Good info, thanks! I like the idea of using a couple passes to combine to make the 512x512 image, however, the layer that this is working at is not aware of how big the screen is... I suppose I could make it aware either by passing in that info, or by polling the video card, but I think that is making it too complicated.

The specific computer that it's not running on (not mine) has an "Nvidia Quadro NVS with 8x AGP". I've gotten the FBO to work on other quadro's before, but I'm not sure why this one won't work! I even tried some beta drivers and that didn't work.

But, even if I were to get it working on this computer, I'd still want it to run on anyone's computer, even if they didn't have the latest drivers.

One more question... does the viewport size affect the back buffer size? If not, what determines the back buffer size? From what I've seen so far, it's the actual window size that determines the back buffer size, not how big I make the viewport.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!