Results 1 to 4 of 4

Thread: Direct2D

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    316

    Direct2D

    Hello I have two questions regarding Direct2D, the answers are probably a resounding no but I must ask.

    it is possible to draw something and preserve the background as we do with GDI, for example if in the form I have an image and I want to draw a text with Direct2 in some part of the form, without the background being a fixed color and without having to repaint the image.

    the other, is it possible to paint only a part and not the whole form?

    I know it is different from GDI but maybe someone understands what my intention is.

    Code:
    Private Sub Form_Paint()
        Dim sText   As String
        'font "Segoe UI Emoji"
        Const D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT = 4
        sText = ChrW2(&H2638) & "Hello World!" & ChrW2(&H2639)
        
        cTarget.BeginDraw
        
        cTarget.Clear D2D1.ColorF(Ivory)
        
        cTarget.DrawText sText, Len(sText), ByVal cTextFormat, D2D1.RectF(20, 20, 220, 120), cBrush, D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT
    
        cTarget.EndDraw ByVal 0&, ByVal 0&
        
    End Sub
    Last edited by LeandroA; Apr 19th, 2021 at 11:36 AM.
    leandroascierto.com Visual Basic 6 projects

  2. #2
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,417

    Re: Direct2D

    use ID2D1BitmapRenderTarget (cTarget)
    this is how my render function looks like:

    Code:
    Sub Rendering()
        On Error GoTo error
        cTarget.EndDraw ByVal 0&, ByVal 0&
        If SoftWare Then D3DKMTWaitForVerticalBlankEvent tWaitVSync
        hTarget.BeginDraw
        hTarget.DrawBitmap cTarget.GetBitmap, ResizeRect, 1, InterPolationMode, GameRect
        hTarget.EndDraw ByVal 0&, ByVal 0&
    
        cTarget.BeginDraw
        cTarget.Clear bcolor
    error:
        If err.Number <> 0 Then Running = 99
    End Sub
    this is the "end" function, so theres a lot before this function where I draw to cTarget.
    hTarget is used to draw to a picturebox. and lastly it will clear cTarget for another circle.
    this is inside a loop, so it will render 60 frames a second, but you can easily change that to work with events.

    instead u can use the paint_event and call:
    Code:
        hTarget.BeginDraw
        hTarget.DrawBitmap cTarget.GetBitmap, ResizeRect, 1, InterPolationMode, GameRect
        hTarget.EndDraw ByVal 0&, ByVal 0&
    alone, as cTarget you already created beforehand.

    and if you use
    Code:
    .presentOptions =D2D1_PRESENT_OPTIONS_IMMEDIATELY
    it will draw when u call it instead of the wait-for sync.

    also, important to set the DPI (when u initialize)
    call
    Code:
    cTarget.SetDpi 96, 96
    hTarget.SetDpi 96, 96
    maybe theres other ways, to draw directly into a DC and make it persistent somehow.
    but Im unsure the refresh autoredraw works. unlikely as u have tried that already I assume.

    to render is superfast, so its not that the vb6 autoredraw is faster. contrary slower.

  3. #3
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,417

    Re: Direct2D

    about drawing a part. u can draw to a picturebox, so its not that you need to draw to the form.
    Code:
    HwndRenderTargetProperties.hWnd = .hWnd
    so it can be any hwnd not just to form.

    not sure theres a way to use the form.hwnd and just draw a specific position.
    but at least with a picturebox u can select the left/top position.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    316

    Re: Direct2D

    Thanks Baka, I will have to study a little more about Direct2D there are many things to learn, I appreciate your time
    leandroascierto.com Visual Basic 6 projects

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