DarkHorizon
02-05-2009 03:22:41
Hello,
I'm fairly new to C# and Mogre.
I'm trying to write a coverage map system for building static geometry, using a texture's alpha channel as density. I'm using this as a nudge in the right direction, but something's still not right.
The pixel data is always read as 0 (zero). The source image is a 32 bit PNG.
What am I doing wrong?
Thanks,
I'm fairly new to C# and Mogre.
I'm trying to write a coverage map system for building static geometry, using a texture's alpha channel as density. I'm using this as a nudge in the right direction, but something's still not right.
unsafe public CoverageMap(string Texture)
{
TexturePtr tex = TextureManager.Singleton.GetByName(Texture);
if (tex != null)
{
Width = tex.Width;
Height = tex.Height;
// Lock the texture's pixel buffer
HardwarePixelBufferSharedPtr buffer = tex.GetBuffer();
buffer.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY);
// Allocate a new alpha buffer
AlphaBuffer = new Byte[Width * Height];
// Obtain a handle to the pixel buffer
PixelBox box = buffer.CurrentLock;
Byte* bytebuffer = (Byte*)box.data.ToPointer();
for (int j = 0; j < Height; j++)
{
for (int i = 0; i < Width; i++)
{
Byte r = bytebuffer[j * Width + i + 0];
Byte g = bytebuffer[j * Width + i + 1];
Byte b = bytebuffer[j * Width + i + 2];
Byte a = bytebuffer[j * Width + i + 3];
AlphaBuffer[j * Width + i] = a;
}
}
// Unlock the texture's pixel buffer
buffer.Unlock();
}
}
The pixel data is always read as 0 (zero). The source image is a 32 bit PNG.
What am I doing wrong?
Thanks,