Results 1 to 10 of 10

Thread: [RESOLVED] Render to Texture and Alphablend problem (VB6/DX8)

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    4

    [RESOLVED] Render to Texture and Alphablend problem (VB6/DX8)

    I’m trying to render to texture, by using the SetRenderTarget method. I create the texture using the D3DFMT_A8R8G8B8 format but when I render a sprite, for example, that has an 8bit alpha channel to the texture, the alpha blending doesn’t seem to be right. The “translucent pixels” in my image are more “clear” than it supposed to be. It’s better to look at an example, see http://www.auriterminal.com/view/Alpha.png (attached below)
    There is a checkered image rendered first on to the backbuffer (which is presented). On top of that is an 8bit alpha channel image (black rectangle with three “holes” with varying opacity, that’s what it supposed to look like on the left. On the right is the render to texture surface. As you can see, the opacity for each hole is less with the right image. You can see the logic in the code snippet below.

    Using VB6 and DX8.1
    VB Code:
    1. ' Declarations
    2. Dim pRendertexture As Direct3DTexture8
    3. Dim pRendersurface As Direct3DSurface8
    4. Dim pBackbuffer As Direct3DSurface8
    5. Dim Zbuffer As Direct3DSurface8
    6.  
    7. ' ... (Code) ....
    8.  
    9. ' Create texture
    10.   Set pRendertexture = d3dx.CreateTexture(device, 256, 256, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT)
    11.   Set pRendersurface = pRendertexture.GetSurfaceLevel(0)
    12.   Set pBackbuffer = device.GetRenderTarget
    13.   Set Zbuffer = device.GetDepthStencilSurface
    14.  
    15. ' ... (Code) ....
    16.  
    17. ' Render to texture
    18.   device.SetRenderTarget pRendersurface, Zbuffer, ByVal 0
    19.   device.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, &H0, 1#, 0
    20.   device.BeginScene
    21.       Sprite.Begin
    22.         Sprite.Draw AlphaImage, ByVal 0, Scaling, Center, Rotation, Pos, &HFFFFFFFF
    23.       Sprite.End
    24.   device.EndScene
    25.   device.SetRenderTarget pBackbuffer, Zbuffer, ByVal 0
    26.  
    27. ' ... (Code) ....
    28.  
    29. ' Render to BackBuffer
    30.   D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, cBackgroundColor, 1#, 0
    31.   D3DDevice.BeginScene
    32.       Sprite.Begin
    33.         Sprite.Draw CheckeredBackground, ByVal 0, Scaling, Center, Rotation, Pos0, &HFFFFFFFF
    34.         Sprite.Draw AlphaImage, ByVal 0, Scaling, Center, Rotation, Pos1, &HFFFFFFFF  
    35.         Sprite.Draw pRendertexture, ByVal 0, Scaling, Center, Rotation, Pos2, &HFFFFFFFF
    36.       Sprite.End
    37.   D3DDevice.EndScene
    38.   D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
    39. End Sub

    Thank You.
    Attached Images Attached Images  
    Last edited by jsmallberry; Jul 19th, 2006 at 09:35 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width