本文整理汇总了C++中LPDIRECT3DDEVICE7::DrawPrimitive方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DDEVICE7::DrawPrimitive方法的具体用法?C++ LPDIRECT3DDEVICE7::DrawPrimitive怎么用?C++ LPDIRECT3DDEVICE7::DrawPrimitive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECT3DDEVICE7
的用法示例。
在下文中一共展示了LPDIRECT3DDEVICE7::DrawPrimitive方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RenderShadow
void RenderShadow(LPDIRECT3DDEVICE7 lpDevice,D3DVERTEX* vertices,int numvertices,WORD* indices,DWORD numindices)
{
// Turn depth buffer off, and stencil buffer on
lpDevice->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE, FALSE );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILENABLE, TRUE );
// Set up stencil compare fuction, reference value, and masks
// Stencil test passes if ((ref & mask) cmpfn (stencil & mask)) is true
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILFUNC, D3DCMP_ALWAYS );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILREF, 0x1 );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILMASK, 0xffffffff );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILWRITEMASK,0xffffffff );
// If ztest passes, write 1 into stencil buffer
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILZFAIL, D3DSTENCILOP_KEEP );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILFAIL, D3DSTENCILOP_KEEP );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILPASS, D3DSTENCILOP_REPLACE );
// Make sure that no pixels get drawn to the frame buffer
lpDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE );
lpDevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_ZERO );
lpDevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE );
lpDevice->SetTexture(0,NULL);
// Draw front-side of shadow volume in stencil/z only
if (indices==NULL)
{
lpDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX,
vertices, numvertices,
NULL );
}
else
lpDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX,
vertices, numvertices,
indices, numindices, NULL );
// Now reverse cull order so back sides of shadow volume are written,
// writing 0's into stencil. Result will be any pixel which still has a bit
// set in the stencil buffer, is inside the shadow.
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILREF, 0x0 );
// Draw back-side of shadow volume in stencil/z only
lpDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_CW );
if (indices==NULL)
{
lpDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX,
vertices, numvertices,
NULL );
}
else
lpDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX,
vertices, numvertices,
indices, numindices, NULL );
// Restore render states
lpDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_CCW );
lpDevice->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE, TRUE );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILENABLE, FALSE );
lpDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE );
}
示例2: wDrawPrimitive
/// <summary>
/// <c>wDrawPrimitive</c>
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="d3dDevice7"></param>
/// <param name="dptPrimitiveType"></param>
/// <param name="dvtVertexType"></param>
/// <param name="lpvVertices"></param>
/// <param name="dwVertexCount"></param>
/// <param name="dwFlags"></param>
/// <returns></returns>
HRESULT __stdcall wDrawPrimitive(
LPDIRECT3DDEVICE7 d3dDevice7, D3DPRIMITIVETYPE dptPrimitiveType,
ULONG dvtVertexType, PVOID lpvVertices, ULONG dwVertexCount, ULONG dwFlags)
{
PSTR pszPrimitiveData;
PSTR pszErrorMessage;
HRESULT hResult;
pszPrimitiveData = GetDrawPrimitiveData(
dptPrimitiveType, dvtVertexType, lpvVertices, dwVertexCount, dwFlags);
InternalFunctionSpew("GameOS_Direct3D", "DrawPrimitive( %s)", pszPrimitiveData);
hResult = d3dDevice7->DrawPrimitive(
dptPrimitiveType,
dvtVertexType,
lpvVertices,
dwVertexCount,
dwFlags);
if (FAILED(hResult))
{
if ( hResult != DDERR_SURFACELOST)
{
pszPrimitiveData = GetDrawPrimitiveData(
dptPrimitiveType, dvtVertexType, lpvVertices, dwVertexCount, dwFlags);
pszErrorMessage = ErrorNumberToMessage(hResult);
if ( InternalFunctionPause("FAILED (0x%x - %s) - DrawPrimitive( %s)",
hResult, pszErrorMessage, pszPrimitiveData) )
ENTER_DEBUGGER;
}
}
return hResult;
}
示例3: DrawSmooth
void CSprite::DrawSmooth(LPDIRECT3DDEVICE7 lpDevice,const D3DVECTOR pos,const float w,const float h,const DWORD color,const int spritenr)
{
D3DVECTOR rightVect,upVect;
D3DMATRIX mat;
{
lpDevice->GetTransform(D3DTRANSFORMSTATE_VIEW,&mat);
rightVect=Normalize(D3DVECTOR(mat._11,mat._21,mat._31))*w*0.5f;
upVect=Normalize(D3DVECTOR(mat._12,mat._22,mat._32))*h*0.5f;
}
const D3DVECTOR n=D3DVECTOR(0,0,0);
D3DLVERTEX verts[4]=
{
D3DLVERTEX(pos-rightVect+upVect, color,0, 1.0f, 0.0f),
D3DLVERTEX(pos+rightVect+upVect, color,0, 0.0f, 0.0f),
D3DLVERTEX(pos-rightVect-upVect, color,0, 1.0f, 1.0f),
D3DLVERTEX(pos+rightVect-upVect, color,0, 0.0f, 1.0f)
};
D3DUtil_SetIdentityMatrix(mat);
lpDevice->SetTransform(D3DTRANSFORMSTATE_WORLD,&mat);
if (Config.alpha)
{
lpDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,FALSE);
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,FALSE);
lpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
lpDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
lpDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
lpDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCCOLOR);
lpDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCCOLOR);
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,TRUE);
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF,0x08);
}
lpDevice->SetTexture(0,GetSurface(spritenr));
lpDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_LVERTEX,verts,4,0);
lpDevice->SetTexture(0,NULL);
if (Config.alpha)
{
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,TRUE);
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,FALSE);
lpDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,TRUE);
}
}
示例4: DrawBillBoard
HRESULT CImageHandler::DrawBillBoard(LPDIRECT3DDEVICE7 lpDevice, D3DVECTOR vTrans, D3DVECTOR vScale, /*D3DVECTOR vRot, */D3DMATERIAL7 mtrl, /*FLOAT fRotRad, */LPDIRECTDRAWSURFACE7 lpddsTextr)
{
if ( lpDevice )
{
if( SUCCEEDED(lpDevice->BeginScene()) )
{
D3DMATRIX matTrans;
D3DMATRIX matScale;
D3DMATRIX matRot;
D3DMATRIX matWorld;
D3DMATRIX matTempWorld;
D3DMATRIX matWorldOriginal;
lpDevice->GetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);
vTrans.x = vTrans.x+vScale.x/2-400;
vTrans.y = -vTrans.y-vScale.y/2+300;
D3DUtil_SetTranslateMatrix(matTrans, vTrans);
D3DUtil_SetScaleMatrix(matScale, vScale.x, vScale.y, vScale.z);
// D3DUtil_SetRotationMatrix(matRot, vRot, fRotRad);
D3DMath_MatrixMultiply(/*matTempWorld*/matWorld, matScale, matTrans);
// D3DMath_MatrixMultiply(matWorld, matRot, matTempWorld);
lpDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorld);
SetBlendRenderState(lpDevice, _BLEND_NORMAL, mtrl);
lpDevice->SetMaterial(&mtrl);
lpDevice->SetTexture(0, lpddsTextr);
lpDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX, m_avBillBoard, 4, NULL);
// 원상복귀.
ZeroMemory(&mtrl, sizeof(mtrl));
mtrl.diffuse.r = mtrl.diffuse.g = mtrl.diffuse.b = 0.1f;
mtrl.ambient.r = mtrl.ambient.g = mtrl.ambient.b = 1.0f;
lpDevice->SetMaterial(&mtrl);
ResetBlendenderState(lpDevice);
lpDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);
}
lpDevice->EndScene();
return S_OK;
}
return E_FAIL;
}
示例5: DrawUI
void CRadar::DrawUI(LPDIRECT3DDEVICE7 lpDevice)
{
if (!Enabled)return;
if ((lpSurface==NULL)||(lpSurface->IsLost()))
{
UpdateSurface();
Update();
}
const float w=130.0f*game->width/640.0f;
const float h=130.0f*game->width/640.0f;
const float x=game->width-20-w;
const float y=game->height-20-h;
const int c=D3DRGBA(1,1,1,0.45f);
const float r=0.9f;
D3DTLVERTEX v[4]={
D3DTLVERTEX(D3DVECTOR(x,y,0),r,c,0,0,0),
D3DTLVERTEX(D3DVECTOR(x+w,y,0),r,c,0,1,0),
D3DTLVERTEX(D3DVECTOR(x,y+h,0),r,c,0,0,1),
D3DTLVERTEX(D3DVECTOR(x+w,y+h,0),r,c,0,1,1)
};
if (Config.alpha)
{
// lpDevice->SetRenderState(D3DRENDERSTATE_ZENABLE,FALSE);
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);
lpDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA);
lpDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA);
lpDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,TRUE);
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF,8);
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAFUNC,D3DCMP_GREATEREQUAL);
}
lpDevice->SetTexture(0,lpSurface);
lpDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_TLVERTEX,v,4,0);
lpDevice->SetTexture(0,NULL);
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,0);
lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,0);
// lpDevice->SetRenderState(D3DRENDERSTATE_ZENABLE,TRUE);
}
示例6: DrawShadow
void DrawShadow(LPDIRECT3DDEVICE7 lpDevice)
{
lpDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILENABLE, TRUE );
// Turn on alphablending
lpDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE );
lpDevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA );
lpDevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA );
lpDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);
// Only write where the stencil value == 1
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILREF, 0x1 );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILFUNC, D3DCMP_EQUAL );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILPASS, D3DSTENCILOP_KEEP );
// Get viewport dimensions for big, gray square
D3DVIEWPORT7 vp;
lpDevice->GetViewport(&vp);
FLOAT sx = (FLOAT)vp.dwWidth;
FLOAT sy = (FLOAT)vp.dwHeight;
D3DCOLOR color=D3DRGBA(0,0,0,0.5f);
// Draw a big, gray square
D3DTLVERTEX vBigGraySquare[4];
vBigGraySquare[0] = D3DTLVERTEX( D3DVECTOR( 0,sy,0.0f),1.0f,color,0,0,0 );
vBigGraySquare[1] = D3DTLVERTEX( D3DVECTOR( 0, 0,0.0f),1.0f,color,0,0,0 );
vBigGraySquare[2] = D3DTLVERTEX( D3DVECTOR(sx,sy,0.0f),1.0f,color,0,0,0 );
vBigGraySquare[3] = D3DTLVERTEX( D3DVECTOR(sx, 0,0.0f),1.0f,color,0,0,0 );
lpDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX,
vBigGraySquare, 4, NULL );
// Restore render states
lpDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, TRUE );
lpDevice->SetRenderState( D3DRENDERSTATE_STENCILENABLE, FALSE );
lpDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE );
}
示例7: Prog_Loop
//////////////////////////////////////////////////////////////////////////////
//MAIN GAME LOOP
//////////////////////////////////////////////////////////////////////////////
void Prog_Loop()
{
//set up the vertex positions
vert[0].sx=(float) (cos(angle)*240.0+320.0);
vert[0].sy=(float) (sin(angle)*240.0+240.0);
vert[0].sz=(float) (sin(angle)*240.0+240.0);
vert[1].sx=(float) (cos(angle+PI/2)*240.0+320.0);
vert[1].sy=(float) (sin(angle+PI/2)*240.0+240.0);
vert[1].sz=(float) (sin(angle+PI/2)*240.0+240.0);
vert[2].sx=(float) (cos(angle-PI/2)*240.0+320.0);
vert[2].sy=(float) (sin(angle-PI/2)*240.0+240.0);
vert[2].sz=(float) (sin(angle-PI/2)*240.0+240.0);
vert[3].sx=(float) (cos(angle-PI)*240.0+320.0);
vert[3].sy=(float) (sin(angle-PI)*240.0+240.0);
vert[3].sz=(float) (sin(angle-PI)*240.0+240.0);
//add to the angle for next time
angle+=PI/90;
//clear the viewport to black
lpd3ddev->Clear(0,NULL,D3DCLEAR_TARGET,0,0,0);
//start the scene
lpd3ddev->BeginScene();
//draw the triangle
lpd3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_TLVERTEX,vert,4,0);
//end the scene
lpd3ddev->EndScene();
//flip
lpddsPrime->Flip(NULL,DDFLIP_WAIT);
}