Masked texture
Blitz3D Forums/Blitz3D Beginners Area/Masked texture
| ||
Hello all, its been a while since I've last posted. I could use some help with an issue I've been struggling with for a while now. I've created a texture using the CreateTexture command, and have attempted to mask the texture using flag 4. However, all this seems to do is remove everything I've added to the texture. Heres an example I've made up: I had coloured the two top textures 0,0,0, and the B3D help docs say that all sections of the texture coloured 0,0,0 would not be drawn to the screen, but it doesn't appear to be doing that at all. The same thing is happening on the two lower textures as well, but there are no black areas on those two textures at all. I had drawn white text onto the textures, but the text is removed as well. I don't know if I'm missing something completely obvious or what, but I'd really appreciate some help here. What exactly does setting the texture flag to 4 do? Many thanks, Kii |
| ||
There are a few issues here and I don't know all the details. Each buffer has some format, a combination of color, alpha etc. The 2D commands only work with compatible formats, whatever that means. In this case Text is simply failing on the incompatible textures. You might hope to use Text on a texture where it works and then CopyRect to another texture. I think that will also fail in this case. You can often get the result you want if you are willing to get your hands dirty with some bit twiddling. Here is a somewhat half-baked example. It builds a texture which is solid yellow, with alpha increasing from left to right. Then there is an image with some blue text. Finally these are combined, using alpha from the texture and color from the image. Graphics3D 800, 600, 0, 2 AmbientLight 255,255,255 cam = CreateCamera() : PositionEntity cam, 0, 0, -3 cube = CreateCube() tex=CreateTexture( 256,256, 1 + 2 + 16 + 32 ) ; color + alpha + clamp u + clamp v EntityTexture cube, tex SetBuffer TextureBuffer( tex ) For x = 0 To 255 For y = 0 To 255 WritePixel x, y, (x Shl 24) + $FFFF00 ; alpha=x R=255 G=255 B=0 Next Next img = CreateImage( 200, 100 ) SetBuffer ImageBuffer( img ) Color 0,0,255 SetFont LoadFont( "arial", 80 ) Text 0,0, "Hello" imgbuff = ImageBuffer( img ) texbuff = TextureBuffer( tex ) For x = 0 To 199 For y = 0 To 99 imgpixel = ReadPixel( x, y, imgbuff ) And $FFFFFF ; just the color data If imgpixel <> 0 texpixel = ReadPixel( x+50, y+90, texbuff ) And $FF000000 ; just alpha WritePixel x+50, y+90, texpixel + imgpixel, texbuff End If Next Next SetBuffer BackBuffer() RenderWorld Flip WaitKey |
| ||
I think that you can't use some flags when using createtexture() or at least it does not work the same way as when you use loadtexture with the same flag for example try to replace the flag 4 by the flag 2. Here i get a "buffer does not exist" 2 possibles solutions to make some pixels transparent/invisible on a texture : create an image with black pixels save the image load the image as a texture with loadtexture and flag 4 or use writepixel to specify the alpha value of each transparent/invisible pixel there are examples of this in the code archives |
| ||
others infos : http://www.blitzbasic.com/b3ddocs/command.php?name=CreateTexture&ref=3d_cat |
| ||
Ah, okay then. Its interesting how certain flags will work using LoadTexture but not CreateTexture. I've been using RemiD's first solution for a while now, just because I could never get the flag to work on CreateTexture...Now I know! Time to go break down Floyd's code and learn that method. Thanks for helping, you two. Kii |
| ||
An obsolete note: some old paint programs change brightness and contrast so you wind up with non 0 black, and 256 color bitmaps may have funny issues with palette slots. This sort of thing can also occur converting images between hardware platforms. |