Results 1 to 10 of 10

Thread: User Control Similar to Picturebox but using DirectX Render

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2020
    Posts
    63

    Question User Control Similar to Picturebox but using DirectX Render

    Hi, I've been meaning to ask this question for a while, because in my experience with vb6 I've never been good at rendering graphics with DirectX, there are plenty of examples on the internet but they're really so long in lines of code that it's a bit confusing.

    I've always used a PictureBox and PaintPicture to get by, and I think it's the easiest way for me to generate graphics and animate them with code in a way that's easy to understand, but in terms of performance when running the application, it's extremely inefficient with resources, especially at larger scales. That's why I'd really like to ask for your help.

    I'd like to create a UserControl that does this task as if it were a PictureBox with the method similar to PaintPicture, but that actually uses DirectX technology so that the graphics processing is actually done by the GPU.

    I share with you an example of what the programming logic that I follow would be like using PaintPicture, but I would love to achieve this with any version of DirectX that the vb6 IDE supports.


    Thanks guys!
    Attached Files Attached Files
    Last edited by Maatooh; Mar 5th, 2025 at 04:33 PM.

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: User Control Similar to Picturebox but using DirectX Render

    You should look at the samples The trick made for his Direct2D typelib (which is also available with oleexp.tlb along with WIC, which is used in some demos).

    https://www.vbforums.com/showthread....=1#post5597152

    Of course everything is easier in tB and I've ported all of the samples to tB/x64 compatible with my WinDevLib package.

    https://github.com/fafalone/D2DSamples

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: User Control Similar to Picturebox but using DirectX Render

    This is actually an excellent idea. It wouldn't be a trivial thing though. If we just specified that everything was in pixels, it wouldn't be too bad. However, one of the very nice features of the PictureBox is its ability to have custom ScaleModes, or to use any of the other "known" measurement units. Implementing all of that would take a bit of work.

    I'm wondering if a first pass using the GdiPlus wouldn't be a better approach. It doesn't really leverage the GPU, but do we really need that for 2D stuff? The GdiPlus would offer much smoother lines and it does have enhanced curve drawing abilities.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2020
    Posts
    63

    Post Re: User Control Similar to Picturebox but using DirectX Render

    It seems that the best way is Direct2D, without knowing this I was basing myself without much success on this example made in dx8.

    Even so, please clarify my doubt, what technology should be more optimal in terms of rendering performance, more compatible with Windows from XP to W11, advantages, etc.?
    Something that allows for example to make 2D video games with the widest range of possibilities for vb6.

    Thanks you!

    DXTut - Advanced Animation.zip

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: User Control Similar to Picturebox but using DirectX Render

    DirectX 11 and 12 are probably the best options; that's what the demos I linked used.

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: User Control Similar to Picturebox but using DirectX Render

    I took a look at it, and it'd just be more work than I want to get into right now. But, if you're wanting to pursue this, Fafalone absolutely pointed you in the correct direction by suggesting The Trick's work.

    I'm curious why we need to leverage the GPU for 2D work.

    If we're just wanting smoother lines and ellipses, it would seem that GdiPlus would be the way to go. And doing that, we also get things like PNG and other image formats to which we can save/load, as well as a host of other image manipulation features. If you want to see what the GdiPlus can actually do, Tanner Helland's PhotoDemon project (think PhotoShop, but all written in VB6) is an incredible project, and has all the VB6 source code available. There are also many other examples of GdiPlus usage on these forums, including a few by me, with this one being relatively simple.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: User Control Similar to Picturebox but using DirectX Render

    Quote Originally Posted by fafalone View Post
    DirectX 11 and 12 are probably the best options; that's what the demos I linked used.
    Personally, I'd go with DX9 (if I was insistent upon doing this with DX), primarily because The Trick has the TypeLib for all the calls and enumerations all worked out.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  8. #8
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: User Control Similar to Picturebox but using DirectX Render

    The post I linked to was The trick's post for his newer typelib (available via oleexp.tlb as well). Direct2D uses dx11 on win8+, dx10 on 7.

    Direct3D isn't ideal for 2d but oleexp fully covers 11 and 12. And DXGI, DirectComposition, DirectWrite.

  9. #9
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: User Control Similar to Picturebox but using DirectX Render

    Quote Originally Posted by fafalone View Post
    The post I linked to was The trick's post for his newer typelib (available via oleexp.tlb as well). Direct2D uses dx11 on win8+, dx10 on 7.

    Direct3D isn't ideal for 2d but oleexp fully covers 11 and 12. And DXGI, DirectComposition, DirectWrite.
    Yeah, my primary experience is with Direct3D, where I wrote some VB6 code to model MOCAP data. Never really used Direct2D much at all. So, I appreciate the correction.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  10. #10

    Thread Starter
    Member
    Join Date
    Oct 2020
    Posts
    63

    Post Re: User Control Similar to Picturebox but using DirectX Render

    I think I'll give up guys, I wasn't successful with the dependencies you recommended, maybe I didn't know how to register them properly and I was intimidated by the large amount of code lol. Anyway, I continued with dx8vb.dll which apparently didn't present many problems and finally with some inefficient help (AI) I think I got to a point of progress, although I didn't manage to render what I needed, anyway I'm sharing it with you in case you want to give me some help, it seems that this approach simply seeks to create an image buffer and then try to render it with directx.

    Name:  needdirectx.jpg
Views: 913
Size:  23.0 KB

    I think it's certainly not the most appropriate, and the truth is that for something 2D the only thing I'm looking for is that a low-resource PC doesn't have too many resource consumption problems and doesn't experience graphic lag, thinking about creating video games with it since this paintpicture methodology seems to me the easiest.

    Thanks guys!

    DirectXBox.zip

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