How to write to the Alpha channel of a tecture 
Author Message
 How to write to the Alpha channel of a tecture

Folks;

Well, I think I figured out how to get to the texture bits (and alpha
channel) of a Tecture, but when I run this code, it does not seem to
change the Texture color in the way that I expect. Instead of changing
to a solid BLUE, it seems to be part BLUE, and part what was there to
begin with.

Anyway, here's the code to look at. If you notice something
out-of-sorts, please let me know!

Note that the underlying tecture is only 1 pixel in width, and a
variable size in the height.

-----
Dim DirectX_ContourMapTexture As Direct3DTexture8
Dim DirectX_RenderingDevice As Direct3DDevice8
Dim pTextureData As D3DLOCKED_RECT, TextureSize As Long
Dim TextureData() As Byte, TextureDataIndex As Long
Dim ImageInfo As D3DXIMAGE_INFO
const TextureFilePathName = "C:\Temp.Bmp"

Set DirectX_ContourMapTexture =
DirectX_Helper.CreateTextureFromFileEx(DirectX_RenderingDevice,
TextureFilePathName, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_POINT, D3DX_FILTER_POINT,
&HFF000000, ImageInfo, ByVal 0)
WasAnError = ((Err.Number <> 0) Or (DirectX_ContourMapTexture Is
Nothing))
If (Not (WasAnError)) Then
  Call DirectX_ContourMapTexture.LockRect(0, pTextureData, ByVal 0,
0): WasAnError = (Err.Number <> 0)
  If (Not (WasAnError)) Then
    TextureSize = (MyDrawState.DirectX_TextureMapLength *
pTextureData.Pitch)
    ReDim TextureData(1 To TextureSize): WasAnError = (Err.Number <>
0)
    If (Not (WasAnError)) Then
      WasAnError = (DXCopyMemory(TextureData(1), ByVal
pTextureData.pBits, TextureSize) <> D3D_OK)
      If (Not (WasAnError)) Then
        For TextureDataIndex = 1 To TextureSize Step
pTextureData.Pitch
          TextureData(TextureDataIndex + 0) = 255 ' Change to all Blue
          TextureData(TextureDataIndex + 1) = 0
          TextureData(TextureDataIndex + 2) = 0
        Next TextureDataIndex
        WasAnError = (DXCopyMemory(ByVal pTextureData.pBits,
TextureData(1), TextureSize) <> D3D_OK)
      End If
    End If
    Call DirectX_ContourMapTexture.UnlockRect(0)
  End If
End If
-----



Mon, 04 Oct 2004 12:01:20 GMT  
 How to write to the Alpha channel of a tecture
are you sure an alpha format was created? you specify unknown....

you also only touch 3 components, with alpha you need to touch 4 components.

you should be able to look at my code that programmatically generates an
alpha texture in my series of articles on alpha-blending on MSDN.

its DX 7 and C++, but it should translate easily.

--
Phil Taylor
PM : DirectX SDK, Managed DirectX, WindowsXP Inbox 3D Screensavers, and a
few more bits and bobs
http://msdn.microsoft.com/directx
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Folks;

> Well, I think I figured out how to get to the texture bits (and alpha
> channel) of a Tecture, but when I run this code, it does not seem to
> change the Texture color in the way that I expect. Instead of changing
> to a solid BLUE, it seems to be part BLUE, and part what was there to
> begin with.

> Anyway, here's the code to look at. If you notice something
> out-of-sorts, please let me know!

> Note that the underlying tecture is only 1 pixel in width, and a
> variable size in the height.

> -----
> Dim DirectX_ContourMapTexture As Direct3DTexture8
> Dim DirectX_RenderingDevice As Direct3DDevice8
> Dim pTextureData As D3DLOCKED_RECT, TextureSize As Long
> Dim TextureData() As Byte, TextureDataIndex As Long
> Dim ImageInfo As D3DXIMAGE_INFO
> const TextureFilePathName = "C:\Temp.Bmp"

> Set DirectX_ContourMapTexture =
> DirectX_Helper.CreateTextureFromFileEx(DirectX_RenderingDevice,
> TextureFilePathName, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
> D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_POINT, D3DX_FILTER_POINT,
> &HFF000000, ImageInfo, ByVal 0)
> WasAnError = ((Err.Number <> 0) Or (DirectX_ContourMapTexture Is
> Nothing))
> If (Not (WasAnError)) Then
>   Call DirectX_ContourMapTexture.LockRect(0, pTextureData, ByVal 0,
> 0): WasAnError = (Err.Number <> 0)
>   If (Not (WasAnError)) Then
>     TextureSize = (MyDrawState.DirectX_TextureMapLength *
> pTextureData.Pitch)
>     ReDim TextureData(1 To TextureSize): WasAnError = (Err.Number <>
> 0)
>     If (Not (WasAnError)) Then
>       WasAnError = (DXCopyMemory(TextureData(1), ByVal
> pTextureData.pBits, TextureSize) <> D3D_OK)
>       If (Not (WasAnError)) Then
>         For TextureDataIndex = 1 To TextureSize Step
> pTextureData.Pitch
>           TextureData(TextureDataIndex + 0) = 255 ' Change to all Blue
>           TextureData(TextureDataIndex + 1) = 0
>           TextureData(TextureDataIndex + 2) = 0
>         Next TextureDataIndex
>         WasAnError = (DXCopyMemory(ByVal pTextureData.pBits,
> TextureData(1), TextureSize) <> D3D_OK)
>       End If
>     End If
>     Call DirectX_ContourMapTexture.UnlockRect(0)
>   End If
> End If
> -----



Sat, 09 Oct 2004 05:15:12 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. alpha channel to object transparency

2. 8 bit alpha channel merge

3. Does StdPicture support alpha channel?

4. Menus with icons in XP style (alpha channel)

5. PNG files with alpha channel

6. Help: Control that supports translucency (alpha channel?)?

7. Adding Alpha Channel at runtime

8. Alpha Channels

9. Need Alpha Channel in DirectX 7

10. alpha channel question revised

11. alpha channel

12. Separate stereo channel of a wav file

 

 
Powered by phpBB® Forum Software