Sign in to follow this  

Copying framebuffer to texture - with alpha

This topic is 2629 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

I have a number of complex sprites made up of very simple parts that don't change that often, and redrawing the parts real-time is a pretty big waste of cycles. So i'm trying to push the entire sprite onto a texture, and just use that texture as my rendering call for the sprite.

This is all great, but whenever i try to copy, the texture i get is an image with the sprite on a black background.

This makes sense, i'm clearing the buffer and drawing the entity, then glCopyTexImage2D() straight to the texture. Naturally i'll get whatever's in the gaps, which in this case is my clear color, black.

I obviously can't have great black squares following my sprites, but i also can't get them into their texture without rendering them somewhere first. Is there a way to render directly to a texture, or to specify that i want the untouched portions of the texture to have zeroed alpha?


Note; i tried a real hack that involved clearing to an ugly purple (1, 0, 1, 1) and running a 'replacement' shader that ignored fragments that would be purple whenever rendering the fragments of the sprite's texture, but this resulted in a sort of purple 'border' around everything, and the shader didn't quite work correctly anyway.

Share this post


Link to post
Share on other sites
The purple border is probably from anti-aliasing in the image. If you look at texture in an image editor, more than likely you will see colors other than the clear color around the image. The only other issue I can think of would be that you are using a lower mip level.

Share this post


Link to post
Share on other sites
You were absolutely right, i'd ensured my rendering didn't use AA, but the images did indeed have soft edges. After some quick tweaks to them, it works fairly well. D'OH.

I still don't like running every sprite through the equivalent of a replacement filter every cycle, but it still really beats drawing a few hundred quads to make one sprite.

Share this post


Link to post
Share on other sites

This topic is 2629 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this