IonicWind Software

IWBasic => 3D Programming => Topic started by: Guilect on August 30, 2008, 10:44:38 AM

Title: Colorkey on a custom mesh ?
Post by: Guilect on August 30, 2008, 10:44:38 AM
How do you get a transparent color on a created mesh?
The code below should make any Black color on the loaded bmp texture 'see-thru'.
m.loadtexture(0,"bug.bmp",RGBA(0,0,0,255))

But it does not.
again looking for some help....

'//Example of creating a custom mesh.

CONST DIK_ESCAPE =         0x01

C3DScreen s
C3DCamera c
C3dMesh m
C3DObject scene
C3DLight light

s.CreateWindowed(0,0,640,480,@CAPTION,"Custom Mesh",NULL,TRUE)

c.Create(s)
c.Position(0,0,-8)
c.Orient(0,0,1,0,1,0)
c.SetBackPlane(500)

m.createmesh(s,4,6,D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1)
'//lock the buffers and write the vertices
POINTER pVB
POINTER pIB

pVB = m.LockVertexBuffer()
pIB = m.LockIndexBuffer()

#<VERTEX1TEXTURE>pVB.position.x = -1
#<VERTEX1TEXTURE>pVB.position.y = -1
#<VERTEX1TEXTURE>pVB.position.z = 0
#<VERTEX1TEXTURE>pVB.diffuseColor = RGBA(255,255,255,255)
#<VERTEX1TEXTURE>pVB.normal = Vec3Normalize(#<VERTEX1TEXTURE>pVB.position)
#<VERTEX1TEXTURE>pVB.texCoords[0].x = 0
#<VERTEX1TEXTURE>pVB.texCoords[0].y = 1
pVB += len(VERTEX1TEXTURE)

#<VERTEX1TEXTURE>pVB.position.x = 1
#<VERTEX1TEXTURE>pVB.position.y = -1
#<VERTEX1TEXTURE>pVB.position.z = 0
#<VERTEX1TEXTURE>pVB.diffuseColor = RGBA(255,255,255,255)
#<VERTEX1TEXTURE>pVB.normal = Vec3Normalize(#<VERTEX1TEXTURE>pVB.position)
#<VERTEX1TEXTURE>pVB.texCoords[0].x = 1
#<VERTEX1TEXTURE>pVB.texCoords[0].y = 1
pVB += len(VERTEX1TEXTURE)

#<VERTEX1TEXTURE>pVB.position.x = -1
#<VERTEX1TEXTURE>pVB.position.y = 1
#<VERTEX1TEXTURE>pVB.position.z = 0
#<VERTEX1TEXTURE>pVB.diffuseColor = RGBA(255,255,255,255)
#<VERTEX1TEXTURE>pVB.normal = Vec3Normalize(#<VERTEX1TEXTURE>pVB.position)
#<VERTEX1TEXTURE>pVB.texCoords[0].x = 0
#<VERTEX1TEXTURE>pVB.texCoords[0].y = 0
pVB += len(VERTEX1TEXTURE)

#<VERTEX1TEXTURE>pVB.position.x = 1
#<VERTEX1TEXTURE>pVB.position.y = 1
#<VERTEX1TEXTURE>pVB.position.z = 0
#<VERTEX1TEXTURE>pVB.diffuseColor = RGBA(255,255,255,255)
#<VERTEX1TEXTURE>pVB.normal = Vec3Normalize(#<VERTEX1TEXTURE>pVB.position)
#<VERTEX1TEXTURE>pVB.texCoords[0].x = 1
#<VERTEX1TEXTURE>pVB.texCoords[0].y = 0
pVB += len(VERTEX1TEXTURE)

'// indices
#<WORD>pIB[0] = 0
#<WORD>pIB[1] = 2
#<WORD>pIB[2] = 1
'// triangle
#<WORD>pIB[3] = 1
#<WORD>pIB[4] = 2
#<WORD>pIB[5] = 3

'//unlock the buffers
m.UnlockIndexBuffer()
m.UnlockVertexBuffer()

m.setvisible(true)

' load in some bitmap
m.loadtexture(0,"bug.bmp",RGBA(0,0,0,255))

light.Create(s,LIGHT_POINT,1)
light.Position(0,20,-100)
light.SetAttenuation(0,1/200.0,0)
light.SetSpecular(.5,.5,.5,1)
light.SetAmbient(.4,.4,.4,1)

scene.CreateScene(s)
scene.AddChild(light)
scene.AddChild(m)

do
s.Clear(RGBA(0,255,0,255))
s.BeginScene(c)
scene.Draw()
s.RenderText(0,10,"ESC to exit",RGBA(255,255,0,255))
s.RenderScene()
until KeyDown(DIK_ESCAPE)
Scene.Free()
END
Title: Re: Colorkey on a custom mesh ?
Post by: Barney on August 30, 2008, 01:20:04 PM
Here it is:

' load in some bitmap and enable alpha
m.loadtexture(0,"bug.bmp",RGBA(87,87,87,255))
m.EnableAlpha(TRUE)


Barney
Title: Re: Colorkey on a custom mesh ?
Post by: Guilect on August 30, 2008, 05:54:39 PM
Ah, the old m.EnableAlpha(TRUE) trick.
That was what I was missing.

(I knew that the outer background of that particular bmp was not true black, but there was other parts
of that image that were black.)

Barney, thanks for your time, I appreciate it.