Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


programci_84

Member Since 23 Feb 2009
Offline Last Active Oct 08 2013 11:29 PM

#4921661 is it necessary to invoke SetVertexDelaration() before we use effect?

Posted by programci_84 on 13 March 2012 - 09:11 AM

There's an exact vertex declaration equivalent for every FVF. And every mesh has a FVF property. So, you don't need to manually call IDirect3DDevice9::SetVertexDeclaration(), because ID3DXMesh::DrawSubset() function calls IDirect3DDevice9::SetVertexDeclaration() before calling SetStreamSource() and SetIndices().


#4916947 CloneMesh()

Posted by programci_84 on 27 February 2012 - 04:33 AM

I know how to specify memory pool. But don't know if not specify memory pool, just giving only D3DUSAGE_WRITEONLY, which memory pool it resides.

You've 2 memory pool parameters for D3DX Mesh functions: D3DXMESH_MANAGED and D3DXMESH_SYSTEMMEM. If you don't specify one of'em, the function will choose D3DPOOL_DEFAULT for both vertex and index buffer of the mesh. So, if you specify only D3DXMESH_WRITEONLY, buffers will reside default memory pool.

I had found the sentence---"Buffers created with D3DPOOL_DEFAULT that do not specify D3DUSAGE_WRITEONLY might suffer a severe performance penalty.".
But I don't understand it well, does it mean if specify D3DUSAGE_WRITEONLY, the memory pool is D3DPOOL_DEFAULT?

maybe that's it meaning.Posted Image

As far as I understand, the sentence says: "Unless you specify D3DUSAGE_WRITEONLY, D3DPOOL_DEFAULT is a bad choice for memory pool. i.e. D3DPOOL_DEFAULT works well with only D3DUSAGE_WRITEONLY".

hth.
-R


#4916444 CloneMesh()

Posted by programci_84 on 25 February 2012 - 01:18 AM

D3DXMESH_MANAGED means D3DPOOL_MANAGED for vertex and index buffer of the mesh. Like this one, D3DXMESH_WRITEONLY means D3DUSAGE_WRITEONLY for both vertex and index bufferof the mesh.

So, you can check DX docs for D3DUSAGE and D3DPOOL. Docs say about D3DUSAGE_WRITEONLY: "Buffers created with D3DPOOL_DEFAULT that do not specify D3DUSAGE_WRITEONLY might suffer a severe performance penalty."


#4916161 Why resizing window causes OnCreateDevice() to be invoked?

Posted by programci_84 on 24 February 2012 - 04:47 AM

Basically, if you change some properties defined in D3DPRESENT_PARAMETERS object (like auto depth buffer usage, window dimensions etc.), it's recommended to reset your device. You don't have to do that for resizing, but, for example, if you resize the window in windowed mode and if you don't reset the device, rendered image may be distorted each time you resized the window. If you want to change device properties (e.g. Vertex Processing: like switching from H/W to Pure HW, Device Type: like switching HAL to REF), you must release your device then recreate.

Before you reset or release the device, you must release all the memory but in D3DPOOL_MANAGED (e.g. D3DXLoadMeshFromX function creates meshes in D3DPOOL_MANAGED). After resetting or recreating, you must recreate corresponding memory.

hth.
-R


#4903166 CreateDevice D3DERR_INVALIDCALL - How to solve without debug runtime?

Posted by programci_84 on 16 January 2012 - 02:33 AM

* Check for device support. For example, if you want a HAL device, and D3DFMT_D16 for depthbuffer and D3DFMT_R5G6B5 for backbuffer and the device don't support them, device creation will fail.

* Check D3DPRESENT_PARAMETERS object you filled. Don't forget to zeroe the object first, then begin filling. Like this:
D3DPRESENT_PARAMETERS pp;
::RtlZeroMemory (&pp, sizeof (pp));

bool _windowed = true; //I suppose
pp.AutoDepthStencilFormat		= D3DFMT_D24X8;
pp.EnableAutoDepthStencil		= true;
pp.BackBufferCount				= 1;
pp.BackBufferFormat				= D3DFMT_X8R8G8B8;
pp.BackBufferHeight				= 0;
pp.BackBufferWidth				= 0;
pp.Flags						= D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
pp.FullScreen_RefreshRateInHz	= 0;
pp.hDeviceWindow				= 0;
pp.MultiSampleQuality			= 0;
pp.MultiSampleType				= D3DMULTISAMPLE_NONE;;
pp.PresentationInterval			= D3DPRESENT_INTERVAL_IMMEDIATE;
pp.SwapEffect					= D3DSWAPEFFECT_DISCARD;
pp.Windowed						= _windowed;

If you don't zeroe pp object and don't fill some members, those members will get random values (e.g. pp.MultisampleQuality = 135438734 or pp.BackBufferCount = 87684543). So, IDirect3D9::CreateDevice() will fail.

hth.
-R


#4894109 Manualy Filling A ID3DXMesh

Posted by programci_84 on 15 December 2011 - 01:55 AM

how would i manually set the vertexes / normals / textures and what ever else is required ?


First, declare your own vertex structure that contains each data you need. Like this one:
struct Vertex_POS_NOR_TEX
{
	vector3 position;
	vector3 normal;
	vector2 texCoords;
};

Then create a vertex declaration:
D3DVERTEXELEMENT9 vertElem[] = 
{
	{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
	{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
	{0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
};
Note that the order of each element is the same as your vertex structure. The second parameter of each element is very important. It tells you how much bytes the distance (offset in bytes) between current element and the head is. In our example, the head is POSITION (because in our Vertex_POST_NOR_TEX structure, the first member is position), so the second parameter must be 0. You know, a float is 4-bytes long. So, NORMAL data must be 12 bytes distant from head, because POSITION has 3 floats (3 x 4bytes = 12 bytes). TEXCOORD data is 20 bytes distant to the head, because NORMAL has 3 floats and TEXCOORD has 2 floats. In total, 5 floats = 5 x 4 = 20 bytes.

After that, you can create your mesh:
LPD3DXMESH pYourMesh = NULL;
D3DXCreateMesh (yourVertexCount, yourPolygonCount, D3DXMESH_MANAGED, vertElem /* take a look above */, yourD3DDevice, &pYourMesh);
Note that D3DXMESH_MANAGED flag can be different and depends on your need. For example, if you manipulate your mesh frequently, you can use D3DXMESH_DYNAMIC. For details, take a look at D3DXMESH flags in SDK docs.

Now the most important step comes: Filling the buffers. As nik02 said, ID3DXMesh interface lets you play with vertex and index buffers, also attribute buffers (for subset manipulating). You can think of ID3DXMesh interface like this:
struct ID3DXMesh
{
 	LPDIRECT3DVERTEXBUFFER9 pVertBuf;
 	LPDIRECT3DINDEXBUFFER9 pIndexBuf;
 	DWORD polyCount;
 	DWORD vertCount;

 	// blah blah...
};
For vertices, lock the vertex buffer, copy your vertex data, and unlock it. And for indices, lock the index buffer, copy your index data, and unlock it. Don't forget to call optimization functions: ID3DXMesh::OptimizeInplace(), D3DXCleanMesh(), D3DXWeldVertices(), ....

That's it! You created your mesh and now you can draw it by calling ID3DXMesh::DrawSubset().

how do you normally handle models ?( IE: do you use your own model loader / manager etc )


I'm using my own model loader. It reads the data from file and creates meshes per subsets:
For each subset returned from file
{
	Create a vertex buffer and an index buffer;
	Create a texture;
	Create an effect/shader
	Fill the buffers;
	Load the texture;
	Load the effect;
	Fill other members (i.e. vertex count, index count, vertex size etc.)
}

To draw the entire model, I call IDirect3DDevice9::SetIndices(), IDirect3DDevice9::SetStreamSource() and IDirect3DDevice9::DrawIndexedPrimitive().

PS: Some links and book excerpts might be useful for you:
- Introduction to 3D Game Programming with DirectX 9.0c : A Shader Approach (from F. Luna) - Chapter 14 Available at Google Books
- http://www.scribd.co...Creating-a-Mesh
- MSDN, SDK docs and samples.

hth.
-R


#4835352 [DX9][C++] Using D3DXFillTexture to create GUI panels

Posted by programci_84 on 14 July 2011 - 11:57 AM

Color value parameters must be [0.f, 1.f] range.

So, try this:
VOID WINAPI 
ColorFillGrey (D3DXVECTOR4* pOut, const D3DXVECTOR2* pTexCoord, const D3DXVECTOR2* pTexelSize, LPVOID pData)
{	
	*pOut = D3DXVECTOR4(150.f / 255.f, 150.f / 255.f, 150.f / 255.f, 1.f);
}



#4823210 need some fixes for my coding, thanks :)

Posted by programci_84 on 14 June 2011 - 07:33 AM

The code displays the original mesh that comes with the book fine. But can't display mine no matter how I tweak it.


I think it comes from D3DXFRAME::Name.

In your ::CreateFrame() function, set Name parameter to NULL first, then do whatever you want:

HRESULT BoneHierarchyLoader::CreateFrame(LPCSTR Name, LPD3DXFRAME *ppNewFrame)
{
        Bone *newBone = new Bone;
        memset(newBone, 0, sizeof(Bone));

        newBone->Name = NULL; // <---- I've added this line!
        
        //Copy name
        if(Name != NULL)
        {
                newBone->Name = new char[strlen(Name)+1];
                strcpy(newBone->Name, Name);
        }

        //Set the transformation matrices
        D3DXMatrixIdentity(&newBone->TransformationMatrix);
        D3DXMatrixIdentity(&newBone->CombinedTransformationMatrix);

        //Return the new bone...
        *ppNewFrame = (D3DXFRAME*)newBone;

        return S_OK;
}
hth.
-R


#4809283 [DX9] Game crashing on other computers

Posted by programci_84 on 10 May 2011 - 11:22 PM

Sorry, I don't have any time to download and test your app.

But the only thing I can say is this: Check for all device types (HAL or REF), render target and/or adapter formats (XRGB8, ARGB8, R5G6B5 and other 16- or 32- bit FP formats etc.) and vertex processing types (Hardware or Software) before you create your D3D Device. Because, for example, on your machine, you can create a HAL D3D device with Hardware Vertex Processing; but other machine(s) may support only software vertex processing. If so, it's so normal for application to crash.

IDirect3D9 interface has a lot of useful methods to test'em: CheckDeviceFormat(), CheckAdapterFormat(), EnumAdapterModes() etc.

hth.
-R


#4791350 Full screen quad through shader problem

Posted by programci_84 on 28 March 2011 - 09:00 AM

I think that passing through shader but not touching position and texcoord might not cause any problems.

For example:
void VS_FSQ (in float4 in_posH : POSITION, in float2 in_texC : TEXCOORD0, out out_posH : POSITION, out out_texC : TEXCOORD0)
{
	out_texC = in_texC;
	out_posH = in_posH;
}

float4 PS_FSQ (float2 texC : TEXCOORD0) : COLOR0
{
   return tex2D (smpSomeSampler, texC);
}

NOTE: You must create a vertex declaration:
D3DVERTEXELEMENT9 vFSQ [ ] = 
{
      { 0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, 
      { 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
      D3DDECL_END() 
};

LPDIRECT3DVERTEXDECLARATION9 pDecl_FSQ = NULL;
yourD3DDevice->CreateVertexDeclaration (vFSQ, &pDecl_FSQ);

...and set it before rendering full screen quad with a shader like above:
LPDIRECT3DVERTEXDECLARATION9 pDecl_Curr = NULL;
yourD3DDevice->GetVertexDeclaration (&pDecl_Curr);
yourD3DDevice->SetVertexDeclaration (pDecl_FSQ);

//your FSQ rendering code goes here!

yourD3DDevice->SetVertexDeclaration (pDecl_Curr);

hth.
-R


#4786383 Animating multiple objects

Posted by programci_84 on 16 March 2011 - 01:03 AM

FVFs don't contain anything related to matrices; so you have to do that on your own.

Don't play with FVFs, play with vertex declarations instead. Here's an example:
D3DVERTEXELEMENT9 vPNT [ ] = 
{
      { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, 
      { 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
      { 0, 20, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },  //world matrix, 1st row
      { 0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2 },  //2nd row
      { 0, 44, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 3 }   //3rd row
      { 0, 56, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 4 }   //4th row
      D3DDECL_END() 
};

Each frame, you may have to Lock & Unlock the corresponding vertex buffer to embed matrix information to a vertex.

I recommend you to google for Instancing. SDK has a great example about it as well.

Btw, using debug runtimes causes performance hit. Why don't you use Release?

hth.
-R


#4767465 updating D3DLIGHT9

Posted by programci_84 on 31 January 2011 - 08:09 AM

Does the light that you want to update (at index 0) work properly?

I recommend you to go step by step:
First, call GetLight() and get the light at index 0. Then, only update diffuse color. If no error occurs, then update ambient color. And if no error occurs, update other property etc. etc. etc.

Also, doc says "You can call IDirect3DDevice9::SetLight with new information as needed to update the light's illumination properties.". There's a point here: "light's illumination properties". What do they exactly mean with illumination property?
Are position and direction vectors illumination property?
Or type?

I dunno, but I think that this is where the problem comes.

hth.
-R


PARTNERS