-
Dec 31st, 2020, 07:57 AM
#1
Thread Starter
PowerPoster
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?
-
Dec 31st, 2020, 08:43 AM
#2
Thread Starter
PowerPoster
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.
-
Dec 31st, 2020, 09:36 AM
#3
Re: Vb6 - how start using Directx9?
-
Dec 31st, 2020, 09:46 AM
#4
Thread Starter
PowerPoster
Re: Vb6 - how start using Directx9?
heres the entire project:
Directx9.zip
i use Windows 10 with compatible for Windows XP SP2
-
Dec 31st, 2020, 09:50 AM
#5
Re: Vb6 - how start using Directx9?
Disable DirectX 8 library in references.
-
Dec 31st, 2020, 10:08 AM
#6
Thread Starter
PowerPoster
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
???
-
Dec 31st, 2020, 11:02 AM
#7
Thread Starter
PowerPoster
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.
-
Jan 1st, 2021, 07:28 AM
#8
Re: Vb6 - how start using Directx9?
how can i load an image file
You should create a texture. See examples here.
how can draw an image file?
You should draw two triangles (a quad) with texture. You specify the texture coordinates to set the source image area.
-
Jan 1st, 2021, 07:41 AM
#9
Thread Starter
PowerPoster
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
-
Jan 1st, 2021, 08:36 AM
#10
Re: Vb6 - how start using Directx9?
Direct3D most operates with triangles so you wrap anything to them. You specify texture coordinates to triangle's vertices then videocard interpolates them to fill the triangle with a texture (textures). This is how the fixed pipeline works. The better description you can get if read a book.
-
Jan 1st, 2021, 10:26 AM
#11
Thread Starter
PowerPoster
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
-
Jan 2nd, 2021, 05:58 AM
#12
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|