Results 1 to 2 of 2

Thread: Multiple BitBlt Routines Causing Flicker

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Question Multiple BitBlt Routines Causing Flicker

    I have created a subroutine that I can simply call whenever I need to use BitBlt:

    Code:
    Public Function DoBitBlt(theBuffer As PictureBox, THESTAGE As Object, THEBACKGROUND As PictureBox, THECHARACTER As PictureBox, THECHARACTERMASK As PictureBox, theCharacterNewX As Long, theCharacterNewY As Long)
    theBuffer.Width = THEBACKGROUND.Width
    theBuffer.Height = THEBACKGROUND.Height
    THECHARACTERMASK.Width = THECHARACTER.Width
    THECHARACTERMASK.Height = THECHARACTER.Height
    
    BitBlt theBuffer.hdc, 0, 0, Val(theBuffer.Width / Screen.TwipsPerPixelX), Val(theBuffer.Height / Screen.TwipsPerPixelY), THEBACKGROUND.hdc, 0, 0, vbSrcCopy
    
    BitBlt theBuffer.hdc, theCharacterNewX, theCharacterNewY, THECHARACTER.Width, THECHARACTER.Height, THECHARACTERMASK.hdc, 0, 0, vbSrcAnd
    BitBlt theBuffer.hdc, theCharacterNewX, theCharacterNewY, THECHARACTER.Width, THECHARACTER.Height, THECHARACTER.hdc, 0, 0, vbSrcPaint
    
    BitBlt THESTAGE.hdc, 0, 0, THESTAGE.ScaleWidth, THESTAGE.ScaleHeight, theBuffer.hdc, 0, 0, vbSrcCopy
    End Function
    In a Timer with an interval of 100, I am calling this subroutine twice (I have two separate pictures I am attempting to BitBlt). If I were to comment out one, the other would work flawlessly. However, when both are called, I get flicker.

    One picture is animating. The other picture is non-animating. The problem is if you BitBlt one thing on a PictureBox, you have to do it to everything else that you want to appear. You can't just drop a PictureBox on the scenery picture... it just won't show.

    Therefore, my question is: How do I BitBlt two or more pictures (animated and non-animated) without causing flicker?

  2. #2
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: Multiple BitBlt Routines Causing Flicker

    Hi Conroy. I fear flickering is unavoidable if you render anything less than the full scene directly to the screen. You'll need to render the entire scene to an off-screen buffer, then flip that buffer to the screen after all drawing has finished.

    So, two potentially easy fixes would be:

    1) Set the .AutoRedraw property of THESTAGE form or picture box to TRUE. After calling DoBitBlt twice (or however many times you need to do it), add this code to the calling function:

    Code:
    THESTAGE.Picture = THESTAGE.Image
    THESTAGE.Refresh
    That will trigger an AutoRedraw refresh.

    2) Instead of rendering directly to THESTAGE, create an off-screen form or picture box called THESTAGEBUFFER. Change DoBitBlt to render to THESTAGEBUFFER, then when all DoBitBlt calls are done, copy THESTAGEBUFFER to THESTAGE.

    Are either of those fixes simple to implement in your current rendering chain?
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

Tags for this Thread

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