Sign in to follow this  
fantasyme

shadow volume Problem

Recommended Posts

class ShadowVolume
{
public:

    void    reset() { m_dwNumVertices = 0L; }
    HRESULT buildShadowVolume( LPD3DXMESH pObject, D3DXVECTOR3 vLight );
    HRESULT render( LPDIRECT3DDEVICE9 pd3dDevice );

private:

	void addEdge( WORD* pEdges, DWORD& dwNumEdges, WORD v0, WORD v1 );

	D3DXVECTOR3 m_pVertices[32000]; // Vertex data for rendering shadow volume
    DWORD       m_dwNumVertices;
};

struct ShadowVertex
{
    D3DXVECTOR4 p;
    D3DCOLOR    color;

	enum FVF
	{
		FVF_Flags = D3DFVF_XYZRHW | D3DFVF_DIFFUSE
	};
};


void initGeometryAndLighting( void )
{
	D3DMATERIAL9 g_pFloorMtrl;
	D3DLIGHT9 g_light0;
	ShadowVolume   *m_pShadowVolume;
	LPDIRECT3DVERTEXBUFFER9  m_pBigSquareVB;

    // Set up a material for the floor quads
	ZeroMemory( &g_pFloorMtrl, sizeof(D3DMATERIAL9) );
    g_pFloorMtrl.Diffuse.r = 1.0f;
    g_pFloorMtrl.Diffuse.g = 1.0f;
    g_pFloorMtrl.Diffuse.b = 1.0f;
    g_pFloorMtrl.Diffuse.a = 1.0f;
    g_pFloorMtrl.Ambient.r = 1.0f;
    g_pFloorMtrl.Ambient.g = 1.0f;
    g_pFloorMtrl.Ambient.b = 1.0f;
    g_pFloorMtrl.Ambient.a = 1.0f;

	//
	// Set up a point light source...
	//

	ZeroMemory( &g_light0, sizeof(D3DLIGHT9) );
	g_light0.Type         = D3DLIGHT_POINT;
	g_light0.Position     = D3DXVECTOR3( 2.0f, 2.0f, 0.0f ); // World-space position
	g_light0.Diffuse.r    = 1.0f;
    g_light0.Diffuse.g    = 1.0f;
    g_light0.Diffuse.b    = 1.0f;
    g_light0.Range        = 100.0f;
	g_light0.Attenuation0 = 1.0f;
    g_light0.Attenuation1 = 0.0f;

    g_pD3DDevice->SetLight( 0, &g_light0 );
	g_pD3DDevice->LightEnable( 0, TRUE );

	//
	// Create a big square for rendering the stencil buffer contents...
	//

    g_pD3DDevice->CreateVertexBuffer(4*sizeof(ShadowVertex),
                                      D3DUSAGE_WRITEONLY, ShadowVertex::FVF_Flags,
                                      D3DPOOL_MANAGED, &m_pBigSquareVB,0 );


	// Get the width & height of the back-buffer.
    LPDIRECT3DSURFACE9 pBackBuffer = NULL;
	D3DSURFACE_DESC d3dsd;
    g_pD3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
    pBackBuffer->GetDesc( &d3dsd );
    pBackBuffer->Release();
	float sx = (float)d3dsd.Width;
	float sy = (float)d3dsd.Height;

	// Set the size of the big square shadow
    ShadowVertex *v;

    m_pBigSquareVB->Lock( 0, 0, BYTE**(&v), 0 );//<--the complier error said cannot change BYTE to void**
	{
		v[0].p = D3DXVECTOR4(  0, sy, 0.0f, 1.0f );
		v[1].p = D3DXVECTOR4(  0,  0, 0.0f, 1.0f );
		v[2].p = D3DXVECTOR4( sx, sy, 0.0f, 1.0f );
		v[3].p = D3DXVECTOR4( sx,  0, 0.0f, 1.0f );
		v[0].color = 0x7f000000;
		v[1].color = 0x7f000000;
		v[2].color = 0x7f000000;
		v[3].color = 0x7f000000;
	}
    m_pBigSquareVB->Unlock();

	//
	// Finally, construct a shadow volume object...
	//

    m_pShadowVolume = new ShadowVolume();
}


in the code, i got complier error (please look at the code) i want to do shadow volume. i got this code from internet and i try to apply for my program. if someone think it won't work please tell me. thanks

Share this post


Link to post
Share on other sites
m_pBigSquareVB->Lock( 0, 0, BYTE**(&v), 0 )
should be:
m_pBigSquareVB->Lock( 0, 0, (BYTE**)(&v), 0 )

I'd highly recommend taking a step back and learning C++ before jumping into Direct3D - you're just going to end up confusing yourself, and getting something working without knowing why, or even knowing if it works properly - just because the code compiles and runs on your machine, doesn't mean that it won't just crash at startup on someone elses machine.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this