Update.
Added ID2D1Effect (and some related interfaces) and usage example.
https://www.vbforums.com/images/ieimages/2023/03/1.png
Printable View
Update.
Added ID2D1Effect (and some related interfaces) and usage example.
https://www.vbforums.com/images/ieimages/2023/03/1.png
UPDATE v.2.1
Added several examples with effects (Blur/Blending/3DPerspective/Convolve).
https://www.vbforums.com/images/ieimages/2023/03/2.png
https://www.vbforums.com/images/ieimages/2023/03/3.png
https://www.vbforums.com/images/ieimages/2023/03/4.png
https://www.vbforums.com/images/ieimages/2023/03/5.png
Good job, thanks for sharing, I'm not sure if it's my problem, but I think wicvb.tlb or dwvb.tlb have a problem, did anyone else have problems? I had to use the old tlb, but again, maybe it's a problem in the my record.
so decided to "try" the newer typelib by The trick,
but I can't use it. I get an error using "UUID"
no matter what I do, it seems I need to use the older OLEEXP to make it work.
I can see the UUID in the typelib of the new "Direct2D_V2_10" collection from The trick,
but somehow that UUID that is used by cWicFactory seems to only accept the OLD OLEEXP UUID
The new version doesn't use oleexp at all. It uses only typed declared in the package typelibs. So if you need to use oleexp type definition you could use either oleexp.UUID or D2DVBLib.UUID (it's depending on references priority). You probably could move Direct2D tlb above oleexp in your references list to avoid renaming all the UUIDs.
yeah. it worked!
I did try it before and I got an error, but retrying again and it worked.
most be a conflict when I changed the typelib.
(I now remove all typelibs instead of adding a new one, it seems VB6 like to change the typelib itself)
so apart from that mismatch where the typelib conflicted, I just needed to change IUnknown to IStream
and a few RECT/Point and a couple of API to make it work without OLEEXP.
as such a big project it took me a couple of minutes to change.
I think its best with as little typelib possible, this to prevent issues. :)
this is mostly for the Trick.
I do have some issue with memory leaks, (https://www.vbforums.com/showthread....y-buffer-cache)
so I asked Sage/Poe: https://poe.com
here's the answer:
Quote:
Yes, there is a way to dispose/cleanup Direct2D bitmaps. Direct2D provides a ID2D1Bitmap interface that represents a bitmap image. To release the resources associated with a bitmap, you can call the ID2D1Bitmap::Release method.
You should call the Release method on all Direct2D objects that you create when you are done using them to avoid memory leaks. It's also a good practice to set the pointer to nullptr after releasing the object to avoid using a dangling pointer.
Quote:
Yes, here is an example of how to release a Direct2D bitmap in Visual Basic 6:
but I can't find any "Release" command.Code:Dim bitmap As ID2D1Bitmap ' obtain a pointer to the bitmap
If Not bitmap Is Nothing Then
bitmap.Release
Set bitmap = Nothing
End If
is there a way to do this? or maybe u need to update the typelib?
You don't need to call Release because VB6 automatically calls IUnknown::Release when you set object reference to Nothing or the variable goes out of scope. Your AI just doesn't know how VB6 works.
but there seems to be some memory leaks.
as I wrote in the other thread.
memory usage: mainmenu - map1 - map2 - mainmenu
only software: 52MB - 315MB - 115MB - 110MB
only hardware: 52MB - 315MB - 116MB - 116MB
start hardware: 52MB - change to software - 435MB - 564MB - 352MB - 479MB
start software: 52MB - change to hardware - 54MB - 321MB - 125MB - 114MB
as u can see something is changing when I switch from hardware to software
maybe u know why this is happening? I cleanup using = nothing and set all variables to nothing before I restart the engine and reload.
when I call the "change mode" I exit the game-loop. outside of it. I call Restart.
Init rendertype is just the cFactory/cWicFactory and different RenderTarget creations + brushes creation.
LoadImage/ReLoadDual are the exact same functions I use to load assets.
Code:Sub Restart(Optional rendertype As Byte)
Dim i&
DestroyD2D
Init rendertype
For i = 0 To UBound(Canvas)
If Canvas(i).Filename <> vbNullString Then
Select Case Canvas(i).Mode
Case 0: LoadImage Canvas(i).Filename, Canvas(i).Flip, i
Case 1: ReloadDual Canvas(i).Filename, Canvas(i).Flip, i
End Select
End If
Next i
End Sub
when Restart is done it will enter the gameloop again. nothing else.Code:Private Sub DestroyD2D()
Dim i&
For i = 0 To UBound(Canvas): Set Canvas(i).Bitmap = Nothing: Next i ' Remove All Bitmaps
For i = 0 To UBound(brushes): Set brushes(i) = Nothing: Next i ' Remove All Brushes
Set tTarget = Nothing
Set cTarget = Nothing
Set hTarget = Nothing
Set cWicFactory = Nothing
Set cFactory = Nothing
End Sub
ok I did another test.
when u use "CTRL+ALT+DEL" it will go to login-page. when u return to desktop the direct2d need to restart. and when it do, it will use the EXACT same reload function.
but this time the memory is unchanged. in any maps it will return and reload it to the same memory-usage.
ONLY when I change between hardware > software this happens.
is it possible to update your typelib adding
WICBitmapInterpolationMode
typedef enum WICBitmapInterpolationMode {
WICBitmapInterpolationModeNearestNeighbor = 0,
WICBitmapInterpolationModeLinear = 0x1,
WICBitmapInterpolationModeCubic = 0x2,
WICBitmapInterpolationModeFant = 0x3,
WICBitmapInterpolationModeHighQualityCubic = 0x4,
WICBITMAPINTERPOLATIONMODE_FORCE_DWORD = 0x7fffffff
} ;
so we get WICBitmapInterpolationModeHighQualityCubic as well?
the idea is that if u are using windows 10 u get that option unlocked.
I tried using "4" but it didnt work, the person in windows 10 told me it was identical to 3 (I get the same result in windows 7, 4 is like 3)
asked Poe and he told me:
When you use a typelib in your VB6 project, the values of the enumeration are determined by the typelib itself and not by the underlying operating system. Since the typelib was created before the addition of WICBitmapInterpolationModeHighQualityCubic, it doesn't have knowledge of that value.
When you compile your executable and run it on Windows 10, the typelib is still the same and doesn't magically update with new values. Therefore, when you specify "4", the VB6 runtime interprets it as an unrecognized value and likely falls back to a default behavior,
now sure if its possible to do.
happy new year
VB6 has no problem using 4 (or "4") as enum value because you can use integer variables and literals instead of enum variables and literals anywhere in code without even a warning from the compiler.
The one not recognizing 4 as an interpolation mode is likely win7 impl of D3D which falls back to its default interpolation mode.
Btw, you can easily "fix" the issue (if typelib update is not avaiable) by simply declaring Public Const WICBitmapInterpolationModeHighQualityCubic As Long = 4 somewhere in a standard module of your project.
cheers,
</wqw>
That part is right.
That part is wrong. VB6 does not perform any validation over enums, whether a value corresponds to an emun member or not.
An enum is just a Long, nothing else.
Enums are a set of constants (type Long) put together. And a constant is a named value, just to help the programmer 1) with intellisense and 2) because in the name itself there is usually some 'explanation' of what it does.
But an enum (or a constant type Long) is just a Long value expressed by a name rather than a number, that is converted to a number on compilation, and the program (function in a DLL) receiving that number does not know whether that Long number was originally generated by a constant, an emun, a literal number, an Hex expression (&H4), a variable read from a file, or whatever. The value is received as a Long, and that's it.
To avoid any issue pass your literal ByVal and with the & at the end:
Code:... , ByVal 4&, ...
I talked to fafalone and I will do some testing to make 100% sure. I have the trick typelib, fafalone typelib and an edited-typelib (fafalones) without the 4th enum.
will make a small project that will use the 3 typelibs.
will use byval 4& as u say as well.
Is there a specific reason why changing from hardware to software mode triggers a change in memory usage, while other scenarios, like switching from hardware to software after using "CTRL+ALT+DEL," show consistent memory behavior? Additionally, have you explored alternatives or additional cleanup methods to address the memory fluctuations when switching modes?
Well when you use hardware acceleration some stuff is put in the memory of your graphics card. With software rendering it's all in system memory.
If anyone is interested, I've ported all of the The trick's samples from Direct2D_V2_10.zip to 64bit compatible twinBASIC projects, using WinDevLib instead of several typelibs, exploiting tB's ability to use Implements on derived interfaces and As Any arguments, among others.
https://github.com/fafalone/D2DSamples - Ports of The trick's Direct2D examples
Huge thanks to The trick, these are great learning resources. I of course left all the credits to him in the projects.
Thank you so much fafalone! I can't give reputation because forum requires spreading to another user.