Hi,
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
Alpha Maske Nr1.
Alpha Maske Nr2.
Kreis zeichnen
Das einzige was funzt ist Draw2DCircle aber dieser ist nur ein außen kreis ungefüllt und da krieg ich keine Textur rein also SetTexture( m_pTexture ) funzt zwar aber kriege sie nicht innerhalb des kreises.
hoffentlich kann mir einer weiterhelfen
(die alpha mask ist eine textur mit einem alphakreis(der teil soll nur noch am ende gezeigt werden))
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;
}
Kreis zeichnen
Code:
void CTexture::Draw2DCircle(POINT pt, float radius, D3DCOLOR color, LPDIRECT3DDEVICE9 dev)
{
const int NUMPOINTS = 400;
const float PI = 3.14159;
VERTEXLIST2 * pkCircle;
pkCircle = new VERTEXLIST2[NUMPOINTS + 1];
int i;
float X;
float Y;
float Theta;
float WedgeAngle; //Size of angle between two points on the circle (single wedge)
//Precompute WedgeAngle
WedgeAngle = (float)((2*PI) / NUMPOINTS);
D3DCOLOR Color = D3DCOLOR_ARGB( 80, 255, 255, 255 ); // Adjust Alpha
//Set up vertices for a circle
//Used <= in the for statement to ensure last point meets first point (closed circle)
for(i=0; i<=NUMPOINTS; i++)
{
//Calculate theta for this vertex
Theta = i * WedgeAngle;
//Compute X and Y locations
X = (float)(pt.x + radius * cos(Theta));
Y = (float)(pt.y - radius * sin(Theta));
pkCircle[i].fX = X;
pkCircle[i].fY = Y;
pkCircle[i].fZ = 0.0f;
pkCircle[i].fRHW = 1.0f;
pkCircle[i].Color = Color;
pkCircle[i].fU = 0.5f;
pkCircle[i].fV = 0.5f;
}
const BYTE bBlue[60] =
{
0x42, 0x4D, 0x3C, 0x00,0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00,
0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01,0x00, 0x00, 0x00, 0x01, 0x00,
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00,
0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00
};
LPDIRECT3DTEXTURE9 Blue = NULL;
if( Blue == NULL )
D3DXCreateTextureFromFileInMemory( dev, (LPCVOID)&bBlue, 60, &Blue );
//Now draw the circle
dev->SetFVF(D3DFVF_TL);
dev->SetTexture(0, Blue);
dev->DrawPrimitiveUP(D3DPT_LINESTRIP, NUMPOINTS, &pkCircle[0], sizeof(pkCircle[0]));
}//Draw2DCircle
Das einzige was funzt ist Draw2DCircle aber dieser ist nur ein außen kreis ungefüllt und da krieg ich keine Textur rein also SetTexture( m_pTexture ) funzt zwar aber kriege sie nicht innerhalb des kreises.
hoffentlich kann mir einer weiterhelfen
(die alpha mask ist eine textur mit einem alphakreis(der teil soll nur noch am ende gezeigt werden))