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!
Last edited by Maatooh; Mar 5th, 2025 at 04:33 PM.
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).
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.
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.
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.
Re: User Control Similar to Picturebox but using DirectX Render
Originally Posted by fafalone
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.
Re: User Control Similar to Picturebox but using DirectX Render
Originally Posted by fafalone
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.
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.
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.