|
-
Nov 3rd, 2005, 10:40 PM
#1
Thread Starter
Fanatic Member
[Vb6] Windowed DirectX8[Resolved]
I have windowed DirectX8 set up with a picturebox on my form. This works fine, except that the picture box changes shape as the form resizes. Perhaps I'm doing this wrong, or perhaps it's by default, but when the pixturebox changes size the blitting from directx warps to fit inside the picturebox. Here's my initialization code.
VB Code:
Public Function Initialize() As Boolean
'On Error GoTo ErrHandler:
Dim DispMode As D3DDISPLAYMODE
Dim D3DWindow As D3DPRESENT_PARAMETERS
Dim ColorKeyVal As Long
Set dx = New DirectX8
Set D3D = dx.Direct3DCreate()
Set D3DX = New D3DX8
DispMode.Format = D3DFMT_X8R8G8B8
D3DWindow.Windowed = 1
D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
'D3DWindow.BackBufferCount = 1
D3DWindow.BackBufferFormat = DispMode.Format
'D3DWindow.BackBufferHeight = 480
'D3DWindow.BackBufferWidth = 640
D3DWindow.hDeviceWindow = frmEditor.picMain.hWnd
Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmEditor.picMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)
D3DDevice.SetVertexShader FVF
D3DDevice.SetRenderState D3DRS_LIGHTING, False
D3DDevice.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA
D3DDevice.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA
D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, True
Set DI = dx.DirectInputCreate()
Set DIDEV = DI.CreateDevice("GUID_SysKeyboard")
DIDEV.SetCommonDataFormat DIFORMAT_KEYBOARD
DIDEV.SetCooperativeLevel frmEditor.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
DIDEV.Acquire
Initialize = True
Exit Function
ErrHandler:
Debug.Print "Error Number Returned: " & Err.Number
Debug.Print "Error Description: " & Err.description
Initialize = False
End Function
Where frmEditor is a standard VB form and frmEditor.picMain is a regular picturebox. Do I need to reinitialize directX each time the picturebox changes shape or is there an easier way around this? Thanks.
Last edited by Nove; Nov 6th, 2005 at 12:52 PM.
-
Nov 3rd, 2005, 10:55 PM
#2
PowerPoster
Re: [Vb6] Windowed DirectX8...
> Do I need to reinitialize directX each time the picturebox changes shape
Kinda; you need to re-initialize the D3D device whenever you enlarge the box (when making it smaller you can just change the present rect).
-
Nov 4th, 2005, 04:24 PM
#3
Thread Starter
Fanatic Member
Re: [Vb6] Windowed DirectX8...
-
Nov 4th, 2005, 10:15 PM
#4
Thread Starter
Fanatic Member
Re: [Vb6] Windowed DirectX8...
Also, when I call the intialize sub again, it totally screws directx up, I get that scrambled stuff when I blit. Why is this?
-
Nov 5th, 2005, 10:48 PM
#5
PowerPoster
Re: [Vb6] Windowed DirectX8...
I guess you want to go the easy way.. well, just remember that DirectX internally renders to a backbuffer that can be any size. Just when you call the Device.Present() function the contents of the backbuffer are copied to your window. By default DirectX copies the whole buffer to the whole target, stretching or shrinking it if necessary. However you can tell the Present function the width/height of your target so there's no need for stretching.
So what you basically do is to create a backbuffer that matches the screen size (because we assume that the window won't ever get larger than the screen). Then you setup the Present rect just the size of your picturebox/window/whatever.
This way you don't have to care about size changes (except you have to store the new size)
-
Nov 6th, 2005, 01:11 AM
#6
Thread Starter
Fanatic Member
Re: [Vb6] Windowed DirectX8...
So basically, when I call the Present function I supply a RECT the size of my picturebox for the first two parameters?
-
Nov 6th, 2005, 03:28 AM
#7
PowerPoster
Re: [Vb6] Windowed DirectX8...
Yep, but only for the first (source rect). The destination rect will match the size but not the position - let DirectX determine that for you
-
Nov 6th, 2005, 12:52 PM
#8
Thread Starter
Fanatic Member
Re: [Vb6] Windowed DirectX8...
-
Nov 6th, 2005, 04:56 PM
#9
PowerPoster
Re: [Vb6] Windowed DirectX8[Resolved]
May I ask what you're developing? "Editor" sounds like "game"
-
Nov 6th, 2005, 11:02 PM
#10
Thread Starter
Fanatic Member
Re: [Vb6] Windowed DirectX8[Resolved]
Well, I'm working on it. I'd like to see if I can get a a stable server-client game going in vb6, so far it's going allright, I'm mostly doing editor work right now.
Would you happen to know if there are any problems in DirectX 8 just filling the screen completely black? I tried using the same method I've been using with tiles, a 4 element array of TLVERTEX, but I couldn't get anything to blit. Can you foresee any problem I would have or is it just poor coding?
-
Nov 7th, 2005, 01:57 AM
#11
PowerPoster
Re: [Vb6] Windowed DirectX8[Resolved]
There should not be any problems with that. However, to clear the screen all you do is:
Device.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, D3DColorRGBA(0, 0, 0, 0), 1, 0
For black you wouldn't even have to use D3DColorRGBA (black is simply 0 you know).
By "blit" do you mean BitBlt? Well, after the rendering is done (Device.EndScene) you can safely blit to the DC - as long as you're in windowed mode, fullscreen would cause problems here.
-
Nov 7th, 2005, 05:50 PM
#12
Thread Starter
Fanatic Member
Re: [Vb6] Windowed DirectX8[Resolved]
Nah, not bitblt, I just kinda refer to everything as blitting. I should probably say draw.
-
Nov 7th, 2005, 08:06 PM
#13
PowerPoster
Re: [Vb6] Windowed DirectX8[Resolved]
But you could BitBlt Ah well, go on then and have fun. If filling the screen doesn't work you probably setup the vertices wrong.. or the FVF.. or something else ^^;
-
Nov 7th, 2005, 08:07 PM
#14
Thread Starter
Fanatic Member
Re: [Vb6] Windowed DirectX8[Resolved]
Clear worked fine, thanks. I guess this thing is totally resolved now, thanks a bunch.
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
|