Page 1 of 6 1234 ... LastLast
Results 1 to 40 of 201

Thread: Direct2D Typelib+ for VB6

  1. #1

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    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?

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    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).
    Last edited by Elroy; May 5th, 2018 at 09:44 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.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Direct2D Typelib+ for VB6

    To do everything you want you might also need DirectWrite and Windows Imaging Component (WIC).

  4. #4

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    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.

  5. #5
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: Direct2D Typelib+ for VB6

    Ooooor you can talk to me about DirectX, as I'm an expert at it

    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.

  6. #6

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    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!

  7. #7
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    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:
    1. '---------------------------------
    2. 'Title: DirectX Tutorial
    3. '
    4. 'Description: This is your first DirectX8 application.
    5. '             I made it to where this is the easiest
    6. '             method to initialize and render. No
    7. '             extra subs/functions, no error handling,
    8. '             no modules/classes, no nothing. It can't
    9. '             get any easier than this, and makes it easy
    10. '             for any beginner to understand.
    11. '
    12. 'Author: Jacob Roman
    13. '
    14. 'Date: 12/01/2005
    15. '
    16. 'Contact: [email]jacob_c_roman@hotmail.com[/email]
    17. '---------------------------------
    18.  
    19. Option Explicit
    20.  
    21. Private DirectX8 As DirectX8 'The master DirectX object.
    22. Private Direct3D As Direct3D8 'Controls all things 3D.
    23. Private Direct3D_Device As Direct3DDevice8 'Represents the hardware rendering.
    24.  
    25. Private Running As Boolean 'Helps determine whether the main game loop is running.
    26.  
    27. Private Sub Form_Activate()
    28.  
    29.     frmMain.Caption = "DirectX Tutorial"
    30.  
    31.     Dim Display_Mode As D3DDISPLAYMODE 'Display mode desciption.
    32.     Dim Direct3D_Window As D3DPRESENT_PARAMETERS 'Backbuffer and viewport description.
    33.    
    34.     Set DirectX8 = New DirectX8 'Creates the DirectX object.
    35.     Set Direct3D = DirectX8.Direct3DCreate() 'Creates the Direct3D object using the DirectX object.
    36.    
    37.     Direct3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, Display_Mode 'Use the current display mode that you
    38.                                                                     'are already on. Incase you are confused, I'm
    39.                                                                     'talking about your current screen resolution. ;)
    40.    
    41.     Direct3D_Window.Windowed = True 'The app will be in windowed mode.
    42.     Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC 'Refresh when the monitor does.
    43.     Direct3D_Window.BackBufferFormat = Display_Mode.Format 'Sets the format that was retrieved into the backbuffer.
    44.    
    45.     'Creates the rendering device with some useful info, along with the info
    46.     'we've already setup for Direct3D_Window.
    47.     Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Direct3D_Window)
    48.  
    49.     Running = True 'Initializations all set. It's now ok to activate the game loop.
    50.  
    51.     Do While Running = True
    52.        
    53.         DoEvents 'Allow events to happen so the program doesn't lock up.
    54.        
    55.         '----------------------------------------------------
    56.         'DirectX automatically handles the framerate for you
    57.         'which makes it run (at most) as fast as the monitors
    58.         'refresh rate, so you don't need to add extra code to
    59.         'slow down the loop and run at a certain number of frames
    60.         'per second.
    61.         '----------------------------------------------------
    62.        
    63.         'Clears the backbuffer.
    64.         Direct3D_Device.Clear 0, ByVal 0, D3DCLEAR_TARGET, D3DColorRGBA(0, 0, 0, 0), 1#, 0
    65.        
    66.             'Rendering code goes here, but in this tutorial, it will be empty for now.
    67.        
    68.         'Flips the backbuffer into the form window.
    69.         Direct3D_Device.Present ByVal 0, ByVal 0, 0, ByVal 0
    70.        
    71.     Loop
    72.  
    73. End Sub
    74.  
    75. Private Sub Form_Unload(Cancel As Integer)
    76.  
    77.     Running = False 'Helps the program bail out of the game loop.
    78.    
    79.     'Unload all of the DirectX objects
    80.    
    81.     Set Direct3D_Device = Nothing
    82.     Set Direct3D = Nothing
    83.     Set DirectX8 = Nothing
    84.    
    85.     Unload Me 'Unload the form
    86.    
    87.     End 'Ends the program
    88.    
    89.     'Although the Unload statement located above exits the program, you
    90.     'will end up with an Automation error after doing so. The End statement
    91.     'will help prevent that, and end the app completely.
    92.  
    93. 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!!!




  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    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
    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.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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.

    Name:  sshot.jpg
Views: 2590
Size:  36.1 KB
    Attached Files Attached Files

  10. #10

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    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.

  11. #11
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    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
    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.

  12. #12
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    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

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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.

  14. #14
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    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
    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.

  15. #15

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    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?

  16. #16
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    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
    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.

  17. #17

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    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?

  18. #18
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    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

  19. #19
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Direct2D Typelib+ for VB6

    Quote Originally Posted by Elroy View Post
    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.

  20. #20
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: Direct2D Typelib+ for VB6

    Quote Originally Posted by dilettante View Post
    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

  21. #21
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Direct2D Typelib+ for VB6

    Quote Originally Posted by Jacob Roman View Post
    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.

  22. #22
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: Direct2D Typelib+ for VB6

    Quote Originally Posted by dilettante View Post
    Now? That issue dates back to 2012 or so.
    Exactly

  23. #23

  24. #24

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Direct2D Typelib+ for VB6

    that would be awesome The trick!

  25. #25

  26. #26

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    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

  27. #27
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    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

  28. #28
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    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.
    Last edited by DEXWERX; May 8th, 2018 at 07:19 AM.

  29. #29

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    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!

  30. #30
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,672

    Re: Direct2D Typelib+ for VB6

    Quote Originally Posted by DEXWERX View Post
    @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.

  31. #31

  32. #32

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    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.

  33. #33
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    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.

  34. #34
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,672

    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

  35. #35
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Direct2D Typelib+ for VB6

    Quote Originally Posted by The trick View Post
    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.

  36. #36
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    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
    Last edited by DEXWERX; May 11th, 2018 at 12:57 PM.

  37. #37

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Direct2D Typelib+ for VB6

    i hope not forgotten. any news/issues?

  38. #38
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    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.
    Last edited by DEXWERX; May 22nd, 2018 at 10:10 AM.

  39. #39

    Thread Starter
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    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

  40. #40

Page 1 of 6 1234 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width