Here is my method DrawBox and DrawCircle.
Code:
#define D3DFVF_TEXTUREVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
Code:
struct TEXTUREVERTEX
{
D3DXVECTOR3 vec;
FLOAT rhw;
DWORD color;
FLOAT u, v;
};
Code:
void CriarVertex( TEXTUREVERTEX* pVertices, FLOAT x, FLOAT y, FLOAT u, FLOAT v, DWORD dwCor )
{
pVertices->vec = D3DXVECTOR3( x - 0.5f, y - 0.5f, 0 );
pVertices->rhw = 1.0f;
pVertices->u = u;
pVertices->v = v;
pVertices->color = dwCor;
}
Box:
Code:
void DesenharCaixa1(int x,int y,int w,int h, DWORD ColorStart,int UsarVertex1,LPDIRECT3DDEVICE9 m_pd3dDevice)
{
RECT rect = { x, y, x + w, y + h };;
FLOAT Esquerda = (FLOAT)rect.left;
FLOAT Cima = (FLOAT)rect.top;
FLOAT Direita = (FLOAT)rect.right;
FLOAT Baixo = (FLOAT)rect.bottom;
TEXTUREVERTEX vertex[ 4 ];
TEXTUREVERTEX* pVertices = vertex;
CriarVertex( pVertices, Esquerda, Cima, rect.left, rect.left, ColorStart );
pVertices++;
CriarVertex( pVertices, Direita, Cima, rect.right, rect.right, ColorStart );
pVertices++;
CriarVertex( pVertices, Esquerda, Baixo, rect.bottom, rect.bottom, ColorStart );
pVertices++;
CriarVertex( pVertices, Direita, Baixo, rect.top+rect.right,rect.top+rect.right, ColorStart );
pVertices++;
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC );//qualidade
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC );//qualidade
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );
m_pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
m_pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
m_pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
m_pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
m_pd3dDevice->SetVertexShader( NULL );
m_pd3dDevice->SetTexture( 0, NULL );
m_pd3dDevice->SetTexture( 1, NULL );
m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( TEXTUREVERTEX ) );
m_pd3dDevice->SetTexture( 0, NULL );
m_pd3dDevice->SetTexture( 1, NULL );
}
Circle:
Code:
BOOL DesenharCirculo(int x,int y,DWORD dwCor, float bTamanho, BOOL bNoCentro,LPDIRECT3DDEVICE9 m_pd3dDevice)
{
POINT pt = {x,y};
if( bTamanho == 0.0f )
bTamanho = float(min(pt.x,pt.y)/2);
bTamanho *= 1.0f;
if( !bNoCentro )
{
pt.x += long(bTamanho);
pt.y += long(bTamanho);
}
TEXTUREVERTEX pVertex[366];
float x1 = float(pt.x);
float y1 = float(pt.y);
float u1 = 0.5f;
float v1 = 0.5f;
for( int i=0;i<=363; )
{
float angle = ( i / 57.3f );
float x2 = pt.x + ( bTamanho * sin( angle ) );
float y2 = pt.y + ( bTamanho * cos( angle ) );
float u2 = 0.5f + ( 0.5f * sin( angle ) );
float v2 = 0.5f + ( 0.5f * cos( angle ) );
CriarVertex( &pVertex[i++], float(pt.x), float(pt.y), 0.5f, 0.5f,dwCor );
CriarVertex( &pVertex[i++], x1, y1, u1, v1 ,dwCor);
CriarVertex( &pVertex[i++], x2, y2, u2, v2 ,dwCor);
y1 = y2;
x1 = x2;
u1 = u2;
v1 = v2;
}
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC );//qualidade
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC );//qualidade
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );
m_pd3dDevice->SetVertexShader( NULL );
//m_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );//Rendertarget mascara alpha
//IDirect3DSurface9 *pRenderTarget = NULL;
//m_pd3dDevice->GetBackBuffer(0,1,D3DBACKBUFFER_TYPE_MONO,&pRenderTarget);
//m_pd3dDevice->CreateDepthStencilSurface(800,600,D3DFMT_A8R8G8B8,D3DMULTISAMPLE_NONMASKABLE,NULL,true,&pRenderTarget,NULL);//
//pRenderTarget->Release();
//m_pd3dDevice->SetRenderTarget(0,pRenderTarget);//
//////////////
m_pd3dDevice->SetTexture( 0, NULL );
m_pd3dDevice->SetTexture( 1, NULL );
m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 363, pVertex, sizeof( TEXTUREVERTEX ) );
m_pd3dDevice->SetTexture( 0, NULL );
m_pd3dDevice->SetTexture( 1, NULL );
return TRUE;
}
The circle is complete, it is not only the edge, good for use in radar, or not! And it can be helpful to some..
Credits : Ademir,DirectX(used as start), Jeff (struct).