Results 1 to 12 of 12

Thread: Vb6 - how start using Directx9?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Vb6 - how start using Directx9?

    i'm starting using Directx 9 on VB6.
    maybe it's the tlb file... but i don't know.
    see the actual code just for Directx9 initialization:
    Code:
    Option Explicit
    Dim pD3D As Direct3D9
    Dim pd3dDevice As Direct3DDevice9
    Dim d3dpp As D3DPRESENT_PARAMETERS
    
    Private Sub Form_Load()
    'Set pd3dDevice = New Direct3DDevice9
    'Set pD3D = New Direct3D9
    'both previous lines give me an error...
    
        d3dpp.Windowed = True
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD
        d3dpp.BackBufferFormat = D3DFMT_UNKNOWN
        d3dpp.BackBufferCount = 1
        d3dpp.BackBufferHeight = 480
        d3dpp.BackBufferWidth = 640
        d3dpp.hDeviceWindow = Me.hWnd
    
        'next line is give me an  error on compilation:
        If (pd3dDevice = pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, Me.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp) = 0) Then MsgBox "error"
    End Sub
    error message: "compiler Error: Method or data member not found"
    when i do 'pD3D.' the 'CreateDevice' is showed on list...
    so what i'm doing wrong? it's the library or dll or otherthing?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Vb6 - how start using Directx9?

    after reinstall the the DirectX8_RunTimes and reboot the PC, i can use the dx9vb.tlb.
    now heres the update code:
    Code:
    Option Explicit
    
    Dim pD3D As IDirect3D9
    Dim pd3dDevice As IDirect3DDevice9
    Dim d3dpp As D3DPRESENT_PARAMETERS
    
    Private Sub Form_Load()
        d3dpp.Windowed = True
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD
        d3dpp.BackBufferFormat = D3DFMT_UNKNOWN
        d3dpp.BackBufferCount = 1
        d3dpp.BackBufferHeight = 480
        d3dpp.BackBufferWidth = 640
        d3dpp.hDeviceWindow = Me.hWnd
        
       pd3dDevice = pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, Me.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp)
    End Sub
    the 'd3dpp' give me an error: 'byref argument type mismatch'
    what i'm doing wrong? the argument variable type it's 'D3DPRESENT_PARAMETERS'.. so what i'm doing wrong?
    Last edited by joaquim; Dec 31st, 2020 at 08:59 AM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Vb6 - how start using Directx9?

    heres the entire project:
    Directx9.zip
    i use Windows 10 with compatible for Windows XP SP2
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Vb6 - how start using Directx9?

    thank you so much for all.
    that code intializate directx 9... now i must release them... how can i do it?
    is just:
    Code:
    d3dev = Nothing
       d3d9 = Nothing
    ???
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Vb6 - how start using Directx9?

    great.. now i have a working code and corrected...
    Code:
    Option Explicit
    Dim d3d9        As IDirect3D9       ' // Direct3D9 object
    Dim d3dev       As IDirect3DDevice9 ' // Direct3D device
    
    'Initializate Directx 9:
    Private Sub Form_Load()
        'yes the directx class's must be setted for initializate them
        Set d3d9 = Direct3DCreate9()
        Dim pP As D3DPRESENT_PARAMETERS
        pP.BackBufferCount = 1
        pP.Windowed = 1 'in these sample is for a window standard size
        pP.BackBufferFormat = D3DFMT_A8R8G8B8
        pP.SwapEffect = D3DSWAPEFFECT_DISCARD
        pP.EnableAutoDepthStencil = 1
        pP.AutoDepthStencilFormat = D3DFMT_D16
        Set d3dev = d3d9.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Me.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, pP)
    End Sub
    
    'Destroying Directx9:
    Private Sub Form_Unload(Cancel As Integer)
        'Clean Directx 9...
        'yes the directx class's must be setted for destroy their objects:
        Set d3dev = Nothing
        Set d3d9 = Nothing
    End Sub
    
    'Render the scene:
    Private Sub Render()
        'clear and draw a color using the RGB()...
        'in these case we don't need the alpha value...
        d3dev.Clear 0, ByVal 0, D3DCLEAR_TARGET, RGB(0, 255, 0), 1#, 0
        
        
        d3dev.BeginScene
    
            'All rendering calls go between these two lines
    
        d3dev.EndScene
        
        'Now we must show what we did:
        d3dev.Present ByVal 0, ByVal 0, 0, ByVal 0
    
    End Sub
    PS: the RGB(0, 0, 255) is 'wrong'... because the Red is 'B' and the Blue is 'R'.. tested now
    these topic is for start Directx 9.
    readers: don't forget that adding the Directx 8 library mess with these code... so don't select it
    The trick: before i finish these topic, i need ask more 2 things:
    1 - how can i load an image file?
    2 - how can draw an image file?
    Last edited by joaquim; Dec 31st, 2020 at 11:24 AM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8

  9. #9

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Vb6 - how start using Directx9?

    The trick, is like GDI, right?
    - create a brush and select it.... on Directx create a texure;
    - we have a polygon points.... and the brush is drawed with that points.... on directx is more or less the same right?

    anotherthing: heres a function for convert RGB to BGR color:
    Code:
    Public Function BGR(Blue As Integer, Green As Integer, Red As Integer) As Long
        BGR = RGB(Blue, Green, Red)
    End Function
    VB6 2D Sprite control

    To live is difficult, but we do it.

  10. #10

  11. #11

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Vb6 - how start using Directx9?

    i have 2 great books, but they are for C\C++
    and that link for Directx 8 for VB6: http://directx4vb.vbgamer.com/Direct...T_DX8Start.asp
    at least that link can be converted to portuguese hehehehe (with google translator)
    i must read that books for C\C++ and then convert the code for VB6.
    thanks for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

  12. #12
    New Member
    Join Date
    Jul 2017
    Location
    Dhaka.
    Posts
    4

    Re: Vb6 - how start using Directx9?

    New learning for me too.

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