Results 1 to 14 of 14

Thread: [Vb6] Windowed DirectX8[Resolved]

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Resolved [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:
    1. Public Function Initialize() As Boolean
    2.   'On Error GoTo ErrHandler:
    3.  
    4.   Dim DispMode As D3DDISPLAYMODE
    5.   Dim D3DWindow As D3DPRESENT_PARAMETERS
    6.   Dim ColorKeyVal As Long
    7.  
    8.   Set dx = New DirectX8  
    9.   Set D3D = dx.Direct3DCreate()
    10.   Set D3DX = New D3DX8
    11.  
    12.  
    13.  
    14.   DispMode.Format = D3DFMT_X8R8G8B8    
    15.   D3DWindow.Windowed = 1
    16.   D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
    17.   'D3DWindow.BackBufferCount = 1
    18.   D3DWindow.BackBufferFormat = DispMode.Format
    19.   'D3DWindow.BackBufferHeight = 480
    20.   'D3DWindow.BackBufferWidth = 640
    21.   D3DWindow.hDeviceWindow = frmEditor.picMain.hWnd
    22.  
    23.  
    24.   Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmEditor.picMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)
    25.  
    26.   D3DDevice.SetVertexShader FVF
    27.  
    28.   D3DDevice.SetRenderState D3DRS_LIGHTING, False
    29.  
    30.   D3DDevice.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA
    31.   D3DDevice.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA
    32.   D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, True
    33.  
    34.   Set DI = dx.DirectInputCreate()
    35.   Set DIDEV = DI.CreateDevice("GUID_SysKeyboard")
    36.  
    37.   DIDEV.SetCommonDataFormat DIFORMAT_KEYBOARD
    38.   DIDEV.SetCooperativeLevel frmEditor.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
    39.   DIDEV.Acquire
    40.  
    41.   Initialize = True
    42.   Exit Function
    43. ErrHandler:
    44. Debug.Print "Error Number Returned: " & Err.Number
    45. Debug.Print "Error Description: " & Err.description
    46. Initialize = False
    47. 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.

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

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

  3. #3

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: [Vb6] Windowed DirectX8...

    Present Rect?

  4. #4

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    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?

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    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)

  6. #6

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    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?

  7. #7
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    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

  8. #8

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: [Vb6] Windowed DirectX8...

    Ok, thank you very much.

  9. #9
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Re: [Vb6] Windowed DirectX8[Resolved]

    May I ask what you're developing? "Editor" sounds like "game"

  10. #10

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    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?

  11. #11
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    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.

  12. #12

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: [Vb6] Windowed DirectX8[Resolved]

    Nah, not bitblt, I just kinda refer to everything as blitting. I should probably say draw.

  13. #13
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    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 ^^;

  14. #14

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    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
  •  



Click Here to Expand Forum to Full Width