dx not working as it should again.

RazerWriter

Freshman
Joined
Jun 26, 2003
Messages
32
I don't get it, I have had years of experience with DX and now somehow things are getting screwy with DX9. First it was the tex coords, which it took a while for me to figure out why it was acting funny, now its transparency. I don't know why, but Dx is drawing every method except simple colorkey transparency!! Can you beleive it, I don't know what's up! Why won't it do it.

Here is the code, maybe i need another eye to figure this one out.

Okay, so I'm loading the texture:

ColorKey = Manganta

LoadTexture = TextureLoader.FromFile(device, strFilename, nW, nH, 1, 0, Format.X8R8G8B8, Pool.Managed, 3, 3, ColorKey.ToArgb)

Now I'm setting the alpha values:

device.RenderState.AlphaBlendEnable = True
device.RenderState.SourceBlend = Blend.SourceAlpha
device.RenderState.DestinationBlend = Blend.InvSourceAlpha


And, finally I'm drawing it:

device.SetStreamSource(0, vertexBuffer, 0)
device.VertexFormat = CustomVertex.TransformedColoredTextured.Format
device.SetTexture(0, Texture)
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2)

The results should be a nice sprite with transparency, but I get an image with a blackbackground where the transparecny should be !!! What's up??

Please help.. thank you so very much :)
 
Have you tried the same code and image, but change the Magenta to black (and change the sprite to use black as transparency)? I test with black since I know it works (no misinterpreting what 0 means :))

If that doesn't work, check out the texture stage states:
textureState0.AlphaOperation = TextureOperation.Modulate;
textureState0.AlphaArgument1 = TextureArgument.TextureColor;
textureState0.AlphaArgument2 = TextureArgument.Diffuse;

Also I noticed you're passing in 0 for the vertext size (3rd param) in the call to SetStreamSource. I think you want the size of your vertex, maybe CustomVertex.TransformedColoredTextured.StrideSize?

If you're using Direct3D to do sprites, don't forget to subtract 0.5 from your screen locations-to-x/y values. If you don't know what I'm talking about, let me know :)

-Nerseus
 
Ah yes, thanks Nerseus, those optomizations worked very nicely. I also noticed that when I was loading the textures, I was using the wrong texture format (no 32-bit).

Here is he updated code (which suprisingly works!):

'Loading texture
LoadTexture = TextureLoader.FromFile(device, strFilename, nW, nH, 1, 0, Format.A8R8G8B8, Pool.Default, Filter.Triangle, Filter.Triangle, ColorKey.ToArgb)

'Now I'm drawing it
device.SetStreamSource(0, vertexBuffer, 0, CustomVertex.TransformedColoredTextured.StrideSize)
device.VertexFormat = CustomVertex.TransformedColoredTextured.Format
device.SetTexture(0, Texture)
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2)


Just for laughs, I'll throw in the code to update the vertex:

Public Sub UpdateVertex(ByVal Vert As vertexBuffer, ByVal sX As Single, ByVal sY As Single, ByVal sW As Single, ByVal sH As Single, ByVal TextureX As Single, ByVal TextureY As Single, ByVal TextureW As Single, ByVal TextureH As Single, ByVal Color1 As Long, ByVal Color2 As Long, ByVal Color3 As Long, ByVal Color4 As Long)
If Not settingUse3D Then Exit Sub

Dim v As CustomVertex.TransformedColoredTextured() = CType(Vert.Lock(0, 0), _
CustomVertex.TransformedColoredTextured())

Dim TexCorLeft As Single = (TextureX / TextureW)
Dim TexCorTop As Single = (TextureY / TextureH)
Dim TexCorRight As Single = TexCorLeft + (sW / TextureW)
Dim TexCorBottom As Single = TexCorTop + (sH / TextureH)

sX = sX - 0.5
sY = sY - 0.5

v(0) = New CustomVertex.TransformedColoredTextured(sX, sY, 0, 1, _
Color1, TexCorLeft, TexCorTop)
v(1) = New CustomVertex.TransformedColoredTextured(sX + sW, sY, 0, 1, _
Color2, TexCorRight, TexCorTop)

v(2) = New CustomVertex.TransformedColoredTextured(sX, sY + sH, 0, 1, _
Color3, TexCorLeft, TexCorBottom)
v(3) = New CustomVertex.TransformedColoredTextured(sX + sW, sY + sH, 0, 1, _
Color4, TexCorRight, TexCorBottom)

Vert.Unlock()

End Sub
 
Back
Top