Enabeling windows events after Direct-X 8.0 3D rendering

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Enabeling windows events after Direct-X 8.0 3D rendering

Christoph J. Bachinger
Hi,
I'm trying to do Direct-X Rendering via the VB Direct-X 8.0 Type
library. Starting at the beginning I try to translate an VB-example at

http://www.activevb.de/tutorials/directx/d3d_intro/d3dintro.html
  (sorry its german explanation but english code)

to Dolphin Smalltalk.
To follow the example I have to initialize. Write a render method and
start in a Window the main message.

main
        self initializeDx.
        true whileTrue: [
                self renderDx.
                self doEvents]. "???????????"

The problem is the "doEvents". I can't find it in Dolphin. It should be
in  Presenter or View, and should allow the window to handle pending
events. But searching more then 2 hours, I can't find any
correspondending code. I'm sure it's there, but I can't find. Find
appended the VB Main loop. Thanks for any suggestion.

cjb


Private Sub Form_Load()
  Me.Show 'Versichern, dass das Fenster sichtbar ist.
  bRunning = Initialise()
  Debug.Print "Device Creation Return Code : ", bRunning
    'Damit jeder sieht, was passiert
  Do While bRunning
    Render 'Frame aktualisieren
    DoEvents ' Gibt dem Fenster Zeit zum "Denken",
             ' damit es auf Ereignisse reagieren kann
        'Framerate ausrechenen, es ist nicht größer
        'wichtig zu wissen wie...
      'Also brauchen wir uns keine Sorgen zu machen
    If GetTickCount - LastTimeCheckFPS >= 1000 Then
      LastTimeCheckFPS = GetTickCount
      FrameRate = FramesDrawn 'Framerate unterbringen
      FramesDrawn = 0 'Zähler zurücksetzten
      Me.Caption = "DirectX-Graphics: Lesson 01 " & _
        "{" & FrameRate & "fps}"
        'Framerate ausgeben
    End If
    FramesDrawn = FramesDrawn + 1
  Loop


Reply | Threaded
Open this post in threaded view
|

Re: Enabeling windows events after Direct-X 8.0 3D rendering

Andy Bower-3
Christoph,

> main
> self initializeDx.
> true whileTrue: [
> self renderDx.
> self doEvents]. "???????????"
>
> The problem is the "doEvents". I can't find it in Dolphin. It should
> be in  Presenter or View, and should allow the window to handle
> pending events. But searching more then 2 hours, I can't find any
> correspondending code. I'm sure it's there, but I can't find. Find
> appended the VB Main loop. Thanks for any suggestion.

I imagine what they are looking for is a "message pump" to keep the
Windows messages being serviced. Try:

SessionManager inputState pumpMessages.

FWIW, I've been teaching my son some Smalltalk by writing a DirectX
game with him in Dolphin. It's actually 2D sprite based but shows that
getting DirectX up and running under Dolphin using the VB type
libraries is *relatively* straightforward. In our case we start a
background process to handle the rendering; that way the normal UI
thread is not placed in a continuous loop and you don't need the
message pump.

BTW, when it's done I'll post up a download for the game.

Best regards,

--
Andy Bower
Dolphin Support
www.object-arts.com


Reply | Threaded
Open this post in threaded view
|

Re: Enabeling windows events after Direct-X 8.0 3D rendering

Christoph J. Bachinger
Thanks Andi,

> I imagine what they are looking for is a "message pump" to keep the
> Windows messages being serviced. Try:
>
> SessionManager inputState pumpMessages.

I believe this is it.

But there is another problem during initialisation
I put the stuff together for an evaluation below.

I got the following error after calling createDevice!
'HRESULT Error: Unrecognised HRESULT - 16r8876086C (FACILITY_DIRECTDRAW)

I'm not sure about the parameter
    hFocusWindow: shell view handle
because this is the main view handle. But with a subview handle I got
the same error.
If you have any idea evaluating the code below would be nice.

Thanks cjb


    | shell d3d d3dWindow d3dDevice |
    (shell := View desktop addSubView: ShellView new)
        extent: 400@500.
    shell show.
    d3d := DxVBLibAIDirectX8 new direct3DCreate.
    d3d getAdapterDisplayMode: (DxVBLibAConstants at: #D3DADAPTER_DEFAULT)
displayMode: (dispMode := DxVBLibAD3DDISPLAYMODE new).
    d3dWindow := DxVBLibAD3DPRESENT_PARAMETERS new.
    d3dWindow Windowed: 1.
    d3dWindow SwapEffect:  (DxVBLibAConstants at: #D3DSWAPEFFECT_COPY_VSYNC).
    d3dWindow BackBufferFormat: dispMode Format.
" The next call rises the error"
    d3dDevice := d3d
                createDevice:  (DxVBLibAConstants at: #D3DADAPTER_DEFAULT)
                deviceType:  (DxVBLibAConstants at: #D3DDEVTYPE_HAL)
                hFocusWindow: shell view handle    "??????"
                behaviorFlags:  (DxVBLibAConstants at:
#D3DCREATE_SOFTWARE_VERTEXPROCESSING)
                presentationParameters: d3dWindow.
    1000 timesRepeat: [
        d3dDevice clear: 0 clearD3DRect: 0 flags:  (DxVBLibAConstants at:
#D3DCLEAR_TARGET) color: 0xHCCCCFF z: 1 stencil: 0

        "Render start"
        "Render end"

        d3dDevice beginScene.
        d3dDevice endScene.
        d3dDevice present: 0  pDestRect: 0 hWndDestWindowOverride: 0
pDirtyRegion: 0.
        SessionManager inputState pumpMessages].


End of Code and Email


Reply | Threaded
Open this post in threaded view
|

Re: Enabeling windows events after Direct-X 8.0 3D rendering

Andy Bower-3
Christoph,

> But there is another problem during initialisation
> I put the stuff together for an evaluation below.
>
> I got the following error after calling createDevice!
> 'HRESULT Error: Unrecognised HRESULT - 16r8876086C
> (FACILITY_DIRECTDRAW)
>
> I'm not sure about the parameter
>     hFocusWindow: shell view handle
> because this is the main view handle. But with a subview handle I got
> the same error.
> If you have any idea evaluating the code below would be nice.

I think I know the problem. There is a "deficiency" in the Dolphin
ActiveX wizard when it generates the helper methods for automation
calls that take in-out parameters. It tries to be too clever and allow
for conversions from other structure types to the corrrect one. In
these cases it is inappropriate to do this. Here the offending call is
Direct3D8>>getAdapaterDisplayMode:displayMode:.

If you take a look at that method, you'll see that it is creating a
D3DDISPLAYMODE structure and then throwing away the result. In these
situations, you either need to edit the method to work properly or
allocate the structure yourself and use the uppercase
(GetAdapaterDisplayMode:displayMode:) method instead. The code below
should make it clear what I mean. I've been using the uppercase methods.

BTW, you'll see that my workspace code looks somewhat different from
yours. First of all I haven't include a prefix on the DirectX classes.
Second, I have added the DxVBLibAConstants pool (I called it
DirectX8Constants) to the workspace so you don't need to explicitly
reference it every time.

I haven't used Direct3D myself (I've been using DirectDraw7 mainly) but
I got the following adaptation of you code to work.

---
shell := Shell show.
d3d := IDirectX8 new direct3DCreate.

"Notice I am using the uppercase version of GetAdapaterDisplayMode"
dispMode := D3DDISPLAYMODE new.
d3d GetAdapterDisplayMode: D3DADAPTER_DEFAULT displayMode: dispMode.

d3dWindow := D3DPRESENT_PARAMETERS new.
d3dWindow Windowed: 1.
d3dWindow SwapEffect: D3DSWAPEFFECT_COPY_VSYNC.
d3dWindow BackBufferFormat: dispMode Format.

d3dDevice := d3d createDevice: D3DADAPTER_DEFAULT deviceType:
D3DDEVTYPE_HAL hFocusWindow: shell view handle behaviorFlags:
D3DCREATE_SOFTWARE_VERTEXPROCESSING presentationParameters: d3dWindow

this gives: a Direct3DDevice8(an ExternalAddress(16rE9800))
---

Best regards

Andy Bower
Dolphin Support
www.object-arts.com


Reply | Threaded
Open this post in threaded view
|

Re: Enabeling windows events after Direct-X 8.0 3D rendering

Christoph J. Bachinger
Hi Andy,
thanks a lot it works so far.

Have a nice day
cjb