示例#1
0
BOOL gldGetDXErrorString_DX(
	HRESULT hr,
	char *buf,
	int nBufSize)
{
	//
	// Return a string describing the input HRESULT error code
	//

	D3DXGetErrorString(hr, buf, nBufSize);
	return TRUE;
}
示例#2
0
CString hr_ssprintf( int hr, const char *fmt, ...)
{
    va_list	va;
    va_start(va, fmt);
    CString s = vssprintf( fmt, va );
    va_end(va);

#ifdef _XBOX
	char szError[1024] = "";
	D3DXGetErrorString( hr, szError, sizeof(szError) );
#else	
	const char *szError = DXGetErrorString8( hr );
#endif

	return s + ssprintf( " (%s)", szError );
}
示例#3
0
//! Create a dialog box and tell the user what went wrong
bool DisplayError(LPSTR lpstrErr, HRESULT hres)
{
    static bool InError = false;
    int retval = 0;
    if (!InError)
    {
        InError = true;
#ifdef DDSCAPS_PRIMARYSURFACELEFT
        const char *message = hres?DXGetErrorString8A(hres):0;
#else
        char message[256]; if(hres) D3DXGetErrorString(hres, 256, message);
#endif
        retval = MessageBoxA(g_hAppWnd, lpstrErr, hres?message:"Error!", MB_OK|MB_ICONERROR);
        InError = false;
    }
    return false;
}
示例#4
0
文件: Utilities.cpp 项目: gthgame/gth
void	ShowDXError	(	const HRESULT	hr,
						const char		*pszFileName,
						const int		line	)
{
	char	szDXError[256];
	char	szError[512];

	D3DXGetErrorString	(	hr,
							szDXError,
							256		);

	sprintf	(	szError,
				"%s\nFile : %s\nLine : %d",
				szDXError,	pszFileName,	line	);

	MessageBox	(	NULL,
					szError,
					"DX Error!",
					MB_OK	);
}
示例#5
0
HRESULT CRacorX::RestoreDeviceObjects()
{
	IDirect3DDevice8* device;
	HRESULT hr = m_spD3D->CreateDevice(
		D3DADAPTER_DEFAULT,
		D3DDEVTYPE_HAL,
		m_hWnd,
		m_iVP,
		&m_dpps,
		&device);
	if (FAILED(hr)) {
		OutputDebugString(L"Create Device Failed! Error:\n");
		switch (hr)
		{
		case D3DERR_DEVICELOST:
			OutputDebugString(L"D3DERR_DEVICELOST\n");
			break;
		case D3DERR_INVALIDCALL:
			OutputDebugString(L"D3DERR_INVALIDCALL\n");
			break;
		case D3DERR_NOTAVAILABLE:
			OutputDebugString(L"D3DERR_NOTAVAILABLE\n");
			break;
		case D3DERR_OUTOFVIDEOMEMORY:
			OutputDebugString(L"D3DERR_OUTOFVIDEOMEMORY\n");
			break;;
		default:
			OutputDebugString(L"Unknown\n");
			break;
		}
		return S_FALSE;
	}
	m_spDevice.reset(device, [](IDirect3DDevice8* device){ device->Release(); });
	DWORD dwDecl0[] = {
		D3DVSD_STREAM(0),
		D3DVSD_REG(0,D3DVSDT_FLOAT3),
		//D3DVSD_REG(5,D3DVSDT_D3DCOLOR),
		/*D3DVSD_CONST(0, 4),
		*(DWORD*)&m_mtWorld[0], *(DWORD*)&m_mtWorld[1], *(DWORD*)&m_mtWorld[2], *(DWORD*)&m_mtWorld[3],
		*(DWORD*)&m_mtWorld[4], *(DWORD*)&m_mtWorld[5], *(DWORD*)&m_mtWorld[6], *(DWORD*)&m_mtWorld[7],
		*(DWORD*)&m_mtWorld[8], *(DWORD*)&m_mtWorld[9], *(DWORD*)&m_mtWorld[10], *(DWORD*)&m_mtWorld[11],
		*(DWORD*)&m_mtWorld[12], *(DWORD*)&m_mtWorld[13], *(DWORD*)&m_mtWorld[14], *(DWORD*)&m_mtWorld[15],
		D3DVSD_CONST(0, 1),
		*(DWORD*)&m_fMaterial[0], *(DWORD*)&m_fMaterial[1], *(DWORD*)&m_fMaterial[2], *(DWORD*)&m_fMaterial[3],*/
		D3DVSD_END()
	};

	IDirect3DVertexBuffer8* vb;
	m_spDevice->CreateVertexBuffer(
		4 * sizeof (Vertex),
		D3DUSAGE_WRITEONLY,
		Vertex::FVF,
		D3DPOOL_MANAGED,
		&vb);
	m_spVB.reset(vb, [](IDirect3DVertexBuffer8* vb){ vb->Release(); });

	Vertex* vertices = 0;
	m_spVB->Lock(0, 0, reinterpret_cast<BYTE**>(&vertices), 0);
	vertices[0] = { -100.0f, -100.0f, 0.0f, };
	vertices[1] = { 100.0f, -100.0f, 0.0f, };
	vertices[2] = { 100.0f, 100.0f, 0.0f, };
	vertices[3] = { -100.0f, 100.0f, 0.0f, };
	/*
	vertices[0] = { -1.0f, -1.0f, 0.2f, };
	vertices[1] = { 1.0f, -1.0f, 0.2f, };
	vertices[2] = { 1.0f, 1.0f, 0.2f, };
	vertices[3] = { -1.0f, 1.0f, 0.2f, };
	*/
	m_spVB->Unlock();

	IDirect3DIndexBuffer8* ib;
	m_spDevice->CreateIndexBuffer(
		6 * sizeof(WORD),
		D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16,
		D3DPOOL_MANAGED,
		&ib);
	m_spIB.reset(ib, [](IDirect3DIndexBuffer8* ib){ ib->Release(); });

	WORD *indices = 0;
	m_spIB->Lock(0, 0, reinterpret_cast<BYTE**>(&indices), 0);

	indices[0] = 0;
	indices[1] = 1;
	indices[2] = 2;
	indices[3] = 0;
	indices[4] = 2;
	indices[5] = 3;

	m_spIB->Unlock();
	
	const char vsh[] = 
		"vs.1.1 \n" \
		"dp4 oPos.x, v0, c0 \n"\
		"dp4 oPos.y, v0, c1 \n"\
		"dp4 oPos.z, v0, c2 \n"\
		"dp4 oPos.w, v0, c3 \n"\
		"mov oD0, c4\n";
	/*
	const char vsh[] = 
		"vs.1.1 \n" \
		"mov oPos, v0 \n" \
		"mov oD0, c4 \n";
		*/
	ID3DXBuffer* pVBuffer;
	ID3DXBuffer* pErrors;
	HRESULT rc = D3DXAssembleShader(reinterpret_cast<LPCVOID>(vsh), sizeof(vsh) - 1, 0, NULL, &pVBuffer, &pErrors);
	if (FAILED(rc))
	{
		OutputDebugString(L"Failed to assemble the vertex shader, error:\n");
		OutputDebugStringA(reinterpret_cast<CHAR*>(pErrors->GetBufferPointer()));
		OutputDebugString(L"\n");
	}

	rc = m_spDevice->CreateVertexShader(dwDecl0, (DWORD*)pVBuffer->GetBufferPointer(), &m_dwVertexShader, 0);
	if (FAILED(rc))
	{
		OutputDebugString(L"Failed to create vertex shader, error:\n");
		WCHAR szBuffer[512] = { 0 };
		D3DXGetErrorString(rc, szBuffer, sizeof(szBuffer));
		OutputDebugString(szBuffer);
		OutputDebugString(L"\n");
	}
	m_spDevice->SetViewport(&m_Viewport);
	//m_spDevice->SetTransform(D3DTS_VIEW, &m_mtView);
	//m_spDevice->SetTransform(D3DTS_PROJECTION, &m_mtProj);
	m_spDevice->SetRenderState(D3DRS_ZENABLE, true);
	m_spDevice->SetRenderState(D3DRS_LIGHTING, false);
	//m_spDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
	m_spDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	return S_OK;
}
示例#6
0
CString GetErrorString( HRESULT hr )
{
	char szError[1024] = "";
	D3DXGetErrorString( hr, szError, sizeof(szError) );
	return szError;
}