Skip to main content
gamedev.net
🔒 Locked

Alpha blending problems - FIXED

Started by Seiko Nov 1, 2005 at 7:08 AM 1 replies 950+ views
Original Post
Seiko
Seiko
Hi, I'm having trouble upgrading my VB6 code/DX8 to VB.net/DX9. In short I can't seem to be able to activate AlphaBlending. I've created a dummy application that does nothing more than render two textured triangles with a single texture. It has one point light and no ambient. I have added a diffuse color to the FVF and set the Alpha properties to the values I used in my DX8 code. Alas the triangles still appear solid. Can someone please help me spot the no doubt obvious mistake. Here are some code snippets. -- Vertex Format Const cCVF As VertexFormats = VertexFormats.Position Or VertexFormats.Normal Or VertexFormats.Diffuse Or VertexFormats.Texture1 Structure CustomVertexFormat Public x As Single Public y As Single Public z As Single Public nx As Single Public ny As Single Public nz As Single Public diffuse As Integer Public tu As Single Public tv As Single End Structure ----------------------------------------------------------------------- Dim iColour1 As Integer = Color.FromArgb(128, 255, 255, 150).ToArgb Dim iColour2 As Integer = Color.FromArgb(128, 255, 255, 150).ToArgb With myCustomVertex(0) .x = -1 : .y = -1 : .z = 0.0F .nz = 1 .diffuse = iColour1 .tv = 0 : .tu = 0 End With With myCustomVertex(1) .x = 1 : .y = -1 : .z = 0.0F .nz = 1 .diffuse = iColour1 .tu = 1 : .tv = 0 End With With myCustomVertex(2) .x = 0 : .y = 1 : .z = 0.0F .nz = 1 .diffuse = iColour1 .tv = 1 : .tu = 0 End With '---------------------------------------------------- With myCustomVertex(3) .x = 0 : .y = -1 : .z = 0.0F .nz = 1 .diffuse = iColour2 .tv = 0 : .tu = 0 End With With myCustomVertex(4) .x = 2 : .y = -1 : .z = 0.0F .nz = 1 .diffuse = iColour2 .tu = 1 : .tv = 0 End With With myCustomVertex(5) .x = 1 : .y = 1 : .z = 0.0F .nz = 1 .diffuse = iColour2 .tv = 1 : .tu = 0 End With ----------------------------------------------------------------------- With .RenderState() .CullMode = Cull.CounterClockwise .Lighting = True .ColorVertex = True .AlphaSourceBlend = Blend.SourceAlpha <-- SourceBlend = Blend.SourceAlpha .AlphaDestinationBlend = Blend.InvSourceAlpha <-- DestinationBlend = Blend.InvSourceAlpha .AlphaBlendEnable = True End With .TextureState(0).AlphaOperation = TextureOperation.Modulate ----------------------------------------------------------------------- Edited to show colors correctly calcualted but still broken! Edited to show fix! [Edited by - Seiko on November 1, 2005 9:14:42 AM]
jollyjeffers
jollyjeffers
Quote:
Dim iColour1 As Integer = Color.FromArgb(255, 255, 255, 150).ToArgb
Dim iColour2 As Integer = Color.FromArgb(255, 255, 255, 150).ToArgb

Isn't this code making both of the colours 'solid' - a 255 value for alpha? In that case alpha blending might be taking place but it'd be a bit redundant [smile]

I can't see anything else that's obviously wrong.

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
Seiko
Seiko
lol, thanks that's a typo. I just copied the code incorrectly. Even when changing it to

Dim iColour1 As Integer = Color.FromArgb(10, 255, 255, 255).ToArgb
Dim iColour2 As Integer = Color.FromArgb(10, 255, 255, 255).ToArgb

The triangles still overlap i.e. they remain solid! It's a real pain as I know this normally works!

:(

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.