Page 1 of 1

dx9 help [SOLVED]

Posted: Wed Apr 09, 2008 12:52 pm
by spike0314
Hi all
im trying to use Dx9 to create a Mesh but i can seem to get this peace of code to work. ( :( ive been at this peace of code four 2 days now :( :( )

Code: Select all

LocalMesh.ID3DXMesh

 Dim vertices.MYVERTEX(3)

  vertices(0)\x = 0.0
  vertices(0)\y = 10.0
  vertices(0)\z = 50
  vertices(0)\color = D3DCOLOR_ARGB(255,255,0,0)


  vertices(1)\x = 10.0
  vertices(1)\y = 0.0
  vertices(1)\z = 50
vertices(1)\color = D3DCOLOR_ARGB(255,0,255,0)
  
  vertices(2)\x = -10.0
  vertices(2)\y = 0.0
  vertices(2)\z = 50
    vertices(2)\color = D3DCOLOR_ARGB(255,0,0,255)

 D3DXCreateMeshFVF(1,3,#D3DXMESH_MANAGED ,#D3DFVF_XYZ | #D3DFVF_DIFFUSE,MMS_D3DDEVICE , @LocalMesh)

Protected *pVertices=0  
LocalMesh\LockVertexBuffer(0 , @*pVertices)
CopyMemory(@vertices(),*pVertices, 3*16)
    
LocalMesh\UnlockVertexBuffer()
all it does is use the first vertexbut will not add 1 or 2.

Posted: Wed Apr 09, 2008 3:20 pm
by Rook Zimbabwe
you only dim 3 places in your array 0 - 3, you call for 12

You could use a 3d array and tell the 0,0 0,1 0,2 0,3 :: 1,0 1,1 1,2 1,3 :: 2,0 2,1 2,2 2,3 the values and then pop them out...

Posted: Wed Apr 09, 2008 4:12 pm
by spike0314
Im sorry i dont under stand what you mean?? :oops:

Posted: Wed Apr 09, 2008 9:19 pm
by SFSxOI
I think he means it should be this:

Code: Select all

Dim vertices.MYVERTEX(11)

and not...

Dim vertices.MYVERTEX(3)


Posted: Wed Apr 09, 2008 9:33 pm
by Derek
Presumably MYVERTEX is a structure used to assign 4 variables so there is in fact nothing wrong with the dim().

Posted: Wed Apr 09, 2008 10:08 pm
by spike0314
MYVERTEX is a structure

and this is the structure layout

Code: Select all

Structure MYVERTEX
    x.f
    y.f
    z.f
    color.l
EndStructure

I think the problem lies with-in "*pVertices" as it only adds vertices(0) to the mesh.

Posted: Wed Apr 09, 2008 10:14 pm
by SFSxOI
Yep, what happens when you try

Code: Select all

Dim vertices.MYVERTEX(11)

Posted: Wed Apr 09, 2008 10:19 pm
by spike0314
same only shows vertices(0) :(

Posted: Thu Apr 10, 2008 9:10 am
by tinman
Have you tried the other functions of the interface, to check whether you are just reading it back incorrectly?

For example, what do

LocalMesh\GetNumBytesPerVertex()

and

LocalMesh\GetNumVertices()

give as results?

Posted: Thu Apr 10, 2008 2:22 pm
by spike0314
ok this is ding my head in now.

@Tinman
i have tryed LocalMesh\GetNumVertices() but that will always just return the number that is in D3DXCreateMeshFVF(faces,vertex)
so it will return 3.

as for LocalMesh\GetNumBytesPerVertex() that returns 16 as it's the size of the structure.

I have sent this screenshot of my results:
Image

and i have also used this command in the main loop

Code: Select all

D3DDEVICE\SetRenderState(#D3DRS_FILLMODE,   #D3DFILL_POINT )

Posted: Thu Apr 10, 2008 6:23 pm
by spike0314
:D :D :D I found my problem.

The way it works is if you dont render the face's it will only show 1 vertex
:oops:

Posted: Thu Apr 10, 2008 10:42 pm
by SFSxOI
??
can you post the complete code?

Posted: Thu Apr 10, 2008 11:24 pm
by spike0314
here is the code:

Code: Select all


localmesh.ID3DXMesh

Structure MYVERTEX
    x.f
    y.f
    z.f
    color.l
EndStructure

Dim vertices.MYVERTEX(3)

  vertices(0)\x = 0.0
  vertices(0)\y = 10.0
  vertices(0)\z = 50
  vertices(0)\color = D3DCOLOR_ARGB(255,255,0,0)


  vertices(1)\x = 10.0
  vertices(1)\y = 0.0
  vertices(1)\z = 50
  vertices(1)\color = D3DCOLOR_ARGB(255,0,255,0)
  
  vertices(2)\x = -10.0
  vertices(2)\y = 0.0
  vertices(2)\z = 50
  vertices(2)\color = D3DCOLOR_ARGB(255,0,0,255)
  
 
 D3DXCreateMeshFVF(1,3,#D3DXMESH_MANAGED |#D3DXMESH_32BIT ,#D3DFVF_XYZ | #D3DFVF_DIFFUSE,MMS_D3DDEVICE , @LocalMesh)

*pVert=#Null

  *pVBuf.IDIRECT3DVERTEXBUFFER9;
 LocalMesh\GetVertexBuffer(@*pVBuf)
  *pVBuf\Lock( 0, 0, @*pVert, 0 )
      CopyMemory(vertices(),*pVert,3* SizeOf(MYVERTEX))

  	  Debug PeekF(*pVert)
	  Debug PeekF(*pVert+4)
	  Debug PeekF(*pVert+8)
	  Debug PeekL(*pVert+12)
	    
  	  Debug PeekF(*pVert+16)
	  Debug PeekF(*pVert+20)
	  Debug PeekF(*pVert+24)
	  Debug PeekL(*pVert+28)
	    
	  Debug PeekF(*pVert+32)
	  Debug PeekF(*pVert+36)
	  Debug PeekF(*pVert+40)
	  Debug PeekL(*pVert+44)  
	  
*pVBuf\Unlock()
*pVBuf\Release()

*pInd=#Null
LocalMesh\LockIndexBuffer(#D3DLOCK_DISCARD,@*pInd)
      PokeL(*pInd,0)
      PokeL(*pInd+4,1)
      PokeL(*pInd+8,2)
LocalMesh\UnlockIndexBuffer();
hope that helps