2017-04-09 93 views
0

此代码创建一个非零的alpha通道的纹理。XNA。的Texture2D。 SetData的。错误的Alpha香奈尔

Texture2D result = new Texture2D(Program.MainThread.GraphicsDevice, (Int32)texture_size, (Int32)texture_size); 
Color[ ] colorData = new Color[result.Width * result.Height]; 
for (UInt32 x = 0; x < result.Width; x++) { 
    for (UInt32 y = 0; y < result.Height; y++) { 
     UInt32 index = (UInt32)(x * result.Width + y); 
     colorData[index] = new Color(1f, 0f, 0f, 0f); 
    } 
} 
result.SetData(colorData); 

颜色变得稍微透明。但是,大约为0.5f的值。这是为什么发生?

P.S. Color.Transparent正常工作,但我必须通过编程计算的alpha通道,例如:

colorData[index] = new Color(1f, 0f, 0f, 1f - temp); 

回答

0

为了使纹理XNA透明的,我觉得这样做了以下工作要好得多:

Color color = new Color(r,g,b) * alpha; 

看看这是否适合你。