ich versuche eine Textur rund zu rendern(sie ist ein großes viereck und ich rendere immer einen bestimmten teil(Ist eine MiniMap))
Ich möchte das aber gerne Rund haben
habe bereits mehreres versucht aber leider kein erfolg.
Hier meine test's
Rundes Rendern
Code:
BOOL C2DRender::RenderTextureCircle( int iVertices, float iRadius, CTexture* pTexture, DWORD dwBlendFactorAlhpa, FLOAT fScaleX , FLOAT fScaleY)
{
if(!pTexture) return FALSE;
int nVertex = iVertices + 1;
TEXTUREVERTEX * pVertices;
pVertices = new TEXTUREVERTEX [nVertex];
FLOAT fComplete;
FLOAT x;
FLOAT y;
FLOAT u;
FLOAT v;
for ( int iVertex = 0; iVertex < nVertex; iVertex ++)
{
fComplete = (float)iVertex / nVertex;
x = (float)((fScaleX) + (float)iRadius * cos(6.2831f*fComplete));
y = (float)((fScaleY) + (float)iRadius * sin(6.2831f*fComplete));
u = x / (sqrt((double) ((int)x^(int)2 + (int)y^(int)2 )));
v = y / (sqrt((double) ((int)x^(int)2 + (int)y^(int)2 )));
SetTextureVertex( pVertices, x, y, u, v);
pVertices++;
}
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( dwBlendFactorAlhpa, 0, 155, 0 ) );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
//m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
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->SetTexture( 0, pTexture->m_pTexture );
m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, pVertices, sizeof( TEXTUREVERTEX ) );
m_pd3dDevice->SetTexture( 0, NULL );
return TRUE;
};
Alpha Maske Nr1.
Code:
struct tDXVertexTextureMask
{
float fRHW;
D3DXVECTOR3 vec;
FLOAT x, y, z;
D3DCOLOR color;
FLOAT u1, v1;
FLOAT u2, v2;
};
inline void SettDXVertexTextureMask( tDXVertexTextureMask* pVertices, FLOAT x, FLOAT y, FLOAT u, FLOAT v )
{
pVertices->x = (FLOAT)x - 0.5f;
pVertices->y = (FLOAT)y - 0.5f;
pVertices->z = 0.0f;
pVertices->vec = D3DXVECTOR3( x - 0.5f, y - 0.5f, 0 );
pVertices->fRHW = 1.0f;
pVertices->u1 = u;
pVertices->v1 = v;
pVertices->u2 = u;
pVertices->v2 = v;
pVertices->color = (DWORD)0xffffff;
}
BOOL C2DRender::RenderTextureAlphaMask( CPoint pt, CTexture* pTexture, CTexture* pTexture2, DWORD dwBlendFactorAlhpa, FLOAT fScaleX , FLOAT fScaleY )
{
if( !pTexture ) //gmpbigsun
return FALSE;
if( !pTexture2 )
return FALSE;
pt += m_ptOrigin;
CPoint ptCenter = pTexture->m_ptCenter;
ptCenter.x = (LONG)( ptCenter.x * fScaleX );
ptCenter.y = (LONG)( ptCenter.y * fScaleY );
pt -= ptCenter;
FLOAT left = (FLOAT)( pt.x );
FLOAT top = (FLOAT)( pt.y );
FLOAT right = pt.x + ( fScaleX * pTexture->m_size.cx );
FLOAT bottom = pt.y + ( fScaleY * pTexture->m_size.cy );
tDXVertexTextureMask vertex[ 4 ];
tDXVertexTextureMask* pVertices = vertex;
SettDXVertexTextureMask( pVertices, left, top, pTexture->m_fuLT, pTexture->m_fvLT );
pVertices++;
SettDXVertexTextureMask( pVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT);
pVertices++;
SettDXVertexTextureMask( pVertices, left, bottom, pTexture->m_fuLB, pTexture->m_fvLB);
pVertices++;
SettDXVertexTextureMask( pVertices, right, bottom, pTexture->m_fuRB, pTexture->m_fvRB);
pVertices++;
////
#define D3DFVF_TEXTURE_MASK (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2)
m_pd3dDevice->SetFVF(D3DFVF_TEXTURE_MASK);
m_pd3dDevice->SetTexture( 0, pTexture->m_pTexture );
m_pd3dDevice->SetTexture( 1, pTexture2->m_pTexture );
m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
// Use the color from the previous texture, and blend the alpha from the mask.
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->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( tDXVertexTextureMask ) );
m_pd3dDevice->SetTexture( 0, NULL );
m_pd3dDevice->SetTexture( 1, NULL );
return TRUE;
}
Alpha Maske Nr2.
Code:
BOOL C2DRender::RenderTextureAlphaMask( CPoint pt, CTexture* pTexture, CTexture* pTexture2, DWORD dwBlendFactorAlhpa, FLOAT fScaleX , FLOAT fScaleY )
{
if( !pTexture ) //gmpbigsun
return FALSE;
if( !pTexture2 )
return FALSE;
pt += m_ptOrigin;
CPoint ptCenter = pTexture->m_ptCenter;
ptCenter.x = (LONG)( ptCenter.x * fScaleX );
ptCenter.y = (LONG)( ptCenter.y * fScaleY );
pt -= ptCenter;
FLOAT left = (FLOAT)( pt.x );
FLOAT top = (FLOAT)( pt.y );
FLOAT right = pt.x + ( fScaleX * pTexture->m_size.cx );
FLOAT bottom = pt.y + ( fScaleY * pTexture->m_size.cy );
tDXVertexTextureMask vertex[ 4 ];
tDXVertexTextureMask* pVertices = vertex;
SettDXVertexTextureMask( pVertices, left, top, pTexture->m_fuLT, pTexture->m_fvLT );
pVertices++;
SettDXVertexTextureMask( pVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT);
pVertices++;
SettDXVertexTextureMask( pVertices, left, bottom, pTexture->m_fuLB, pTexture->m_fvLB);
pVertices++;
SettDXVertexTextureMask( pVertices, right, bottom, pTexture->m_fuRB, pTexture->m_fvRB);
pVertices++;
////
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetVertexShader( NULL );
m_pd3dDevice->SetTexture( 0, pTexture->m_pTexture );
m_pd3dDevice->SetTexture( 1, pTexture2->m_pTexture );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetFVF( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 | D3DFVF_TEX2 );
m_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( dwBlendFactorAlhpa, 0, 0, 0 ) );
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_COLOROP, D3DTOP_MODULATE );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT );
m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( tDXVertexTextureMask ) );
m_pd3dDevice->SetTexture( 0, NULL );
m_pd3dDevice->SetTexture( 1, NULL );
return TRUE;
}
hoffentlich kann mir einer weiterhelfen
(die alpha mask ist eine textur mit einem alphakreis(der teil soll nur noch am ende gezeigt werden))
Wie ihr euch sicher denken könnt , es ist für die MiniMap.
Hab nicht so viel ahnung von texturstages etc. und mein DX buch ist seeeehr alt und kann mir über dieses Problem keine antwort geben :C
hoffe jemand kann helfen ;D






