Texture Masking Problem
Blitz3D Forums/Blitz3D Programming/Texture Masking Problem
| ||
My problem is that I’m trying to create a texture which has text printed to it in real time and the rest of the texture is completely transparent. I want to do this so that I can have text rotating above objects in a scene. These textures have to be generated inside Blitz as because the player can rename objects. The problem is that for some reason I can’t do this, I found that using the ‘masked’ texture flag would make this work but for some reason the texture is still an opaque black square, the only difference is that the text is no longer visible either, not exactly what I wanted! Can anybody tell me what I’m going wrong? Is there an alternative way to do the same thing using alpha channels perhaps? Here’s my code Graphics3D 800,600 camera = CreateCamera() PositionEntity camera,0,0,-3.12 CameraClsMode camera,0,1 AmbientLight 255,255,255 SetBuffer BackBuffer() fntArialB=LoadFont("Arial",28,True) SetFont fntArialB back = LoadImage("2.png") Shadow = CreateSprite() tex = CreateTexture(256,256,1) SpriteViewMode Shadow ,2 SetBuffer(TextureBuffer(tex)) Text 0,100,"Why won't this work?" SetBuffer BackBuffer() brush = CreateBrush(255,255,255) BrushTexture brush,tex PaintEntity Shadow, brush Repeat MoveEntity Shadow,0,0.001,0 DrawBlock back,0,0 RenderWorld Flip Until KeyHit(1) |
| ||
You'll need to actually use writepixelfast or writepixel to write the transparent alpha information to the black areas i'm afraid... i wrote some functions to write this stuff.. http://www.blitzbasic.com/codearcs/codearcs.php?code=1013 :o) Hope that helps |
| ||
Thanks, I'll experiment with your way but why won't the masking flag work? I thought that was what it was for, otherwise what's the point? |
| ||
or just change your textureblend |
| ||
The masking flag won't work because blitz doesn't writealpha information when using drawing commands such as text, rect, line....etc etc. Same with copyrect. This doesn't write aplha information too. Need to remember black doesn't mean masked. It's not the colour, is the alpha information that each pixel/texel holds :o) |
| ||
The documentation says that the masking flag sets any black area to be transparent, I take it the documentation is wrong then? |
| ||
Not really - the masking works if you apply the flag when loading a texture - just not when creating them on the fly. |
| ||
it even works when you create it, but as soon as you write something to the texture, the entire alphachannel will be erased (= set to 255). I guess this happens because blitz has to load the texture from the video-ram, write to it, then move it back to the video ram. It seems in this process the alpha-channel is erased. Probably this won't happen when you use the Flag 256, but I didn't test this yet. As people said, use an other blending mode, or manually set back the alpha bytes. |