Multitexturing and alpha, round 2 (help please)

Blitz3D Forums/Blitz3D Beginners Area/Multitexturing and alpha, round 2 (help please)

octothorpe(Posted 2005) [#1]
I've been wrestling with this for a while now... I'm attempting to draw on a background texture with an overlay texture. Everything works fine until I set EntityAlpha to less than 1 - the background texture disappears entirely! Even an alpha setting of .99 causes this. Here is some code which demonstrates the problem:

Graphics3D 800, 600, 0, 2
camera = CreateCamera()
PositionEntity camera, 0, 0, -5
backdrop = CreateCube()
ScaleEntity(backdrop, 10, 10, 1)
PositionEntity(backdrop, 0, 0, 10)

Const textureblend_ALPHA = 1, textureblend_MULTIPLY = 2, textureblend_ADD = 3
Const loadtexture_COLOUR = 1, loadtexture_ALPHA = 2, loadtexture_MASKED = 4
Const BLUE = 0, GREEN = 8, ALPHA = 24

t1 = CreateTexture(64, 64, loadtexture_COLOUR+loadtexture_ALPHA)
TextureBlend(t1, textureblend_ALPHA)
For x=0 To 63:For y=0 To 63
	WritePixel(x,y,(Rand(255) Shl BLUE) + (255 Shl ALPHA),TextureBuffer(t1))
Next:Next

t2 = CreateTexture(64, 64, loadtexture_COLOUR+loadtexture_ALPHA)
TextureBlend(t2, textureblend_ALPHA)
For x=0 To 63:For y=0 To 63
	WritePixel(x,y,0,TextureBuffer(t2))
Next:Next
For x=20 To 45:For y=20 To 45
	WritePixel(x,y,(Rand(255) Shl GREEN) + (255 Shl ALPHA),TextureBuffer(t2))
Next:Next

c = CreateCube()
RotateEntity(c, -15, -20, 0)
EntityTexture(c, t1, 0, 0)
EntityTexture(c, t2, 0, 1)

While Not KeyHit(1)
	EntityAlpha(c, 1)
	RenderWorld : Flip
	Delay 200
	EntityAlpha(c, .5)
	RenderWorld : Flip
	Delay 200
Wend
End


The cube should be blue noise with a green square of noise in the middle of it, and alternate between being opaque and 50% translucent. On the three computers I've tested this on, the blue background texture disappears entirely when EntityAlpha drops below 1.


DH(Posted 2005) [#2]
quoted from the documents on textureblending:

Sets the blending mode for a texture.

The texture blend mode determines how the texture will blend with the texture or polygon which is 'below' it. Texture 0 will blend with the polygons of the entity it is applied to. Texture 1 will blend with texture 0. Texture 2 will blend with texture 1. And so on.

Texture blending in Blitz effectively takes the highest order texture (the one with the highest index) and it blends with the texture below it, then that result to the texture directly below again, and so on until texture 0 which is blended with the polygons of the entity it is applied to and thus the world, depending on the EntityBlend of the object.

Each of the blend modes are identical to their EntityBlend counterparts.

In the case of multitexturing (more than one texture applied to an entity), it is not recommended you blend textures that have been loaded with the alpha flag, as this can cause unpredictable results on a variety of different graphics cards.




octothorpe(Posted 2005) [#3]
I'm still stuck, but that sheds some light, thanks. That'll teach me to try to learn from samples instead of documentation!
;Samples\Blitz 3D Samples\mak\multi_tex\multi_tex.bb
env=LoadTexture( "spheremap.bmp",67 )
EntityTexture cube,env,0,2
If using alpha on my overlay texture is not recommended, is it possible to accomplish this with masking? Or must I use another surface and stop using multitexturing?


DH(Posted 2005) [#4]
What, exactly, are you trying to do?

I can do my best to give you a good solution however merely seeing a cube blink doesn't give me much on what your trying to accomplish.


octothorpe(Posted 2005) [#5]
I'm trying to draw images onto my GUI windows' textures (which are quads).

I figured it'd be a good idea to draw onto separate layers so I can safely rewrite text all over my topmost layer without worrying about remembering which graphics need to be drawn where on the artwork layer underneath. I was originally going to use separate entities for each layer, but then I read about multitexturing and figured it might simplify things. Everything seemed to be going fine until I tried to make the whole window translucent with EntityAlpha.