-
Direct2D Typelib+ for VB6
in the other thread: GDI+ Load Png + Resize dilettante mentioned Direct2D IDL/TLB,
DEXWERX also answered that it shouldn't be that hard to do, but wonders if theres any interests in doing one at all. He also says its "very simple" API.
well, I would really like one and for me its not easy at all as I don't even know where to start and how the functions/API looks like.
so, what say, is this possible? any other would like to play with Direct2D in VB6?
-
Re: Direct2D Typelib+ for VB6
Hi baka,
I'm a bit out of my depths here, but I'm going to jump in anyway. And here are understandings/expertises I do have:
- I'm not too bad at Linear Algebra (particularly when it comes to objects in 3D space). As such, I could do everything I need without DirectX, but it'd be much slower and much more involved. And displaying graphics and animations on the screen, directly using our graphics accelerators, is what DirectX is all about.
- I've developed a decent project using DirectX using DX8.
- It's my understanding that the API for DX8 is directly accessible via VB6 (i.e., no TypeLib needed). Also, all that's required to use it is to place the Dx8vb.dll in the same path as your executable (i.e., no registration necessarily required).
- It's my understanding (but not entirely sure) that something changed (possibly the calling conventions) about DX9 and beyond that makes the APIs impossible to directly call from VB6.
- I've been contemplating a couple of DX projects, but both of mine will probably use Direct3D rather than Direct2D, but stepping back to Direct2D should be fairly easy once Direct3D is understood. I'll probably start the beginnings of one of those projects today, probably leaning on my knowledge of DX8. I may start another thread to assist with getting advice on that project.
Take Care,
Elroy
EDIT1: And, just to say a bit more about the one project using DX that I have developed. It was a static project with a dynamic camera. As such, I didn't worry about frames or FPS (frames-per-second). The two projects I'd like to work on in the future both involve both dynamic frames (along with a FPS setting) and a need for a dynamic camera (able to change perspective, zoom & pan).
-
Re: Direct2D Typelib+ for VB6
To do everything you want you might also need DirectWrite and Windows Imaging Component (WIC).
-
Re: Direct2D Typelib+ for VB6
I will follow that thread Elroy, and I do hope it will be "noob" friendly as im clueless when its about DirectX. those matrix things confuses me a lot and the different calls to "initialize" the screen/engine is hard to grasp.
Dilettante, yeah, I did a search and found out that TextOut equivalent is DrawText (using DirectWrite) and loading bitmap we need to use WIC,
but I also read that it is possible to combine GDI and Direct2D, so we could use GDI/GDI+ to load and we can use the GDI DC. so we can render directly into a DC from Direct2D.
now, Im not sure if thats good or bad, but I do like the options to use both.
-
Re: Direct2D Typelib+ for VB6
Ooooor you can talk to me about DirectX, as I'm an expert at it :bigyello:
I have tons of DX VB6 stuff in my signature, including the infamous Massive DirectX Tutorial. But to be honest, with VB6, it only gone as far as DirectX8. Even the .NET languages are stuck with DirectX9. We have DirectX12 now, which is why I switched to C++. But even then, DirectX12 only works on Windows10 computers, and won't work on Windows7, which is why I do DirectX11 instead. But if you do ever decide to make the leap to DirectX11, you will no longer be stuck in the fixed graphical pipeline. Everything you do will now require shaders, so you will need to learn the HLSL language (high level shading language). Its not hard once you learn about vertex shaders and fragment shaders. And you will now have more control over how your polygons are drawn, 2D and 3D. Also the entire syntax of DX11 is different, and makes use of what is called "swapchains." With that said, the D3DX library is now deprecated! So you will have to write your own math functions and use the DirectXTK library to do simple things such as texture mapping.
-
Re: Direct2D Typelib+ for VB6
the reason Im not using directx is that im working with 2D, I need functions that are similar to gdialphablend that allow me to use raster png's and copy/paste parts of a bitmap into a memory device context and later render it all into a picturebox.
so the idea is:
have a memory device context: say 800x600
clear it
a loop that will copy a number of 32bit bitmaps into that context, any rect allowed and opacity.
a number of "textout" with different fonts and sizes.
the final render to a picturebox
and repeat
i can do this quite easily and fast with GDI. but once i apply any filters or resize algorithms the fps is getting extremely low.
when I tried directx, for different sources, even your tutorial i just get confused, I coudln't load a simple png and render it, theres matrix that i need to work with but changing them resulted in 3d effects or strange shapes.
also, i think its nice if VB can use Direct2D as well!
-
Re: Direct2D Typelib+ for VB6
DirectX isnt that hard at all. Its a small learning curve, but once you are pass that, you can do so much so fast. Take my "Your First DirectX Window Application" for example
vb Code:
'---------------------------------
'Title: DirectX Tutorial
'
'Description: This is your first DirectX8 application.
' I made it to where this is the easiest
' method to initialize and render. No
' extra subs/functions, no error handling,
' no modules/classes, no nothing. It can't
' get any easier than this, and makes it easy
' for any beginner to understand.
'
'Author: Jacob Roman
'
'Date: 12/01/2005
'
'---------------------------------
Option Explicit
Private DirectX8 As DirectX8 'The master DirectX object.
Private Direct3D As Direct3D8 'Controls all things 3D.
Private Direct3D_Device As Direct3DDevice8 'Represents the hardware rendering.
Private Running As Boolean 'Helps determine whether the main game loop is running.
Private Sub Form_Activate()
frmMain.Caption = "DirectX Tutorial"
Dim Display_Mode As D3DDISPLAYMODE 'Display mode desciption.
Dim Direct3D_Window As D3DPRESENT_PARAMETERS 'Backbuffer and viewport description.
Set DirectX8 = New DirectX8 'Creates the DirectX object.
Set Direct3D = DirectX8.Direct3DCreate() 'Creates the Direct3D object using the DirectX object.
Direct3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, Display_Mode 'Use the current display mode that you
'are already on. Incase you are confused, I'm
'talking about your current screen resolution. ;)
Direct3D_Window.Windowed = True 'The app will be in windowed mode.
Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC 'Refresh when the monitor does.
Direct3D_Window.BackBufferFormat = Display_Mode.Format 'Sets the format that was retrieved into the backbuffer.
'Creates the rendering device with some useful info, along with the info
'we've already setup for Direct3D_Window.
Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Direct3D_Window)
Running = True 'Initializations all set. It's now ok to activate the game loop.
Do While Running = True
DoEvents 'Allow events to happen so the program doesn't lock up.
'----------------------------------------------------
'DirectX automatically handles the framerate for you
'which makes it run (at most) as fast as the monitors
'refresh rate, so you don't need to add extra code to
'slow down the loop and run at a certain number of frames
'per second.
'----------------------------------------------------
'Clears the backbuffer.
Direct3D_Device.Clear 0, ByVal 0, D3DCLEAR_TARGET, D3DColorRGBA(0, 0, 0, 0), 1#, 0
'Rendering code goes here, but in this tutorial, it will be empty for now.
'Flips the backbuffer into the form window.
Direct3D_Device.Present ByVal 0, ByVal 0, 0, ByVal 0
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer)
Running = False 'Helps the program bail out of the game loop.
'Unload all of the DirectX objects
Set Direct3D_Device = Nothing
Set Direct3D = Nothing
Set DirectX8 = Nothing
Unload Me 'Unload the form
End 'Ends the program
'Although the Unload statement located above exits the program, you
'will end up with an Automation error after doing so. The End statement
'will help prevent that, and end the app completely.
End Sub
Since DirectX handles the framerate automatically for you, and does everything hardware, you don't have to worry about "low framerate". I have everything heavily commented to explain what everything does line by line. But if you do not want to run inside a window, and run inside a picturebox instead, change this
Code:
Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Direct3D_Window)
to this
Code:
Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, PictureBox1.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Direct3D_Window)
And DirectX allows you to do some awesome things that Windows GDI is incapable of, such as these 3 games I made, all on VB6!!!
http://www.vbforums.com/attachment.p...1&d=1319869928
http://www.vbforums.com/attachment.p...1&d=1112831035
http://www.vbforums.com/attachment.p...1&d=1369318780
-
Re: Direct2D Typelib+ for VB6
Baka,
I suspect you need to get the concepts of a 2D Transformation Matrix under your belt. Here's a link to a particularly helpful figure. Understanding the underlying geometry (particularly in 3D) can get complex, but it's not too bad in 2D. However, once it's all transformed into a matrix, you really don't even need to know the geometry. Just do what that figure tells you to do.
Good Luck,
Elroy
-
2 Attachment(s)
Re: Direct2D Typelib+ for VB6
Yeah, the "bonehead UserControls as sprites" approach burns a lot of cycles and isn't very flexible. For gaming you are better off using one of the drawing libraries intended for the purpose.
Here the "bugs" just crawl around the edges of the Form. I didn't bother to rotate them as their travel orientation changes.
Attachment 158771
-
Re: Direct2D Typelib+ for VB6
thx for all the suggestions and samples, i still want to see if its possible to make a Direct2D Typelib.
using DirectX8 could be an alternative, while GDI+ is too slow for my needs, that is why im using StretchBlt, BitBlt and AlphaBlend.
that is quite helpful Elroy, if im gonna dig into dx8 or dx9 i will use that so the image will show correct.
-
Re: Direct2D Typelib+ for VB6
Hi baka,
Yes, I'm trying to cobble together a DX8 project right now. It's just taking me a bit to get back up to speed with this stuff. You don't need a Typelib with DX8. Under the VB6 IDEs references, just explore to a copy of Dx8vb.dll, and you're all set. Worst case, just make sure that DLL is in your project's VBP folder, and then make sure the following line is near the top of your VBP file:
Code:
Reference=*\G{E1211242-8E94-11D1-8808-00C04FC2C603}#1.0#0#dx8vb.dll#DirectX 8 for Visual Basic Type Library
And then, you can start using the object browser (F2) to explore that DLL's abilities. However, DirectX can be somewhat overwhelming, possibly more so than even GDI+. That's why examples of how to do things is of paramount importance.
Also, just to say it, I'm not sure I see DirectX and GDI+ as terribly similar. Sure, they both render and display images. However, the GDI+ is truly meant to display those images in such a way that they can be edited and manipulated in a variety of ways. And, I think the big advantage that GDI+ brings to the table (as opposed to GDI32), is that it truly handles the alpha layer correctly. Although, it's my understanding that DirectX also handles alpha correctly, possibly in a much more complex way than either GDI32 or GDI+, in that it considers everything behind the object when working out the translucency and the actual color of each pixel.
Now, I see DirectX as having a different purpose. Of the three (GDI32, GDI+, & DirectX), it's the only one (AFAIK) that makes full use of whatever GUI accelerator hardware we have. And, as such, it's really designed to be a "display" tool, as opposed to an "editing and image manipulation" tool. Sure, you can paint textures (i.e., images) on DX objects. And then, you can rotate and scale these objects, and their textures will rotate and scale with them. However, I don't think you could do brightness, gamma, color corrections and other adjustments to these textures-on-objects. Also, I'm not sure how you'd re-read a texture from an object's face (especially maintaining the way it's scaled and oriented). I suppose you could just read the pixels off the screen's DC, but hmmm.
However, I'm not the guru on these things. Maybe DirectX is the correct tool for your needs.
Good Luck,
Elroy
-
Re: Direct2D Typelib+ for VB6
Read this, and you will see why it's best to jump off the GDI bandwagon:
http://www.vbforums.com/showthread.p...47#post4420647
-
Re: Direct2D Typelib+ for VB6
I thought he explained he was making twitch games, not an image processing tool or even just a dollied up gauche UI. But maybe I misinterpreted his other thread.
-
Re: Direct2D Typelib+ for VB6
@Dilettante: You may be correct. I just scanned the other thread, and I don't see where the purpose is well outlined.
@Baka: Yes, if you're designing some kind of "game", you'd probably do best to learn DirectX. I'll go ahead and get my other thread started, but it's still in the process of "coming to life."
Best Regards,
Elroy
-
Re: Direct2D Typelib+ for VB6
please read OP, this thread is not about my game, but a question and a proposition to create a typelib for Direct2D.
of course i will use it for my needs, why not? i started this thread because of the discussion of Direct2D started by Dilettante and also the posts by DEXWERX.
I want to keep this thread about that and not about my game or any other solutions, even if welcome, i really want to stick with the OP question.
the idea of using DX8 could be useful and I will explore that "BUT" its not what this thread is about, its better we start a new thread about DX8, and I will go and participate to the new thread Elroy created.
so, back to OP, what say about Direct2D? I would love to see a typelib for that and why not? we do love VB6 and more we have better it is and im sure others out there if they knew there where a Direct2D typelib they would even consider returning or even starting using VB6.
and my game is a 2D platform game using 5 layers, with background animations, effects, animated creatures and npc and so on. the screen is constantly changing with multiple animation working in the background creating depth and distance. it is set to 125fps default but i can easily go up to 250fps without problems. my somehow middle range computer i can go up to 500fps but in some places it can be a bit laggy.
the game works fine with low-end computers where fps goes up to at least 67fps, and i mean very low-end, with integrated graphics and low memory. so my game works just fine i dont need to replace anything.
but, if i get something even better i could add filters and resize algorithms, its not needed but would make it even better. now can we go back to the OP questions or you want to know more?
-
Re: Direct2D Typelib+ for VB6
Hi Baka,
Ok, just to clarify though ... Direct2D is one of the sub-libraries within DirectX. However, the first thing we must do is decide which version of DirectX we're talking about (DX8? DX9?, more recent?). Once that's decided, then we can figure out what we need to use Direct2D.
Having said that, if we're happy with DX8, then we don't need a TypeLib. It's all directly accessible via the Dx8vb.dll (including Direct2D). If we want to use DX9, we can use Trick's TypeLib, but I'm not terribly familiar with that. If we want to use something more recent, then I'm not sure.
If DX8 will do, this is an excellent document/tutorial that goes through all of it. And, if you go into the graphics section, sections #3 & #4 (parts 1 & 2) are a rather thorough description of Direct2D. Furthermore, it's all described using VB6 examples.
Best Regards,
Elroy
-
Re: Direct2D Typelib+ for VB6
reading about it, it says:
Code:
Direct2D is a user-mode library that is built using the Direct3D 10.1 API.
This means that Direct2D applications benefit from hardware-accelerated
rendering on modern mainstream GPUs. Hardware acceleration is also achieved
on earlier Direct3D 9 hardware by using Direct3D 10-level-9 rendering.
This combination provides excellent performance on graphics hardware
on existing Windows PCs.
Starting with Windows 8, Direct2D is built using the Direct3D 11.1 API.
so, if someone creates a typelib, will that only work on either windows 8+ or windows 7- depending on what API is used?
-
Re: Direct2D Typelib+ for VB6
Technically DirectX is already a typelib. Much like OpenGL is. Otherwise wed all be writing in assembly to access hardware. It's not hard to learn and pick up. Creating a library out of a library would not be worth it. Well unless you learn Unity or Unreal Engine. But even that's a learning curve. Just learn how to use DirectX. If you need to ask me any questions at all regarding it, I can help ;)
-
Re: Direct2D Typelib+ for VB6
Quote:
Originally Posted by
Elroy
Having said that, if we're happy with DX8, then we don't need a TypeLib. It's all directly accessible via the Dx8vb.dll (including Direct2D).
Seems unlikely. There wasn't any Direct2D or DirectWrite until Windows 7 and it was tied to DirectX 10. Then another version came along with Windows 8, tied to DirectX 11.1, and so on and so on.
-
Re: Direct2D Typelib+ for VB6
Quote:
Originally Posted by
dilettante
Seems unlikely. There wasn't any Direct2D or DirectWrite until Windows 7 and it was tied to DirectX 10. Then another version came along with Windows 8, tied to DirectX 11.1, and so on and so on.
And now D3DX is deprecated and you are FORCED to use shaders in both OpenGL and DirectX
Living Without D3DX
-
Re: Direct2D Typelib+ for VB6
Quote:
Originally Posted by
Jacob Roman
And now D3DX is deprecated and you are FORCED to use shaders in both OpenGL and DirectX
Now? That issue dates back to 2012 or so.
-
Re: Direct2D Typelib+ for VB6
Quote:
Originally Posted by
dilettante
Now? That issue dates back to 2012 or so.
Exactly
-
Re: Direct2D Typelib+ for VB6
I was working on that library (Direct2D), i can continue if community need for that library and no one work on it.
-
Re: Direct2D Typelib+ for VB6
that would be awesome The trick! :)
-
1 Attachment(s)
Re: Direct2D Typelib+ for VB6
Okay, i'll check if i made the enough interfaces and will made the helpers module. Then i'll make the several examples. After all i'll publish the all stuffs.
Attachment 158845
-
Re: Direct2D Typelib+ for VB6
im quite excited! this will be definitely worth understanding and spending time to learn as im working with 2D not 3D :)
-
Re: Direct2D Typelib+ for VB6
DirectX as well as OpenGL does both 2D and 3D and utilize the hardware. Since you are eager to learn the 2d aspect, my Massive DirectX Tutorial is all 2D. And covers texture mapping, animation, tile engines, alpha blending, rotation, and so much more! My signature even has the World of Warcraft Spell Cooldown effect done in VB6 and DirectX
-
Re: Direct2D Typelib+ for VB6
@The Trick, Since you've been working with it - would you agree that the API lends itself to VB nicely?
(considering that the resources are COM Objects?)
I think Direct2D is better suited for VB than GDI and GDI+ even with class wrappers.
-
Re: Direct2D Typelib+ for VB6
yeah DEXWERX, in the other thread by Elroy and DirectX8, im with you. that is one reason why im a bit reluctant to start learning DX8. we do have DX9, but so far I felt overwhelmed and couldn't grasp it to convert GDI to it.
now with The trick working with a Direct2D Typelib, maybe its time to learn something new and replace GDI once and for all.
I wonder why nobody else thought about it before, reading about Direct2D it seems to be suited for VB. at least now it seems we will get it and I can't wait to try it! :)
-
Re: Direct2D Typelib+ for VB6
Quote:
Originally Posted by
DEXWERX
@The Trick, Since you've been working with it - would you agree that the API lends itself to VB nicely?
(considering that the resources are COM Objects?)
I think Direct2D is better suited for VB than GDI and GDI+ even with class wrappers.
Seems yes, but sometimes i get crashes. (i need to check all declarations before publish). I changed little bit declarations because some methods accepts objects from DirectWrite (to any) and some methods accepts ByVal UDT, i've changed them too. Just i'm working on the helpers library D1D2.bas in order to we can write like in C++:
Code:
Option Explicit
Dim cFactory As ID2D1Factory
Dim cRenderTarget As ID2D1HwndRenderTarget
Dim cSolidBrush As ID2D1SolidColorBrush
Private Sub Command1_Click()
Dim tArea As D2D1_SIZE_F
Dim lX As Long
Dim lY As Long
Dim lIndex As Long
cRenderTarget.BeginDraw
cRenderTarget.SetTransform D2D1.Matrix3x2F_Identity()
cRenderTarget.Clear D2D1.ColorF(D2D1_COLORS.Beige)
tArea = cRenderTarget.GetSize
For lX = 0 To tArea.Width - 1 Step 10
cRenderTarget.DrawLine lX, 0, 0, lX, cSolidBrush, 0.5
Next
For lIndex = 0 To 100
cSolidBrush.SetColor D2D1.ColorF(Rnd * &H1000000)
cRenderTarget.DrawEllipse D2D1.Ellipse(D2D1.Point2F(Rnd * tArea.Width, Rnd * tArea.Height), _
Rnd * 50, Rnd * 50), cSolidBrush, Rnd * 5
Next
cRenderTarget.EndDraw
End Sub
Private Sub Form_Load()
Set cFactory = D2D1.CreateFactory()
Set cRenderTarget = cFactory.CreateHwndRenderTarget(D2D1.RenderTargetProperties(D2D1.PixelFormat()), _
D2D1.HwndRenderTargetProperties(Me.hWnd, D2D1.SizeU()))
Set cSolidBrush = cRenderTarget.CreateSolidColorBrush(D2D1.ColorF(D2D1_COLORS.Red), ByVal 0&)
End Sub
Private Sub Form_Resize()
cRenderTarget.Resize D2D1.SizeU(Me.ScaleWidth, Me.ScaleHeight)
End Sub
That's the real code example.
-
Re: Direct2D Typelib+ for VB6
Just the progress. Direct2D requires the Windows Imaging Component to open images (if you want to open PNG, JPG and other files). I made that type library too (need to check all). The helpers library for Direct2D is done.
https://s8.hostingkartinok.com/uploa...bba7f8eb2a.jpg
Also it requires DirectWrite to write text i'll do too.
-
Re: Direct2D Typelib+ for VB6
looking good!
checking the code you posted, I think I can learn that, it seems a bit easier then dx9.
im quite interested in the DrawBitmap function, I hope I can use it to replace gdialphablend.
-
Re: Direct2D Typelib+ for VB6
@TheTrick We can use a lightweight COM Object, to intercept the QI so that a D2D1CreateFactory helper can deduce the riid/IID similar to the C++ templates do with __uuidof(). I'll go ahead and post a code sample once I've got it working.
-
Re: Direct2D Typelib+ for VB6
Hi DEXWERX. Okay, thanks. only i don't understand what's it for, i'll wait for you example.
Current code of CreateFactory:
Code:
' // Create ID2D1Factory object
Public Function CreateFactory( _
Optional ByVal eType As D2D1_FACTORY_TYPE = D2D1_FACTORY_TYPE_SINGLE_THREADED, _
Optional ByVal eDebugOptions As D2D1_DEBUG_LEVEL = -1) As ID2D1Factory
Dim tOptions As D2D1_FACTORY_OPTIONS
Dim pOptions As Long
Dim cIID(1) As Currency
If eDebugOptions <> -1 Then
tOptions.debugLevel = eDebugOptions
pOptions = VarPtr(tOptions)
End If
' // IID_ID2D1Factory
cIID(0) = 506948672004902.9703@
cIID(1) = 53149071617564.8146@
Set CreateFactory = D2D1CreateFactory(eType, cIID(0), ByVal pOptions)
End Function
-
Re: Direct2D Typelib+ for VB6
Quote:
Originally Posted by
The trick
Hi DEXWERX. Okay, thanks. only i don't understand what's it for, i'll wait for you example.
Current code of CreateFactory:
Code:
' // Create ID2D1Factory object
Public Function CreateFactory( _
Optional ByVal eType As D2D1_FACTORY_TYPE = D2D1_FACTORY_TYPE_SINGLE_THREADED, _
Optional ByVal eDebugOptions As D2D1_DEBUG_LEVEL = -1) As ID2D1Factory
Dim tOptions As D2D1_FACTORY_OPTIONS
Dim pOptions As Long
Dim cIID(1) As Currency
If eDebugOptions <> -1 Then
tOptions.debugLevel = eDebugOptions
pOptions = VarPtr(tOptions)
End If
' // IID_ID2D1Factory
cIID(0) = 506948672004902.9703@
cIID(1) = 53149071617564.8146@
Set CreateFactory = D2D1CreateFactory(eType, cIID(0), ByVal pOptions)
End Function
Ah I was over-thinking it. D2D1CreateFactory/DWriteCreateFactory only ever uses a single IID (IID_ID2D1Factory/IID_IDWriteFactory).
I thought CreateFactory was for other resources, based on IID.
If It's just the one function - that creates the factory, no need to intercept the QI.
-
Re: Direct2D Typelib+ for VB6
Here's a copy of my Matrix3x2F class. It needs to be set to PreDeclared and the Matrix Property needs to be set to Default.
Code:
Option Explicit
Private m_Matrix As D2D1_MATRIX_3X2_F
Public Property Get m11() As Single
m11 = m_Matrix.[_11]
End Property
Public Property Let m11(ByVal Value As Single)
m_Matrix.[_11] = Value
End Property
Public Property Get m12() As Single
m12 = m_Matrix.[_12]
End Property
Public Property Let m12(ByVal Value As Single)
m_Matrix.[_12] = Value
End Property
Public Property Get m21() As Single
m21 = m_Matrix.[_21]
End Property
Public Property Let m21(ByVal Value As Single)
m_Matrix.[_21] = Value
End Property
Public Property Get m22() As Single
m22 = m_Matrix.[_22]
End Property
Public Property Let m22(ByVal Value As Single)
m_Matrix.[_22] = Value
End Property
Public Property Get m31() As Single
m31 = m_Matrix.[_31]
End Property
Public Property Let m31(ByVal Value As Single)
m_Matrix.[_31] = Value
End Property
Public Property Get m32() As Single
m32 = m_Matrix.[_32]
End Property
Public Property Let m32(ByVal Value As Single)
m_Matrix.[_32] = Value
End Property
Public Function Identity() As Matrix3x2F
Set Identity = New Matrix3x2F
Identity = IdentityMatrix
End Function
Public Function Init(ByVal m11 As Single, _
ByVal m12 As Single, _
ByVal m21 As Single, _
ByVal m22 As Single, _
ByVal m31 As Single, _
ByVal m32 As Single _
) As Matrix3x2F
Set Init = New Matrix3x2F
With Init
.m11 = m11
.m12 = m12
.m21 = m21
.m22 = m22
.m31 = m31
.m32 = m32
End With
End Function
Public Property Get Matrix(ParamArray Terms()) As D2D1_MATRIX_3X2_F
' This property must be set as Default
If UBound(Terms) = -1 Then
Matrix = m_Matrix
ElseIf UBound(Terms) = 5 Then
Matrix = Init(Terms(0), Terms(1), Terms(2), Terms(3), Terms(4), Terms(5))
Else
Err.Raise 5
End If
End Property
Public Property Let Matrix(ParamArray Terms(), ByRef Value As D2D1_MATRIX_3X2_F)
m_Matrix = Value
End Property
Public Function Translation(ByVal X As Single, _
ByVal Y As Single _
) As Matrix3x2F
Set Translation = Init( _
1!, 0!, _
0!, 1!, _
X, Y)
End Function
Public Function Scale_(ByVal X As Single, _
ByVal Y As Single, _
ByVal CenterX As Single, _
ByVal CenterY As Single _
) As Matrix3x2F
Set Scale_ = Init( _
X, 0!, _
0!, Y, _
CenterX - X * CenterX, _
CenterY - Y * CenterY)
End Function
Public Function Rotation(ByVal Angle As Single, _
ByVal CenterX As Single, _
ByVal CenterY As Single _
) As Matrix3x2F
Set Rotation = New Matrix3x2F
Dim M As D2D1_MATRIX_3X2_F
D2D1MakeRotateMatrix Angle, CenterX, CenterY, M
Rotation = M
End Function
Public Function Skew(ByVal AngleX As Single, _
ByVal AngleY As Single, _
ByVal CenterX As Single, _
ByVal CenterY As Single _
) As Matrix3x2F
Set Skew = New Matrix3x2F
Dim M As D2D1_MATRIX_3X2_F
D2D1MakeSkewMatrix AngleX, AngleY, CenterX, CenterY, M
Skew = M
End Function
Public Function Determinent() As Single
With m_Matrix
Determinent = (.[_11] * .[_22]) - (.[_12] * .[_21])
End With
End Function
Public Function IsInvertible() As Boolean
IsInvertible = D2D1IsMatrixInvertible(m_Matrix)
End Function
Public Function Invert() As Boolean
Invert = D2D1InvertMatrix(m_Matrix)
End Function
Public Function IsIdentity() As Boolean
With m_Matrix
IsIdentity = .[_11] = 1! And .[_12] = 0! And _
.[_21] = 0! And .[_22] = 1! And _
.[_31] = 0! And .[_32] = 0!
End With
End Function
Public Sub SetProduct(ByRef A As Matrix3x2F, _
ByRef B As Matrix3x2F)
m_Matrix.[_11] = A.m11 * B.m11 + A.m12 * B.m21
m_Matrix.[_12] = A.m11 * B.m12 + A.m12 * B.m22
m_Matrix.[_21] = A.m21 * B.m11 + A.m22 * B.m21
m_Matrix.[_22] = A.m21 * B.m12 + A.m22 * B.m22
m_Matrix.[_31] = A.m31 * B.m11 + A.m32 * B.m21 + B.m31
m_Matrix.[_32] = A.m31 * B.m12 + A.m32 * B.m22 + B.m32
End Sub
Public Function Multiply(ByRef Matrix As Matrix3x2F _
) As Matrix3x2F
Set Multiply = New Matrix3x2F
Multiply.SetProduct Me, Matrix
End Function
Public Function TransformPoint(ByRef Point As D2D1_POINT_2F _
) As D2D1_POINT_2F
With m_Matrix
TransformPoint.X = Point.X * .[_11] + Point.Y * .[_21] + .[_31]
TransformPoint.Y = Point.X * .[_12] + Point.Y * .[_22] + .[_32]
End With
End Function
-
Re: Direct2D Typelib+ for VB6
i hope not forgotten. any news/issues?
-
Re: Direct2D Typelib+ for VB6
I can tell you it's a can of worms. Maybe we can discuss what should be in this typelib?
DXGI partial - does anyone see any value in including all of DXGI?
D2D1 almost complete - missing effects and property get/set callback support
DWrite partial - missing dwrite_1 + dwrite_2 interfaces
WIC/wincodec complete up to Win8, missing win10 additions
DComposition not yet added
edit: all the extra APIs is possibly why trick hasn't posted a typelib yet.
I intend to have a pretty complete typelib.
I also still need to add GDI to my GDI+ typelib.
-
Re: Direct2D Typelib+ for VB6
for me, what i need is:
- load a png into the memory (replace gdi32/gdi+)
- a replace to fillrect (that is used to fill any color to the hdc and is also used to clear the memorydc)
- a replace to gdialphablend (so i can copy/paste however i want)
- a replacement for textout and AddFontResourceEx (so i can load a font from file and render the text into the memoryhdc)
- a replacement to bitblt (that i use to clear the memorydc if theres a background pattern/picture instead of just fillrect)
- and finally a replacement to stretchblt (that i use to render to the picturebox)
- right now im using a loop and timer to make a fps. maybe in Direct2D is different, need some examples how to do instead.
thats it i think :)
-
1 Attachment(s)
Re: Direct2D Typelib+ for VB6
Hi baka.
I'm working on it when i have free time. I see DEXWERX does the same work too. What the sense to make the same task if Dex does the same? DEXWERX, do you plan to publish your type library? If so, i'll stop developing then. I see you has more much implemented things than me.
I send now my current progress with the demos. I used oleexp typelib to make compatible types (thanks fafalone).
https://s8.hostingkartinok.com/uploa...74ecef7112.png
https://s8.hostingkartinok.com/uploa...0f3eb09653.png
https://s8.hostingkartinok.com/uploa...8c9771bcfc.png
https://s8.hostingkartinok.com/uploa...b27e237bea.png
https://s8.hostingkartinok.com/uploa...8bd380de38.png
-
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!