Exemple #1
0
/******************************Public*Routine*****************************\
* Initialize
\**************************************************************************/
STDMETHODIMP
CGameUILayer::Initialize(
                       IDirect3DDevice9 *pDevice)
{
    HRESULT hr = S_OK;

    // load buttons from resources
    if( m_bInitialized )
    {
        return VFW_E_WRONG_STATE;
    }
    if( !pDevice )
    {
        return E_POINTER;
    }

    try
    {
        CHECK_HR(
            hr = D3DXCreateTextureFromResource( pDevice,
                                                NULL,
                                                MAKEINTRESOURCE( IDB_UIBTN_RESUME ),
                                                &m_pTextureButtonView ),
        DbgMsg("CGameUILayer::Initialize: failed to load texture for the button, hr = 0x%08x", hr));

        CHECK_HR(
            hr = D3DXCreateTextureFromResource( pDevice,
                                                NULL,
                                                MAKEINTRESOURCE( IDB_UIBTN_VIEW ),
                                                &m_pTextureButtonResume ),
        DbgMsg("CGameUILayer::Initialize: failed to load texture for the button, hr = 0x%08x", hr));
    }
    catch( HRESULT hr1 )
    {
        hr = hr1;
    }
    return hr;
}
/**
* Render the Oculus Rift View.
***/
void* OculusRenderer::Provoke(void* pThis, int eD3D, int eD3DInterface, int eD3DMethod, DWORD dwNumberConnected, int& nProvokerIndex)	
{
	// return if wrong call
	if ((eD3D >= (int)AQU_DirectXVersion::DirectX_9_0) &&
		(eD3D <= (int)AQU_DirectXVersion::DirectX_9_29))
	{
		if (((eD3DInterface == INTERFACE_IDIRECT3DDEVICE9) &&
			(eD3DMethod == METHOD_IDIRECT3DDEVICE9_PRESENT)) || 
			((eD3DInterface == INTERFACE_IDIRECT3DDEVICE9) &&
			(eD3DMethod == METHOD_IDIRECT3DDEVICE9_ENDSCENE)) ||
			((eD3DInterface == INTERFACE_IDIRECT3DSWAPCHAIN9) &&
			(eD3DMethod == METHOD_IDIRECT3DSWAPCHAIN9_PRESENT)))
		{
			(pThis);
		}
		else return nullptr;
	}
	else
		return nullptr;

	// get input data
	if (m_paInput[(int)ORN_Decommanders::LeftTexture])
		m_pcTextureLeft = *(LPDIRECT3DTEXTURE9*)m_paInput[(int)ORN_Decommanders::LeftTexture];
	else 
		m_pcTextureLeft = nullptr;
	if (m_paInput[(int)ORN_Decommanders::RightTexture])
		m_pcTextureRight = *(LPDIRECT3DTEXTURE9*)m_paInput[(int)ORN_Decommanders::RightTexture];
	else m_pcTextureRight = nullptr;

	if (m_paInput[(int)ORN_Decommanders::DistortionVertexBufferLeft])
		if (*(LPDIRECT3DVERTEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionVertexBufferLeft])
			m_pcDistortionVertexBufferLeft = **(LPDIRECT3DVERTEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionVertexBufferLeft];
		else m_pcDistortionVertexBufferLeft = nullptr;
	else m_pcDistortionVertexBufferLeft = nullptr;
	if (m_paInput[(int)ORN_Decommanders::DistortionVertexBufferRight])
		if (*(LPDIRECT3DVERTEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionVertexBufferRight])
			m_pcDistortionVertexBufferRight = **(LPDIRECT3DVERTEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionVertexBufferRight];
		else m_pcDistortionVertexBufferRight = nullptr;
	else m_pcDistortionVertexBufferRight = nullptr;
	if (m_paInput[(int)ORN_Decommanders::DistortionIndexBufferLeft])
		if (*(LPDIRECT3DINDEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionIndexBufferLeft])
			m_pcDistortionIndexBufferLeft = **(LPDIRECT3DINDEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionIndexBufferLeft];
		else m_pcDistortionIndexBufferLeft = nullptr;
	else m_pcDistortionIndexBufferLeft = nullptr;
	if (m_paInput[(int)ORN_Decommanders::DistortionIndexBufferRight])
		if (*(LPDIRECT3DINDEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionIndexBufferRight])
			m_pcDistortionIndexBufferRight = **(LPDIRECT3DINDEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionIndexBufferRight];
		else m_pcDistortionIndexBufferRight = nullptr;
	else m_pcDistortionIndexBufferRight = nullptr;
	if (m_paInput[(int)ORN_Decommanders::OculusVertexDeclaration])
		if (*(LPDIRECT3DVERTEXDECLARATION9**)m_paInput[(int)ORN_Decommanders::OculusVertexDeclaration])
			m_pcVertexDecl = **(LPDIRECT3DVERTEXDECLARATION9**)m_paInput[(int)ORN_Decommanders::OculusVertexDeclaration];
		else m_pcVertexDecl = nullptr;
	else m_pcVertexDecl = nullptr;
	if (m_paInput[(int)ORN_Decommanders::DefaultEyeFovLeft])
		if (*(ovrFovPort**)m_paInput[(int)ORN_Decommanders::DefaultEyeFovLeft])
			m_psFOVPortLeft = *(ovrFovPort**)m_paInput[(int)ORN_Decommanders::DefaultEyeFovLeft];
		else m_psFOVPortLeft = nullptr;
	else m_psFOVPortLeft = nullptr;
	if (m_paInput[(int)ORN_Decommanders::DefaultEyeFovRight])
		if (*(ovrFovPort**)m_paInput[(int)ORN_Decommanders::DefaultEyeFovRight])
			m_psFOVPortRight = *(ovrFovPort**)m_paInput[(int)ORN_Decommanders::DefaultEyeFovRight];
		else m_psFOVPortRight = nullptr;
	else m_psFOVPortRight = nullptr;

	// get device 
	LPDIRECT3DDEVICE9 pcDevice = nullptr;
	bool bReleaseDevice = false;
	if (eD3DInterface == INTERFACE_IDIRECT3DDEVICE9)
	{
		pcDevice = (LPDIRECT3DDEVICE9)pThis;
	}
	else if (eD3DInterface == INTERFACE_IDIRECT3DSWAPCHAIN9)
	{
		LPDIRECT3DSWAPCHAIN9 pSwapChain = (LPDIRECT3DSWAPCHAIN9)pThis;
		if (!pSwapChain) 
		{
			OutputDebugString(L"Oculus Renderer Node : No swapchain !");
			return nullptr;
		}
		pSwapChain->GetDevice(&pcDevice);
		bReleaseDevice = true;
	}
	if (!pcDevice)
	{
		OutputDebugString(L"Oculus Renderer Node : No device !");
		return nullptr;
	}

	// Original code (LibOVR) :
	// pShaderCode = ShaderCompile("precompiledVertexShaderSrc",VertexShaderSrc,"vs_2_0");
	// pShaderCode = ShaderCompile("precompiledVertexShaderTimewarpSrc",VertexShaderTimewarpSrc,"vs_3_0");
	// pShaderCode = ShaderCompile("precompiledPixelShaderSrc",PixelShaderSrc,"ps_3_0");

	// pixel shader created ?
	if (!m_pcOculusPixelShader)
	{
		LPD3DXBUFFER pShader;

		// compile and create shader
		if (SUCCEEDED(D3DXCompileShader(PixelShaderSrc,strlen(PixelShaderSrc),NULL,NULL,"main","ps_3_0",NULL,&pShader,NULL,&m_pcOculusPixelShaderCT)))
		{
			OutputDebugString(L"Pixel shader compiled!");
			pcDevice->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), &m_pcOculusPixelShader);
		}
	}

	// vertex shader created ?
	if (!m_pcOculusVertexShader)
	{
		LPD3DXBUFFER pShader;

		// compile and create shader
		if (SUCCEEDED(D3DXCompileShader(VertexShaderSrc,strlen(VertexShaderSrc),NULL,NULL,"main","vs_2_0",NULL,&pShader,NULL,&m_pcOculusVertexShaderCT)))
		{
			OutputDebugString(L"Vertex shader compiled!");
			pcDevice->CreateVertexShader((DWORD*)pShader->GetBufferPointer(), &m_pcOculusVertexShader);
		}
	}

	// side by side pixel shader ?
	if (!m_pcSideBySidePixelShader)
	{
		LPD3DXBUFFER pShader;

		// compile and create shader
		if (SUCCEEDED(D3DXCompileShader(PixelShaderSrcSideBySide,strlen(PixelShaderSrcSideBySide),NULL,NULL,"SBS","ps_2_0",NULL,&pShader,NULL,&m_pcSideBySidePixelShaderCT)))
		{
			OutputDebugString(L"Pixel shader compiled!");
			pcDevice->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), &m_pcSideBySidePixelShader);
		}

	}

	// test textures created ?
	if ((!m_pcTextureRightTest) || (!m_pcTextureLeftTest))
	{
		HMODULE hModule = GetModuleHandle(L"OculusRenderer.dll");

		if (!m_pcTextureLeftTest)
		{
			// create a test texture
			if (SUCCEEDED(D3DXCreateTextureFromResource(pcDevice, hModule, MAKEINTRESOURCE(IMG_BACKGROUND01), &m_pcTextureLeftTest)))
				OutputDebugString(L"Texture created !");
			else m_pcTextureLeftTest = nullptr;
		}
		if (!m_pcTextureRightTest)
		{
			// create a test texture
			if (SUCCEEDED(D3DXCreateTextureFromResource(pcDevice, hModule, MAKEINTRESOURCE(IMG_BACKGROUND02), &m_pcTextureRightTest)))
				OutputDebugString(L"Texture created !");
			else m_pcTextureRightTest = nullptr;
		}
	}

	// default vertex buffer ?
	if (!m_pcVertexBufferDefault)
	{
		InitDefaultVertexBuffer(pcDevice);
		if (!m_pcVertexBufferDefault) return nullptr;
	}

	// vertex buffers ? index buffers ? not all present ?
	if ((!m_pcDistortionVertexBufferLeft) || (!m_pcDistortionVertexBufferRight) ||
		(!m_pcDistortionIndexBufferLeft) || (!m_pcDistortionIndexBufferRight) ||
		(!m_pcVertexDecl))
	{
		if (m_bBuffersConnected)
		{
			// clear all descriptions for safety
			ZeroMemory(&m_sVertexBufferDescLeft, sizeof(D3DVERTEXBUFFER_DESC));
			ZeroMemory(&m_sVertexBufferDescRight, sizeof(D3DVERTEXBUFFER_DESC));
			ZeroMemory(&m_sIndexBufferDescLeft, sizeof(D3DINDEXBUFFER_DESC));
			ZeroMemory(&m_sIndexBufferDescRight, sizeof(D3DINDEXBUFFER_DESC));

			m_bBuffersConnected = false;
		}
	}
	else
	{
		m_bBuffersConnected = true;

		// vertex buffer description ? left
		if (!m_sVertexBufferDescLeft.Size)
			m_pcDistortionVertexBufferLeft->GetDesc(&m_sVertexBufferDescLeft);

		// vertex buffer length matches oculus vertex type ?
		if ((m_sVertexBufferDescLeft.Size % sizeof(ovrDistortionVertex)) != 0)
		{
			OutputDebugString(L"OculusRenderer Node : Connected vertex buffer size mismatch !");
			return nullptr;
		}

		// and right
		if (!m_sVertexBufferDescRight.Size)
			m_pcDistortionVertexBufferRight->GetDesc(&m_sVertexBufferDescRight);

		// vertex buffer length matches oculus vertex type ?
		if ((m_sVertexBufferDescRight.Size % sizeof(ovrDistortionVertex)) != 0)
		{
			OutputDebugString(L"OculusRenderer Node : Connected vertex buffer size mismatch !");
			return nullptr;
		}

		// index buffer ?
		if ((!m_pcDistortionIndexBufferLeft) || (!m_pcDistortionIndexBufferRight))
			return nullptr;

		// index buffer description ?
		if (!m_sIndexBufferDescLeft.Size)
		{
			m_pcDistortionIndexBufferLeft->GetDesc(&m_sIndexBufferDescLeft);

			// index buffer length matches vertex buffer size ? TODO !!
			/*if ()
			{
			OutputDebugString(L"OculusRenderer Node : Connected index buffer size mismatch !");
			return nullptr;
			}*/
		}
		if (!m_sIndexBufferDescRight.Size)
		{
			m_pcDistortionIndexBufferRight->GetDesc(&m_sIndexBufferDescRight);

			// index buffer length matches vertex buffer size ? TODO !!
			/*if ()
			{
			OutputDebugString(L"OculusRenderer Node : Connected index buffer size mismatch !");
			return nullptr;
			}*/
		}
	}

	// start to render
	pcDevice->BeginScene();

	// save states
	IDirect3DStateBlock9* pStateBlock = nullptr;
	pcDevice->CreateStateBlock(D3DSBT_ALL, &pStateBlock);

	// set ALL render states to default
	SetAllRenderStatesDefault(pcDevice);

	// set states
	pcDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
	pcDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	pcDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	pcDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CONSTANT);
	pcDevice->SetTextureStageState(0, D3DTSS_CONSTANT, 0xffffffff);
	pcDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	pcDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
	pcDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
	pcDevice->SetSamplerState(0, D3DSAMP_SRGBTEXTURE, 0);
	pcDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
	pcDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
	pcDevice->SetSamplerState(0, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);
	pcDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
	pcDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
	pcDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

	D3DCOLOR clearColor = D3DCOLOR_RGBA(0, 0, 0, 0);

	pcDevice->Clear(0, NULL, D3DCLEAR_TARGET, clearColor, 0, 0);

	// required fields
	D3DSURFACE_DESC sSurfaceDesc;
	ovrSizei sTextureSize;
	ovrRecti sRenderViewport;
	ovrVector2f UVScaleOffset[2];

	// LEFT EYE :

	// left eye, first set stream source, indices
	if (m_bBuffersConnected)
	{
		// no timewarp here, use standard vertex shader, set pixel shader, set vertex declaration
		pcDevice->SetVertexShader( m_pcOculusVertexShader);
		pcDevice->SetPixelShader( m_pcOculusPixelShader );
		pcDevice->SetVertexDeclaration( m_pcVertexDecl );

		// set texture
		if (m_pcTextureLeft)
			pcDevice->SetTexture( 0, m_pcTextureLeft );
		else if (m_pcTextureLeftTest)
			pcDevice->SetTexture( 0, m_pcTextureLeftTest );
		else pcDevice->SetTexture( 0, 0);

		// get texture size
		if (m_pcTextureLeft)
			m_pcTextureLeft->GetLevelDesc(0, &sSurfaceDesc);
		else if (m_pcTextureLeftTest)
			m_pcTextureLeftTest->GetLevelDesc(0, &sSurfaceDesc);
		else ZeroMemory(&sSurfaceDesc, sizeof(D3DSURFACE_DESC));
		sTextureSize.w = (int)sSurfaceDesc.Width;
		sTextureSize.h = (int)sSurfaceDesc.Height;

		// set render viewport size the same size as the texture size (!)
		sRenderViewport.Pos.x = 0;
		sRenderViewport.Pos.y = 0;
		sRenderViewport.Size.w = sTextureSize.w;
		sRenderViewport.Size.h = sTextureSize.h;

		// get and set scale and offset
		if (m_psFOVPortLeft)
			ovrHmd_GetRenderScaleAndOffset(*m_psFOVPortLeft, sTextureSize, sRenderViewport, UVScaleOffset);
		else
			ovrHmd_GetRenderScaleAndOffset(m_sDefaultFOVPortLeft, sTextureSize, sRenderViewport, UVScaleOffset);
		pcDevice->SetVertexShaderConstantF( 0, ( FLOAT* )&UVScaleOffset[0], 1 );
		pcDevice->SetVertexShaderConstantF( 2, ( FLOAT* )&UVScaleOffset[1], 1 );

		pcDevice->SetStreamSource( 0, m_pcDistortionVertexBufferLeft,0, sizeof(ovrDistortionVertex) );
		pcDevice->SetIndices( m_pcDistortionIndexBufferLeft);

		// draw
		pcDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0, m_sVertexBufferDescLeft.Size / sizeof(ovrDistortionVertex) , 0, m_sIndexBufferDescLeft.Size / 6 );
	}
	else
	{
		pcDevice->SetSamplerState(1, D3DSAMP_SRGBTEXTURE, 0);
		pcDevice->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
		pcDevice->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
		pcDevice->SetSamplerState(1, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);
		pcDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
		pcDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
		pcDevice->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

		// side by side render
		pcDevice->SetVertexShader(NULL);
		pcDevice->SetPixelShader(m_pcSideBySidePixelShader);
		pcDevice->SetVertexDeclaration( NULL );
		pcDevice->SetFVF(D3DFVF_TEXVERTEX);

		// set textures
		if (m_pcTextureLeft)
			pcDevice->SetTexture( 0, m_pcTextureLeft );
		else if (m_pcTextureLeftTest)
			pcDevice->SetTexture( 0, m_pcTextureLeftTest );
		else pcDevice->SetTexture( 0, 0);
		if (m_pcTextureRight)
			pcDevice->SetTexture( 1, m_pcTextureRight );
		else if (m_pcTextureRightTest)
			pcDevice->SetTexture( 1, m_pcTextureRightTest );
		else pcDevice->SetTexture( 1, 0);

		// set stream and draw
		pcDevice->SetStreamSource( 0, m_pcVertexBufferDefault,0, sizeof(TEXVERTEX) );
		pcDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
	}

	// RIGHT EYE:
	if (m_bBuffersConnected)
	{
		// set texture
		if (m_pcTextureRight)
			pcDevice->SetTexture( 0, m_pcTextureRight );
		else if (m_pcTextureRightTest)
			pcDevice->SetTexture( 0, m_pcTextureRightTest );
		else pcDevice->SetTexture( 0, 0);

		// get texture size
		if (m_pcTextureRight)
			m_pcTextureRight->GetLevelDesc(0, &sSurfaceDesc);
		else if (m_pcTextureRightTest)
			m_pcTextureRightTest->GetLevelDesc(0, &sSurfaceDesc);
		else ZeroMemory(&sSurfaceDesc, sizeof(D3DSURFACE_DESC));
		sTextureSize.w = (int)sSurfaceDesc.Width;
		sTextureSize.h = (int)sSurfaceDesc.Height;

		// get and set scale and offset
		if (m_psFOVPortRight)
			ovrHmd_GetRenderScaleAndOffset(*m_psFOVPortRight, sTextureSize, sRenderViewport, UVScaleOffset);
		else
			ovrHmd_GetRenderScaleAndOffset(m_sDefaultFOVPortRight, sTextureSize, sRenderViewport, UVScaleOffset);
		pcDevice->SetVertexShaderConstantF( 0, ( FLOAT* )&UVScaleOffset[0], 1 );
		pcDevice->SetVertexShaderConstantF( 2, ( FLOAT* )&UVScaleOffset[1], 1 );

		// set stream source, indices, draw
		pcDevice->SetStreamSource( 0, m_pcDistortionVertexBufferRight,0, sizeof(ovrDistortionVertex) );
		pcDevice->SetIndices( m_pcDistortionIndexBufferRight);

		// draw
		pcDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0, m_sVertexBufferDescRight.Size / sizeof(ovrDistortionVertex) , 0, m_sIndexBufferDescRight.Size / 6 );
	}

	pcDevice->EndScene();

	// apply and release state block
	if (pStateBlock)
	{
		pStateBlock->Apply();
		pStateBlock->Release();
	}

	// release device if provided by swapchain
	if (bReleaseDevice) pcDevice->Release();

	return nullptr;
}
Exemple #3
0
BOOL initD3dStuff(HWND hWnd) {
    void *tempVoid;
    LPD3DXBUFFER shipMB;
    D3DXMATERIAL *tempMaterials;
    int transparency = 127;

    CUSTOMVERTEX customVertex1[] = {
        //	triangle
        {0.8f, -0.8f, 0.0f, 0, 0, 1, D3DCOLOR_ARGB(255, 255, 255, 255), 0, 0},
        {0.0f, 0.8f, 0.0f, 0, 0, 1, D3DCOLOR_ARGB(255, 255, 255, 255), 1, 0},
        {-0.8f, -0.8f, 0.0f, 0, 0, 1, D3DCOLOR_ARGB(255, 255, 255, 255), 1, 1}
    };
    CUSTOMVERTEX customVertex2[] = {
        //	side 1
        {-3.0f, 3.0f, -3.0f, 0, 0, -1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {3.0f, 3.0f, -3.0f, 0, 0, -1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {-3.0f, -3.0f, -3.0f, 0, 0, -1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {3.0f, -3.0f, -3.0f, 0, 0, -1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1},

        //	side 2
        {-3.0f, 3.0f, 3.0f, 0, 0, 1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {-3.0f, -3.0f, 3.0f, 0, 0, 1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {3.0f, 3.0f, 3.0f, 0, 0, 1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {3.0f, -3.0f, 3.0f, 0, 0, 1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1},

        //	side 3
        {-3.0f, 3.0f, 3.0f, 0, 1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {3.0f, 3.0f, 3.0f, 0, 1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {-3.0f, 3.0f, -3.0f, 0, 1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {3.0f, 3.0f, -3.0f, 0, 1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1},

        //	side 4
        {-3.0f, -3.0f, 3.0f, 0, -1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {-3.0f, -3.0f, -3.0f, 0, -1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {3.0f, -3.0f, 3.0f, 0, -1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {3.0f, -3.0f, -3.0f, 0, -1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1},

        //	side 5
        {3.0f, 3.0f, -3.0f, 1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {3.0f, 3.0f, 3.0f, 1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {3.0f, -3.0f, -3.0f, 1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {3.0f, -3.0f, 3.0f, 1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1},

        //	side 6
        //	I inverted the texture coords to get my image right
        {-3.0f, 3.0f, -3.0f, -1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {-3.0f, -3.0f, -3.0f, -1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {-3.0f, 3.0f, 3.0f, -1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {-3.0f, -3.0f, 3.0f, -1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1}
    };

    //	predefined simple D3DX mesh objects
    D3DXCreateBox(d3d9dev, 7.0f, 3.0f, 3.0f, &mesh1, NULL);
    D3DXCreateSphere(d3d9dev, 0.3f, 20, 10, &mesh2, NULL);

    //	one complete mesh loading (vertices, materials and textures)
    if (D3DXLoadMeshFromXResource(NULL, (LPCSTR)MAKEINTRESOURCE(IDR_MESHX1), "meshx", D3DXMESH_MANAGED, d3d9dev, NULL, &shipMB, NULL, &numMaterials, &mesh3) != D3D_OK) {
        MessageBox(hWnd, "craft.x could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    /*	load from file
    if (D3DXLoadMeshFromX("craft.x", D3DXMESH_MANAGED, d3d9dev, NULL, &shipMB, NULL, &numMaterials, &mesh3) != D3D_OK) {
    	MessageBox(hWnd, "craft.x file not found", "Error", MB_ICONERROR);
    	PostQuitMessage(0);
    }
    */
    tempMaterials = (D3DXMATERIAL *)shipMB->GetBufferPointer();
    materialX = new D3DMATERIAL9[numMaterials];
    planeTexture = new LPDIRECT3DTEXTURE9[numMaterials];
    for (DWORD i = 0; i < numMaterials; i++) {
        materialX[i] = tempMaterials[i].MatD3D;
        materialX[i].Ambient = materialX[i].Diffuse;
        /*	dont need the following cause I use resources
        		USES_CONVERSION;    // allows certain string conversions
        		// if there is a texture to load, load it
        		if(FAILED(D3DXCreateTextureFromFile(d3d9dev, CA2W(tempMaterials[i].pTextureFilename), &planeTexture[i])))
        */			planeTexture[i] = NULL;	// if there is no texture, set the texture to NULL

    }

    // load the textures (embedded in the executable) we will use
    if (D3DXCreateTextureFromResource(d3d9dev, NULL, (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP1), &planeTexture[2]) != D3D_OK) {
        MessageBox(hWnd, "wings.bmp could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    if (D3DXCreateTextureFromResource(d3d9dev, NULL, (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP2), &planeTexture[6]) != D3D_OK) {
        MessageBox(hWnd, "bihull.bmp could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    planeTexture[0] = planeTexture[1] = planeTexture[3] = planeTexture[4] = planeTexture[6];

    if (D3DXCreateTextureFromResourceEx(d3d9dev,	//	the device pointer
                                        NULL,	//	module (executable containing the resource)
                                        (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP3),	//	resource
                                        //"logo1.bmp",	//	the file name
                                        D3DX_DEFAULT,	//	default width
                                        D3DX_DEFAULT,	//	default height
                                        D3DX_DEFAULT,	//	no mip mapping
                                        NULL,	//	regular usage
                                        D3DFMT_A8R8G8B8,	//	32-bit pixels with alpha
                                        D3DPOOL_MANAGED,	//	typical memory handling
                                        D3DX_DEFAULT,	//	no filtering
                                        D3DX_DEFAULT,	//	no mip filtering
                                        D3DCOLOR_ARGB(127, 255, 0, 255),	//	the hot-pink color key
                                        NULL,	//	no image info struct
                                        NULL,	//	not using 256 colors
                                        &texture1) != D3D_OK) {
        MessageBox(hWnd, "logo1.bmp could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    /*	if (D3DXCreateTextureFromResource(d3d9dev, NULL, (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP3), &texture1) != D3D_OK) {
    		MessageBox(hWnd, "logo1.bmp could not be loaded", "Error", MB_ICONERROR);
    		PostQuitMessage(0);
    		return FALSE;
    	}
    */

    if (D3DXCreateTextureFromResourceEx(d3d9dev,	//	the device pointer
                                        NULL,	//	module (executable containing the resource)
                                        (LPCSTR)MAKEINTRESOURCE(IDR_LOGO2PNG),	//	resource
                                        //"logo2.png",	//	the file name
                                        D3DX_DEFAULT,	//	default width
                                        D3DX_DEFAULT,	//	default height
                                        D3DX_DEFAULT,	//	no mip mapping
                                        NULL,	//	regular usage
                                        D3DFMT_A8R8G8B8,	//	32-bit pixels with alpha
                                        D3DPOOL_MANAGED,	//	typical memory handling
                                        D3DX_DEFAULT,	//	no filtering
                                        D3DX_DEFAULT,	//	no mip filtering
                                        D3DCOLOR_ARGB(127, 255, 0, 255),	//	the hot-pink color key
                                        NULL,	//	no image info struct
                                        NULL,	//	not using 256 colors
                                        &texture2) != D3D_OK) {
        MessageBox(hWnd, "logo2.png could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    /*
    	if (D3DXCreateTextureFromResource(d3d9dev, NULL, (LPCSTR)MAKEINTRESOURCE(IDR_LOGO2PNG), &texture2) != D3D_OK) {
    		MessageBox(hWnd, "logo2.png could not be loaded", "Error", MB_ICONERROR);
    		PostQuitMessage(0);
    		return FALSE;
    	}
    */
    if (D3DXCreateTextureFromResourceEx(d3d9dev,	//	the device pointer
                                        NULL,	//	module (executable containing the resource)
                                        (LPCSTR)MAKEINTRESOURCE(IDR_LOGO3PNG),	//	resource
                                        //"logo3.png",	//	the file name
                                        D3DX_DEFAULT,	//	default width
                                        D3DX_DEFAULT,	//	default height
                                        D3DX_DEFAULT,	//	no mip mapping
                                        NULL,	//	regular usage
                                        D3DFMT_A8R8G8B8,	//	32-bit pixels with alpha
                                        D3DPOOL_MANAGED,	//	typical memory handling
                                        D3DX_DEFAULT,	//	no filtering
                                        D3DX_DEFAULT,	//	no mip filtering
                                        D3DCOLOR_ARGB(127, 255, 0, 255),	//	the hot-pink color key
                                        NULL,	//	no image info struct
                                        NULL,	//	not using 256 colors
                                        &texture3) != D3D_OK) {
        MessageBox(hWnd, "logo3.png could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    /*	if (D3DXCreateTextureFromResource(d3d9dev, NULL, (LPCSTR)MAKEINTRESOURCE(IDR_LOGO3PNG), &texture3) != D3D_OK) {
    		MessageBox(hWnd, "logo3.png could not be loaded", "Error", MB_ICONERROR);
    		PostQuitMessage(0);
    		return FALSE;
    	}
    */

    //	sprite
    D3DXCreateSprite(d3d9dev, &sprite);
    // sprite texture
    if (D3DXCreateTextureFromResourceEx(d3d9dev,	//	the device pointer
                                        NULL,	//	module (executable containing the resource)
                                        (LPCSTR)MAKEINTRESOURCE(IDR_LEGENDPNG),	//	resource
                                        //"legend.png",	//	the file name
                                        D3DX_DEFAULT,	//	default width
                                        D3DX_DEFAULT,	//	default height
                                        D3DX_DEFAULT,	//	no mip mapping
                                        NULL,	//	regular usage
                                        D3DFMT_A8R8G8B8,	//	32-bit pixels with alpha
                                        D3DPOOL_MANAGED,	//	typical memory handling
                                        D3DX_DEFAULT,	//	no filtering
                                        D3DX_DEFAULT,	//	no mip filtering
                                        D3DCOLOR_XRGB(255, 0, 255),	//	the hot-pink color key
                                        NULL,	//	no image info struct
                                        NULL,	//	not using 256 colors
                                        &legendTexture) != D3D_OK) {
        MessageBox(hWnd, "legend.png could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }

    //	sprite legend
    D3DXCreateSprite(d3d9dev, &legendSprite);
    //	its texture
    if (D3DXCreateTextureFromResourceEx(d3d9dev,	//	the device pointer
                                        NULL,
                                        (LPCSTR)MAKEINTRESOURCE(IDR_SPRITEPNG),
                                        //"sprite.png",	//	the file name
                                        D3DX_DEFAULT,	//	default width
                                        D3DX_DEFAULT,	//	default height
                                        D3DX_DEFAULT,	//	no mip mapping
                                        NULL,	//	regular usage
                                        D3DFMT_A8R8G8B8,	//	32-bit pixels with alpha
                                        D3DPOOL_MANAGED,	//	typical memory handling
                                        D3DX_DEFAULT,	//	no filtering
                                        D3DX_DEFAULT,	//	no mip filtering
                                        D3DCOLOR_XRGB(255, 0, 255),	//	the hot-pink color key
                                        NULL,	//	no image info struct
                                        NULL,	//	not using 256 colors
                                        &spriteTexture) != D3D_OK) {
        MessageBox(hWnd, "panel.png could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }

    //	triangle
    d3d9dev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &d3d9VertexBuffer1, NULL);
    d3d9VertexBuffer1->Lock(0, 0, &tempVoid, 0);
    if (memcpy(tempVoid, customVertex1, sizeof(customVertex1)) == NULL) MessageBox(NULL, "Error", "error", MB_OK);
    d3d9VertexBuffer1->Unlock();

    //	cube
    d3d9dev->CreateVertexBuffer(24*sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &d3d9VertexBuffer2, NULL);
    d3d9VertexBuffer2->Lock(0, 0, &tempVoid, 0);
    memcpy(tempVoid, customVertex2, sizeof(customVertex2));
    d3d9VertexBuffer2->Unlock();

    return TRUE;
}