Skip to main content
gamedev.net
🔒 Locked

Transparent rendered texture

Started by DanielH 13 replies 2.1k views
Original Post
DanielH
DanielH
In my game I render a gun to a texture and then draw it in ortho mode. I''d like to make the textures background transparent instead of black, but i don''t know how to. Any ideas?
tok_junior
tok_junior
How about setting the alpha to 0 and using alphablending?
DanielH
DanielH
How do I do that?
DanielH
DanielH
Is the correct way of doing this by use some strange background color and the go through the texturedata and change that color to alpha 0? But how do I then get the pixeldata since i just copied the viewport to a texture.
DanielH
DanielH
I read an article that just explained the way of doing this but didnt show any code for it.

Firstly the texture must be a 4 channel RGBA texture. And then before drawing the 3D object I clear the screen with a 0 alpha clear color. And lastly I copy the vieport using glCopyTexImage2D with GL_RGBA mode. But It still doesnt work!?
DanielH
DanielH
I really need help with this That black quad looks awfull
Jeffno10
Jeffno10
I''ll try and put you on the right track.

You really need to create an ALPHA map, which is basically just an 8 bit texture used to store transparency values. You can do this by going through your data manually and for a black pixel, on your alpha map have a value of 0.0, and for any over value have the alpha of 1.0. You could write some code to find the edges of your texture and have an alpha of say 0.5, thus you won''t have ultra sharp unrealistic edges.

The easiest way to do this is propably to copy your RGB texture into a RGBA texture and the process the fourth byte of each pixel as I describe above.

I hope I have at least been of some help.
Ilici
Ilici
isn''t that extremly slow???

first copy the texture from AGP memory to system mem - then pass over it - send it back (i bet this takes 50% of the frame time)

Doesn''t the frame buffer have an alpha channel ? If so clear it with alpha 0.0 and render with alpha 1.0 . Or you could use a PBUFFER.



[ My Site ]
''I wish life was not so short,'' he thought. ''Languages take such a time, and so do all the things one wants to know about.'' - J.R.R Tolkien
/*ilici*/
DanielH
DanielH
Not just loading, making a already existing texture transparent.

I still havent been able to make it transparent


I think that when i use glCopyTexImage2D to copy the framebuffer to a texture its background should also be alpha 0 when the background is cleared with alpha 0.... But no no
DanielH
DanielH
Solved it by rendering a black and white texture and then use it as a mask.

Thanks anyway.
Hellsp4wn
Hellsp4wn
Maybe a stupid question, but you might have overlooked it, so I''ll ask it anyway

Did you use an internal-format in glCopyTexImage2d of RGBA or equivalent? If not, the alpha value wouldn''t be returned, would it?

Hellsp4wn
-----------

I''m having deja-vu and amnesia at the same time. It''s like I think I''ve forgotten this before.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.