DirectX 8 - VB example to Dolphin question

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

DirectX 8 - VB example to Dolphin question

Christoph J. Bachinger
Hi folks, or should I say Andy,

this is a very special question.
I'm still trying to convert a vb example to dolphin you can find it at
http://www.activevb.de/tutorials/directx/d3d_3dg/downloads/d3dtut5.zip.

Please evaluate the code below in a workspace to see my problem.
You have to install the DxVBLibA Type Library. I Installed it with
preceeding Dx8 not DxVBLibA, so maybe you have to find "Dx8" and replace
with "DxVBLibA" in the code below.
I got the message "Invalid access to memory location" ... after
evaluating the setPrivateData at the end.
1. cube is defined above as
        cube := StructureArray length: 36 elementClass: Dx8D3DLVERTEX.
    Is the definiton correct??

2. I'm also a little bit confused about the keyword order of
        setPrivateData:data:sizeOfData:flags:
    because in VB the order is different!
        D3DVertexBuffer8SetData VBuffer, 0, Len(Cube(0)) * 36, 0, Cube(0)

Take care to add in the workspace the Dx8Constants to the pool.

Thanks in forward
cjb

CODE START
==========
        |shell d3d dispMode d3dWindow d3dDevice matWorld matView matPerspective
vertexBuffer cube c000 c001 c010 c011 c100 c101 c110 c111|
        (shell := View desktop addSubView: ShellView new)
                extent: 300@200.
        shell show.
        litFVF := (D3DFVF_XYZ bitOr: D3DFVF_DIFFUSE) bitOr: (D3DFVF_SPECULAR
bitOr: D3DFVF_TEX1).
        d3d := Dx8IDirectX8 new direct3DCreate.
        dispMode := Dx8D3DDISPLAYMODE new.
        d3d GetAdapterDisplayMode: D3DADAPTER_DEFAULT displayMode: dispMode.
        d3dWindow := Dx8D3DPRESENT_PARAMETERS new.
        d3dWindow Windowed: 1.
        d3dWindow SwapEffect: D3DSWAPEFFECT_COPY_VSYNC.
        d3dWindow BackBufferFormat: dispMode Format.

        "ZBuffer setting"

        d3dWindow EnableAutoDepthStencil: 1.
        d3dWindow AutoDepthStencilFormat:  D3DFMT_D16.

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

        "Set the vertex shader to use our vertex format"
        d3dDevice SetVertexShader: litFVF.

        "Transformed and lit vertices dont need lighting so we disable it..."
        d3dDevice SetRenderState: D3DRS_LIGHTING value: false asParameter.

        "'Direct3D wont draw any triangles that are facing away from us;
        to stop it doing this we stop it culling - it's good practise to design
        your geometry so that you DONT need this option...
        To do this, generate your vertices in a clockwise order... (by default
it removes all CCW ordered triangles)"
        d3dDevice SetRenderState: D3DRS_CULLMODE value: D3DCULL_NONE.
        "Enable our Z-Buffer"
        d3dDevice SetRenderState: D3DRS_ZENABLE value: 1.

        "Set world matrix"
        matWorld := Dx8D3DMATRIX new.
        Dx8D3DXMATH_MATRIXLibrary default d3dxMatrixIdentity: matWorld.
        d3dDevice SetTransform: D3DTS_WORLD matrix: matWorld.

        "Set view matrix"
        matView := Dx8D3DMATRIX new.
        Dx8D3DXMATH_MATRIXLibrary default d3dxMatrixIdentity: matView.
        vecFrom := Dx8D3DVECTOR new.
        vecTo := Dx8D3DVECTOR new.
        vecUp := Dx8D3DVECTOR new.
        "Camera location"
        vecFrom x: 0; y: 5; z: 9.
        "Camera look to:"
        vecTo x: 0; y: 0; z: 0.
        ""
        vecUp x: 0; y: 1; z: 0.
        "View matrix creation"
        Dx8D3DXMATH_MATRIXLibrary default
                d3dxMatrixLookAtLH: matView
                vEye: vecFrom
                vAt: vecTo
                vUp: vecUp.
        d3dDevice SetTransform: D3DTS_VIEW matrix: matView.

        "Set the Perspective matrix"

        matPerspective := Dx8D3DMATRIX new.
        Dx8D3DXMATH_MATRIXLibrary default d3dxMatrixIdentity: matPerspective.
        Dx8D3DXMATH_MATRIXLibrary default
                d3dxMatrixPerspectiveFovLH: matPerspective
                fovy: Float pi / 4.0
                aspect: 1
                zn: 0.1
                zf: 500.
        d3dDevice SetTransform: D3DTS_PROJECTION matrix: matPerspective.
        "Cretate cube"
        c000 := Color red asRGB asParameter.
        c001 := Color green asRGB asParameter.
        c010 := Color blue asRGB asParameter.
        c011 := Color magenta asRGB asParameter.
        c100 := Color yellow asRGB asParameter.
        c101 := Color cyan asRGB asParameter.
        c110 := Color white asRGB asParameter.
        c111 := Color brown asRGB asParameter.
        cube := StructureArray length: 36 elementClass: Dx8D3DLVERTEX.
        "Front"
        cube at: 1 put: ((Dx8D3DLVERTEX new) x: -1; y:  1; z:  1; color: c011;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 2 put: ((Dx8D3DLVERTEX new) x:  1; y:  1; z:  1; color: c111;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 3 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z:  1; color: c001;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 4 put: ((Dx8D3DLVERTEX new) x: 1; y:  1; z:  1; color: c111;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 5 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z: 1; color: c001;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 6 put: ((Dx8D3DLVERTEX new) x: 1; y: -1; z: 1; color: c101;
specular: 0; tu: 0 ; tv: 0; yourself).
"Rear"
        cube at: 7 put: ((Dx8D3DLVERTEX new) x: -1; y: 1; z: -1; color: c010;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 8 put: ((Dx8D3DLVERTEX new) x: 1; y: 1; z: -1; color: c110;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 9 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z: -1; color: c000;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 10 put: ((Dx8D3DLVERTEX new) x: 1; y: 1; z: -1; color: c110;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 11 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z: -1; color: c000;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 12 put: ((Dx8D3DLVERTEX new) x: 1; y: -1; z: -1; color: c100;
specular: 0; tu: 0 ; tv: 0; yourself).
"Right"
        cube at: 13 put: ((Dx8D3DLVERTEX new) x: -1; y: 1; z: -1; color: c010;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 14 put: ((Dx8D3DLVERTEX new) x: -1; y: 1; z: 1; color: c011;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 15 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z: -1; color: c000;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 16 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z: 1; color: c011;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 17 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z: -1; color: c000;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 18 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z: 1; color: c001;
specular: 0; tu: 0 ; tv: 0; yourself).
"Left"
        cube at: 19 put: ((Dx8D3DLVERTEX new) x: 1; y: 1; z: -1; color: c110;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 20 put: ((Dx8D3DLVERTEX new) x: 1; y: 1; z: 1; color: c111;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 21 put: ((Dx8D3DLVERTEX new) x: 1; y: -1; z: -1; color: c100;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 22 put: ((Dx8D3DLVERTEX new) x: 1; y: 1; z: 1; color: c111;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 23 put: ((Dx8D3DLVERTEX new) x: 1; y: -1; z: -1; color: c100;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 24 put: ((Dx8D3DLVERTEX new) x: 1; y: -1; z: 1; color: c101;
specular: 0; tu: 0 ; tv: 0; yourself).
"Oben"
        cube at: 25 put: ((Dx8D3DLVERTEX new) x: -1; y: 1; z: 1; color: c011;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 26 put: ((Dx8D3DLVERTEX new) x: 1; y: 1; z: 1; color: c111;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 27 put: ((Dx8D3DLVERTEX new) x: -1; y: 1; z: -1; color: c010;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 28 put: ((Dx8D3DLVERTEX new) x: 1; y: 1; z: 1; color: c111;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 29 put: ((Dx8D3DLVERTEX new) x: -1; y: 1; z: -1; color: c010;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 30 put: ((Dx8D3DLVERTEX new) x: 1; y: 1; z: -1; color: c110;
specular: 0; tu: 0 ; tv: 0; yourself).
"Unten"
        cube at: 31 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z: 1; color: c001;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 32 put: ((Dx8D3DLVERTEX new) x: 1; y: -1; z: 1; color: c101;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 33 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z: -1; color: c000;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 34 put: ((Dx8D3DLVERTEX new) x: 1; y: -1; z: 1; color: c101;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 35 put: ((Dx8D3DLVERTEX new) x: -1; y: -1; z: -1; color: c000;
specular: 0; tu: 0 ; tv: 0; yourself).
        cube at: 36 put: ((Dx8D3DLVERTEX new) x: 1; y: -1; z: -1; color: c100;
specular: 0; tu: 0 ; tv: 0; yourself).

        "set cube geometrie"
        "Create us a blank vertex buffer of the required size"
        vertexBuffer :=  d3dDevice
                createVertexBuffer: cube size * cube first size
                usage: 0
                fvf: litFVF
                pool: D3DPOOL_DEFAULT.

        "Fill the created vertex buffer with the data"
        vertexBuffer setPrivateData: 0 data: cube sizeOfData: (vertexBufferSize
:= cube size * cube first size) flags: 0.

===========
Code END


Reply | Threaded
Open this post in threaded view
|

Re: DirectX 8 - VB example to Dolphin question

Christoph J. Bachinger
Hi folks,

i found the problem and the VB Dx3D-Example runs now under Dolphin (:.

> 2. I'm also a little bit confused about the keyword order of
>     setPrivateData:data:sizeOfData:flags:
>    because in VB the order is different!
>     D3DVertexBuffer8SetData VBuffer, 0, Len(Cube(0)) * 36, 0, Cube(0)

Instead of Class:Method
Dx8Direct3DVertexBuffer8:setPrivateData:data:sizeOfData:flags:
use
Dx8D3DAUXLibrary d3dVertexBuffer8SetData:offset:size:flags:data:

Thanks to all
cjb