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.
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
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?
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.
Using ColorF2 doesnt work. Not sure if im doing it wrong, but this function seems to work for RBG:
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?
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?
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 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.
Last edited by Elroy; May 24th, 2018 at 09:15 AM.
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.
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.
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
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!
I used oleexp typelib to make compatible types (thanks fafalone).
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.
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.
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
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.
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.
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?
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.
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.
Last edited by DEXWERX; May 31st, 2018 at 01:07 PM.
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?).
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).
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)
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?