Skip to content

Instantly share code, notes, and snippets.

@ssube
Created November 27, 2011 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssube/1397175 to your computer and use it in GitHub Desktop.
Save ssube/1397175 to your computer and use it in GitHub Desktop.
FS quad draw func
struct FSVert
{
float x, y, z, rhw; // The transformed(screen space) position for the vertex.
float tu, tv; // Texture coordinates
};
#define FSVERT_VFV (D3DFVF_XYZRHW | D3DFVF_TEX0)
//IDirect3DVertexDeclaration9 * g_VDecl;
IDirect3DVertexBuffer9 * g_Verts;
void TestCreate(IDirect3DDevice9 * mDevice, float fx, float fy)
{
UNREFERENCED_PARAMETER(fx);
UNREFERENCED_PARAMETER(fy);
/*D3DVERTEXELEMENT9 VertElems[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0},
{0, 12, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
{0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};
HRESULT hr = mDevice->CreateVertexDeclaration(VertElems, &g_VDecl);*/
FSVert verts[6] =
{
{150,400,0.5,1,0,1},
{150,100,0.5,1,0,0},
{450,100,0.5,1,1,0},
{150,400,0.5,1,0,1},
{450,100,0.5,1,1,0},
{450,400,0.5,1,1,1}
};
HRESULT hr = mDevice->CreateVertexBuffer(sizeof(verts), D3DUSAGE_WRITEONLY, FSVERT_VFV, D3DPOOL_DEFAULT, &g_Verts, NULL);
void * pVerts;
hr = g_Verts->Lock(0, 0, &pVerts, 0);
memcpy(pVerts, verts, sizeof(verts));
hr = g_Verts->Unlock();
}
void TestDraw(IDirect3DDevice9 * mDevice, IDirect3DStateBlock9 * pCleanState)
{
HRESULT hr;
IDirect3DStateBlock9 * deviceState = nullptr;
hr = mDevice->CreateStateBlock(D3DSBT_ALL, &deviceState);
hr = pCleanState->Apply();
hr = mDevice->SetStreamSource(0, g_Verts, 0, sizeof(FSVert)); assert(SUCCEEDED(hr));
hr = mDevice->SetFVF(FSVERT_VFV); assert(SUCCEEDED(hr));
hr = mDevice->SetRenderState(D3DRS_CLIPPING, FALSE); assert(SUCCEEDED(hr));
hr = mDevice->SetRenderState(D3DRS_ZENABLE, FALSE); assert(SUCCEEDED(hr));
hr = mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); assert(SUCCEEDED(hr));
hr = mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); assert(SUCCEEDED(hr));
hr = mDevice->BeginScene(); assert(SUCCEEDED(hr));
if (SUCCEEDED(hr))
{
hr = mDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 2, sizeof(FSVert)); assert(SUCCEEDED(hr));
hr = mDevice->EndScene(); assert(SUCCEEDED(hr));
}
else
{
gpVoodooCore->GetLogger()->Log(LL_ModError, VOODOO_DX9_NAME, L"Voodoo DX9: Failed to draw quad.\n");
}
hr = deviceState->Apply();
hr = deviceState->Release();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment