-
Re: Direct2D Typelib+ for VB6
awesome! thx a bunch The trick!
I will create a new project using direct2d and see if i can re-create the game im doing in gdi. I will post the progress.
not sure whats best, you should discuss and see whats the best approach for this. maybe cooperate?
no matter what i appreciate you both taking your time for it.
-
Re: Direct2D Typelib+ for VB6
ok, Im now trying the typelib.
the first thing is cRenderTarget.DrawBitmap
It says: destinationRectangle as any but the type used in the demo is D2D1_SIZE_F that contains width and height, shouldn't it be D2D1_RECT_F instead?
it seem to work with either so maybe it doesnt matter?
another parameter is interpolationmode and I can choose between 3 (dword, linear and nearest_neighbor)
is there a way to not use any interpolation at all? when not resizing i would not want any interpolation.
linear seems to be the best quality, what kind of interpolation is that? bilinear? bicubic? not sure what dword is but i can't use it, creates an error.
as I have a Long value for the background color I need either RGB or RGBLong.
Using ColorF2 doesnt work. Not sure if im doing it wrong, but this function seems to work for RBG:
Code:
Private Function RGBa(ByVal R&, ByVal G&, ByVal B&, Optional ByVal Alpha! = 1) As D2D1_COLOR_F
With RGBa
.R = R / 255!
.G = G / 255!
.B = B / 255!
.a = Alpha
End With
End Function
for Long I just do:
Code:
Private Function RGBL(ByVal Lng&, Optional Byval Alpha! = 1) As D2D1_COLOR_F
Dim R&, G&, B&
B = Lng \ 65536
G = (Lng - B * 65536) \ 256
R = Lng - B * 65536 - G * 256
RGBL = RGBa(R, G, B, Alpha)
End Function
-
Re: Direct2D Typelib+ for VB6
Quote:
It says: destinationRectangle as any but the type used in the demo is D2D1_SIZE_F that contains width and height, shouldn't it be D2D1_RECT_F instead?
What's the demo exactly?
Quote:
another parameter is interpolationmode and I can choose between 3 (dword, linear and nearest_neighbor)
is there a way to not use any interpolation at all? when not resizing i would not want any interpolation.
If you don't transform the image it doesn't affect. When you rotate/scale/skew - it affects (see ImageDrawings demo). dword - is not mode.
Quote:
Using ColorF2 doesnt work. Not sure if im doing it wrong, but this function seems to work for RBG:
It's work with &HAARRGGBB.
-
Re: Direct2D Typelib+ for VB6
demo: ImageDrawings, in Form_Load() you use D2D1.SizeF(100,100)
right now my project is using 1 picture (1024x579) that is a background with clouds.
I use the DrawBitmap function to create a moving animation that will loop the image, copying 800x579.
the animation works, but theres still stuttering every 1½ seconds. sure im just using a timer right now so its not 100% accurate.
so, now with Direct2D, what is the best way to render and to prevent stuttering?
-
Re: Direct2D Typelib+ for VB6
baka, i use SizeF in CreateCompatibleRenderTarget that accepts D2D1_SIZE_F.
Quote:
I use the DrawBitmap function to create a moving animation that will loop the image, copying 800x579.
the animation works, but theres still stuttering every 1½ seconds. sure im just using a timer right now so its not 100% accurate.
so, now with Direct2D, what is the best way to render and to prevent stuttering?
Usually a game use a loop.
-
Re: Direct2D Typelib+ for VB6
The trick i was thinking about waitforvblank or VSync.
I read in a forum about calling "IDXGIObject" to access WaitForVBlank, that is called before EndDraw to sync with the monitor.
here's a "test" project (source code).
even when compiled theres some "stuttering".
https://www92.zippyshare.com/v/XJgUVYNZ/file.html
I will use a loop when I figure out things. but the timer should be enough accurate for just 1 picture.
-
Re: Direct2D Typelib+ for VB6
Baka,
Here's the code for my TimerEx also. It uses the QueryPerformanceCounter & QueryPerformanceFrequency for a much more accurate timer than VB's Timer() function. I've given it to you in Notepad (rather than just the code from the IDE) form so you can get the VB_PredeclaredId = True and Attribute Value.VB_UserMemId = 0 settings. Just put it into a .CLS module with Notepad, and then add to your project. No need to declare any object variable, or anything. Just use TimerEx like a new function in the language.
This will help if you use a Loop rather than a timer event for your frames. I just put this in my loop to make it run at the desired speed. It completely eliminates any pauses caused by VB's slow timer control.
Code:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "TimerEx"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'
' This class has VB_PredeclaredId = True.
' Also, the Value is set to the default property.
' Therefore, TimerEx will just act like a new built-in function.
' No need to declare an object variable or explicitly instantiate.
'
Option Explicit
'
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
'
Private cFreq As Currency
'
Private Sub Class_Initialize()
QueryPerformanceFrequency cFreq
End Sub
Public Function Value() As Double
Attribute Value.VB_UserMemId = 0
' Must be Public (not Friend) so we can set default property.
' Returns seconds, a double, with high-precision.
' Caller is responsible for keeping track of start/stop times.
' Basically, it works exactly like the built-in Timer function, but with much more precision.
Dim cValue As Currency
QueryPerformanceCounter cValue
Value = cValue / cFreq ' The division will return a double, and it also cancels out the Currency decimal points.
End Function
Best Of Luck,
Elroy
EDIT1: Also, the units returned by TimerEx is seconds, but it's a Double and very accurate with the use of the Double's decimal points.
EDIT2: And just to say it, I'd save the value for TimerEx at the beginning of rendering one of your cloud frames, do the rendering, and then fall into a loop, waiting for the appropriate amount of time to expire, looking at your saved time value and comparing it against more calls to TimerEx.
-
Re: Direct2D Typelib+ for VB6
thx Elroy, but this "test" project is just to figure out the stuttering, I do have a loop in my other game, not vb6.timer.
in my Gdi32 project I also get stuttering when I go below 100fps, that because I don't have any means to get the exact moment the monitor refreshes, that is why Im asking if we can do differently with Direct2D, otherwise I have the exact same problem with Direct2D I have with Gdi32.
no matter how precise the timer is, theres no point when we can not sync.
in my Gdi32 project, I refresh so many times that we don't notice that its not in-sync. that is why when I reach 125fps, I don't see any stuttering, its quite smooth, but still is very bad optimized and a waste of cpu.
even if we can not get any sync with Direct2D its better then Gdi32 anyway, the auto-size feature is quite neat, I dont need to do anything, Direct2D is doing it automatically, I just need to adjust the x/y mouse and thats it.
-
Re: Direct2D Typelib+ for VB6
baka, Direct2D has option D2D1_PRESENT_OPTIONS where you can specify v-synch.
You can use loop like this:
Code:
Private Sub Form_Load()
Me.Show
Set D2D = New direct2d
D2D.LoadImage App.Path & "\back1.png"
bIsRunning = True
Do While bIsRunning
D2D.Render
DoEvents
Loop
End Sub
-
Re: Direct2D Typelib+ for VB6
nice! thx for explaining that. i dont even need to do any fps-measurements now.
is there a return variable to get the vsync rate?
I read in a forum that Direct2D uses vsync, and if used on a laptop the sync could change from 60fps to 30fps to save power.
if going slower I also need to know how fast so that I can adjust the speed of the animations.
I could get it using a timer, but if theres a parameter for it, i would save me time making one! :)
-
Re: Direct2D Typelib+ for VB6
Just use a timer like Elroy suggested and get time difference between two frames.
-
Re: Direct2D Typelib+ for VB6
ok. i will add the timer , i need a timer anyway as i use a "timer" in-game as i need to calculate seconds. not a big deal. thanks :)
-
1 Attachment(s)
Re: Direct2D Typelib+ for VB6
Updation.
Added DirectWrite interfaces (Win7).
Examples:
Text basic drawing;
Font families enumeration;
Inline object implementation example;
Custom text renderer implementation.
https://s8.hostingkartinok.com/uploa...59ca361c5d.png
https://s8.hostingkartinok.com/uploa...5e195d4712.png
https://s8.hostingkartinok.com/uploa...caa468f132.png
-
Re: Direct2D Typelib+ for VB6
So, some samples depend on OLEEXP - olelib With Modern Interfaces by fafalone, v4.3 as far as I can see.
Can it be internalized by any of the *four* typelibs that come in the zip?
cheers,
</wqw>
-
Re: Direct2D Typelib+ for VB6
wqweto,
Quote:
Originally Posted by
The trick
I don't want to use the internal definitions of the UDTs and the interfaces because in that case we can't assign the same types defined in the different typelibs.
-
Re: Direct2D Typelib+ for VB6
Quote:
Originally Posted by
The trick
wqweto,
I don't want to use the internal definitions of the UDTs and the interfaces because in that case we can't assign the same types defined in the different typelibs.
You can both assign equal GUIDs to UDTs to create compatible structs. Assignment in VB6 should work across typelibs, although personally never tested it.
cheers,
</wqw>
-
1 Attachment(s)
Re: Direct2D Typelib+ for VB6
Quote:
Originally Posted by
wqweto
You can both assign equal GUIDs to UDTs to create compatible structs. Assignment in VB6 should work across typelibs, although personally never tested it.
cheers,
</wqw>
Won't work.
Code:
Sub Main()
Dim t1 As tlb_01.s1
Dim t2 As tlb_02.s1
t1 = t2 ' // Type mismatch
test_sub t1 ' // ByRef argument type mismatch
End Sub
Sub test_sub( _
ByRef t As tlb_02.s1)
End Sub
-
Re: Direct2D Typelib+ for VB6
Pity! A very unfortunate shortcoming of the current compiler and a feature request for vNext.
cheers,
</wqw>
-
Re: Direct2D Typelib+ for VB6
We can use LSet to copy:
Anyway, we can't pass it to a function.
-
Re: Direct2D Typelib+ for VB6
hello, im back from a weekend trip. thanks for the DirectWrite, Its essential so its much appreciated.
2 things:
1
the demos, I can't make work: CustomRenderer
I get error: Compile Error, Error in Loading DLL and I get that from "Dim cCustRender As CRenderer"
everything else works.
2
I use AddFontResourceEx to add a custom fonts in GDI. is there a equivalent in DirectWrite?
googling I found this: https://stackoverflow.com/questions/...ile-at-runtime
but Im unsure how to do it!
-
Re: Direct2D Typelib+ for VB6
1. Can you please provide screenshot? What dll exactly?
2. It isn't implemented yet. The article how to do it here.
-
1 Attachment(s)
Re: Direct2D Typelib+ for VB6
Quote:
Originally Posted by
The trick
1. Can you please provide screenshot? What dll exactly?
2. It isn't implemented yet. The article how to do it
here.
in my system win7 32 chinese . have error
can you fix?
Attachment 159365
-
Re: Direct2D Typelib+ for VB6
Progress.
xxdoc123, baka there is the bug in Direct2D on some OS.
ID2D1GeometrySink inherits ID2D1SimplifiedGeometrySink but if you call QueryInterface(ID2D1GeometrySink, IID_ID2D1SimplifiedGeometrySink) it raises the type mismatch error. I've fixed that error by manually casting types.
-
Re: Direct2D Typelib+ for VB6
questions:
Im trying to use 2 render hwnd.
one I call cTarget and is set to be rendered in picturebox1
and the other cTargetSys on picturebox2
I have tried with different approaches but always giving me the error: automation error (runtime error "-2003238891" (88990015)
first I render cTarget first, using the .presentOptions = D2D1_PRESENT_OPTIONS_NONE, with begin to end.
after that I call cTargetSys, that i using .presentOptions = D2D1_PRESENT_OPTIONS_IMMEDIATELY to make it immediately.
but I get the error.
are there any way to 2 hwnd or do I need to make it on 1 hwnd only?
-
Re: Direct2D Typelib+ for VB6
Attach the project please.
-
Re: Direct2D Typelib+ for VB6
here the source: https://www80.zippyshare.com/v/RywqEggN/file.html
i also use a typelib (custom) that includes a bunch of API im using. i added the ODL if you want to look into it.
-
1 Attachment(s)
Re: Direct2D Typelib+ for VB6
Updation.
Fixed bug with "Compile Error, Error in Loading DLL".
Added example with embedded fonts collection.
https://s8.hostingkartinok.com/uploa...d1eea3cf53.png
-
Re: Direct2D Typelib+ for VB6
baka you use the resources from different render target (D2DERR_WRONG_RESOURCE_DOMAIN). You should use either the compatible resources (bitmaps created by the same render target) or use D2D1_RENDER_TARGET_TYPE_SOFTWARE flag.
-
Re: Direct2D Typelib+ for VB6
review of the latest build:
- SaveImage
try to run or make I get:
Unexpected error (32810)
at "Private Sub Form_Load()"
everything else works! the old errors are fixed. also, I can change the target flag to either SOFTWARE or HARDWARE and both works! :D
-
Re: Direct2D Typelib+ for VB6
Quote:
try to run or make I get:
Unexpected error (32810)
at "Private Sub Form_Load()"
Please show the screenshot.
-
Re: Direct2D Typelib+ for VB6
original: https://postimg.cc/gallery/3geeungqk/
Attachment 159389Attachment 159391
also, the demo CustomFont loads from the resource file, how to load from external file?
-
Re: Direct2D Typelib+ for VB6
baka, i can't produce that error on all my VM.
Quote:
also, the demo CustomFont loads from the resource file, how to load from external file?
It doesn't matter you can load it to a byte array from a file instead the resources.
-
Re: Direct2D Typelib+ for VB6
Here's a harder one, save an image from a render target using Windows 7 interfaces. (MSDN only shows the windows 8+ interfaces)
edit: also thanks for all the hard work on this Trick. I won't be releasing a typelib for a long time. If I do it will most likely be a large all in one typelib, including all of DirectX, sort of like SharpDX/SlimDX for VB6.
-
Re: Direct2D Typelib+ for VB6
Quote:
Originally Posted by
The trick
Still shows error "load dll error"
-
Re: Direct2D Typelib+ for VB6
Quote:
Still shows error "load dll error"
You should either replace tlbs or re-register them.
-
Re: Direct2D Typelib+ for VB6
Quote:
Here's a harder one, save an image from a render target using Windows 7 interfaces. (MSDN only shows the windows 8+ interfaces)
Yes, but CreateWicBitmapRenderTarget works since Vista SP2. It's look like a compiler error (bug?).
Quote:
also thanks for all the hard work on this Trick. I won't be releasing a typelib for a long time. If I do it will most likely be a large all in one typelib, including all of DirectX, sort of like SharpDX/SlimDX for VB6.
Okay, then maybe i'll post that sources on CodeBank (after i add comments, fix bugs, and make more examples).
BTW, i accept the suggestions for the new demos.
-
Re: Direct2D Typelib+ for VB6
what kind of termination/unload should be applied for direct2d?
right now I just use Set variable$ = Nothing.
the same when I unload a picture, and re-use the bitmap, as :
Set Image(0) = LoadImageEx(Filename) that is a ID2D1Bitmap
and when Im unloading it I use:
Set Image(0) = Nothing
is this enough of do I need to do more?
I notice that direct2d is not stable in IDE. if Im running a few times and do some changes in the project (like adding a picturebox) the IDE can crash (need to save the project before running)
-
Re: Direct2D Typelib+ for VB6
baka, i don't know the reason why you have the crashes. If you provide me the project caused the crash i can see.
-
Re: Direct2D Typelib+ for VB6
ok, just run it once in IDE, click the "X" to quit, and add a textbox anywhere and run again. it will crash.
https://www30.zippyshare.com/v/FwjwVIvf/file.html
but if you run it again without adding anything it will run without crashing.
that is why im asking if there a termination/unload procedure.
-
Re: Direct2D Typelib+ for VB6
I asked in one of my previously post about the refresh rate, since D2D1_PRESENT_OPTIONS is following the monitor refresh-rate, i think its useless to calculate fps.
sure, the fps could fluctuate a bit, but nothing i want to monitor, the user need to take responsibility to not overuse the cpu/gpu when running the game, or change the refresh rate during play.
the easiest way is to use the API GetDeviceCaps with the parameter VREFRESH.
it's working on my machine and im running windows 7.
my questions, is this compatible with all windows version, also 10? any other method that can be used?