Transparent Texture - How To ?

Blitz3D Forums/Blitz3D Programming/Transparent Texture - How To ?

semar(Posted 2004) [#1]
Hi all.

What I would like to achieve, is a sprite textured with a transparent texture (flag=4 ?), then write some text on a texture, so that it appears on the sprite.

I've tryed different combination with the texture flags, but no joy...

From the flag 4 description, I read:

4: Masked - all areas of a texture coloured 0,0,0 will not be drawn to the screen



So I expect to see the cube through the sprite, and the text on the sprite itself... but it does not. Instead, the sprite is full black, solid (it covers part of the cube), and no text is written on it.

What's wrong ?!?!?

Thanks in advance...
Sergio.

Graphics3D 640,480,0,2

cam = CreateCamera()
cube = CreateCube()
MoveEntity cube,0,0,6

sp = CreateSprite()
PositionEntity sp,0,1.2,3

size = 128
mode = 4
tx = CreateTexture(size,size,mode)

EntityTexture sp,tx

SetBuffer TextureBuffer(tx)
ClsColor 0,0,0
Cls

Color 255,255,255
Text size/2,size/2,"Hello World",True
SetBuffer BackBuffer()

EntityTexture sp,tx

While Not KeyDown(1)

TurnEntity cube,0,1,0

UpdateWorld()
RenderWorld()

Flip

Wend
End



David819(Posted 2004) [#2]
I'm not quite sure why this is happening but when i get rid of the mode=4 part it shows the hello world fine, so it could be a bug, but i am not sure.


big10p(Posted 2004) [#3]
Try adding this code in place of where you're CLS'ing the texture to black:

For y = 0 To size-1
    For x = 0 To size-1
        WritePixel x,y,$00000000
    Next
Next



Ziltch(Posted 2004) [#4]
Had same problem ages ago. It still may be in bug reports.

I think the work around was using a loaded texture with the mask flag set. You can just saved it first!

Also I think the text command only works on the backbuffer

e.g.
Graphics3D 640,480;,0,2

cam = CreateCamera()
cube = CreateCube()
MoveEntity cube,0,0,5

sp = CreateSprite()
PositionEntity sp,0,.2,1

size = 128
mode = 4
tx = Createtexture(size,size,mode)

Color 255,55,255
Text size/2,size/2,"Hello World",True
copyrect 0,0,size,size,0,0,BackBuffer(),texturebuffer(tx)

savebuffer (texturebuffer(tx),"temp.bmp")
tx=loadtexture("temp.bmp",mode)
EntityTexture sp,tx

While Not KeyDown(1)

  TurnEntity cube,0,1,0

  UpdateWorld()
  RenderWorld()

  Flip

Wend
End



Hope this helps.


Ziltch(Posted 2004) [#5]
Here is a Pretty Alpha version
Graphics3D 640,480;,0,2
setbuffer backbuffer()
cam = CreateCamera()
cameraclscolor cam, 68,0,0

sp = CreateSprite()
PositionEntity sp,0,.2,2

Setfont LoadFont("Arial",100,False,False,False)
size = 512
mode = 3
tx = Createtexture(size,size,mode)

Color 255,225,155
Text size/2,size/2,"Alpha World",True,true
copyrect 0,0,size,size,0,0,BackBuffer(),texturebuffer(tx)
savebuffer (texturebuffer(tx),"temp.bmp")
tx=loadtexture("temp.bmp",mode)
EntityTexture sp,tx

cube = CreateCube()
EntityTexture cube,tx
entityfx      cube,16
siz#=1
for count = 1 to 16
  cube2=copymesh(cube,cube)
  siz# = siz# -.07
  scalemesh cube2,siz#,siz#,siz#
  EntityTexture cube2,tx
  entityfx      cube2,16
  ptch#=ptch+.25
  rotatemesh    cube2,-ptch,-count*12,-count*12
  entitycolor cube2,sin(count*5.625)*128+127,cos(count*5.625)*128+127,count
next



MoveEntity cube,0,0,3

start_time = MilliSecs( )
While Not KeyDown(1)

  TurnEntity cube,0.15,1,1
  now= (MilliSecs( ) - start_time )  mod  2147483647
  entitycolor cube,sin(now*.1)*128+127,0,cos(now*.5)*255+127
  RenderWorld()

  Flip

Wend
End


Have Fun!


Neochrome(Posted 2004) [#6]
bug in v1.86, go to 1.87, that bug is fixed


Ziltch(Posted 2004) [#7]
The writing text on a texture bug was fixed ?
Not in my 1.87.


semar(Posted 2004) [#8]
Thanks all m8s !

I still don't know if I'm doing right or wrong here; anyway, I've solved everything using sprites and the magic statement:
EntiyBlend sprite,3


If only the docs were a bit more explicative about what kind of effects could be achieved with which setting... it would save me lots of time !

Time to write a tutorial about all the tips and tricks about EntiyBlend, EntityFx, LoadTexture, CreateSprite,...

Cheers to all,
Sergio.

[edited]
@Ziltch,
nice one, thanks !


Rob Farley(Posted 2004) [#9]
Sergio,

Have you seen my snippet for entityblend?

http://www.blitzbasic.com/b3ddocs/command.php?name=entityblend&ref=goto


semar(Posted 2004) [#10]
Guys, that is *extremely* useful !

Thanks a load Rob !

I should check the on-line manual more often I guess...

Sergio.