Results 1 to 10 of 10

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

  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.

  2. #2
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: Render to Texture and Alphablend problem (VB6/DX8)

    Are both your images 32 bit?

    Plus, you should check out my alphablending demo in my Massive DX8 2D tutorial over in my signature. With the D3DColorRGBA(255, 255, 255, 255), you can change how much it has alphablended, but only from 128 - 255. Maybe if you alphablend it my way, it should work.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    4

    Re: Render to Texture and Alphablend problem (VB6/DX8)

    Are both your images 32 bit?
    It's the same image, the one on the left is rendered directly on the backbuffer, the one on the right is first rendered to a texture surface, and that texture is rendered to the backbuffer. And, it is a 32 bit PNG file.

    Thank you for the tutorial reference, I'll look at it tonight, it looks very in depth. I have used D3DColorRGBA before, but that applies to the whole texture. I want DirectX to accurately do the per-pixel alpha blending, and it doesn’t seem to be doing it properly when you first render to texture, and then render that texture to the backbuffer.

  4. #4
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: Render to Texture and Alphablend problem (VB6/DX8)

    Try BMP instead and see what happens. And also see if your resolution is 32 bit as well.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    4

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

    After much consternation, I finally figured it out. It’s all how the surface is cleared.

    The line
    VB Code:
    1. device.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, &H0, 1#, 0



    Should be
    VB Code:
    1. device.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, &HFFFFFF, 1#, 0

    I cleared the surface with black, it should be cleared with white. Despite the fact that the alpha setting is totally transparent (&H00 as in &H00FFFFFF) for the surface, the color modulates the elements rendered.

    I’ve been fighting this one for a while.

  6. #6
    New Member
    Join Date
    Jun 2022
    Posts
    4

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

    Jsmallberry, How do I contact?

  7. #7
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

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

    @Politano, do you have question related to this thread?
    The thread is dated 2006, that's 16 years ago, so I don't think jsmallberry is still working on this.

  8. #8
    New Member
    Join Date
    Jun 2022
    Posts
    4

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

    Jeez I didn't notice that I had so much time, so I have a similar problem, I'm developing a game, I need to insert a system of day and night and lights, day and night is simple with images, but making the lights work is pretty bad.

    This link was the most similar to what I'm looking for, I saw something about D3DRS_LIGHTING, but information about directx8 is very difficult to find and I'm not able to proceed.

  9. #9
    New Member
    Join Date
    Jun 2022
    Posts
    4

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

    I' have a problem em : Set Zbuffer = device.GetDepthStencilSurface

    I'm not able to add the reference from d3d9.dll to vb6

  10. #10
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

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

    That is because VB6 only supported directX up until Directx8. Although there are hacks to get it to support directx9, I wouldn't recommend it as even that is old. Now and days, most graphic related applications now use DirectX12, OpenGL 4.6, or Vulkan 1.2, none of which is supported by VB6 due to its age. And those use high level shaders to render the polygons with special effects, not necessarily hardcoded code. And now, we have libraries which make game creation easier such as with Unity 2021 or Unreal Engine 5, both of which support not only PC's, but Virtual Reality (Quest 2, Oculus Rift, and HTC Vive), PS4, PS5, XBox Series S, XBox Series X, Android, iOS, MacOS, and even the Hololens. So your applications can easily become multiplatform! You can even do full blown Ray Tracing. It's more hands on and a lot less coding as it gives you plenty of tools at your disposal and lots of tutorials on YouTube. And from my experience, it makes game creation faster, easier, and impressive!

    I also would like to point out that you will find it much easier to get Visual Studio 2022 Community Edition as it is now free, which can easily link up with Unity or Unreal Engine, whichever you decide. And you will have no worries about any sort of DX initialization, ZBuffers, DepthStencils, or clear colors as it is all handled for you. Btw here is a screenshot of me working with Unity. I used zero code. And if I were coding, it would be scripting using CSharp
    Attached Images Attached Images  

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