Sickes
23-12-2007 23:19:42
Hi!
I want to create a texture for a plane using a System.Drawing.Image object.
How can i do that?
Thanks
I want to create a texture for a plane using a System.Drawing.Image object.
How can i do that?
Thanks
Sickes
23-12-2007 23:19:42
GermanDZ
24-12-2007 11:38:25
DynTexture = TextureManager.Singleton.CreateManual("TEX_CUSTOM_DYN", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, 2048, 1024, 0, PixelFormat.PF_BYTE_BGRA, 6/*TextureUsage.TU_DYNAMIC_WRITE_ONLY*/);
ResourcePtr rp2 = MaterialManager.Singleton.Create("MATERIAL_CUSTOM_DYN", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
MaterialPtr mat2 = (MaterialPtr)rp2;
TextureUnitState tState2 = mat2.GetTechnique(0).GetPass(0).CreateTextureUnitState("TEX_CUSTOM_DYN");
tState2.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_BORDER);
public void ShowImageOnTexture(System.Drawing.Image img, Entity ent) {
ent.SetMaterialName("MATERIAL_CUSTOM_DYN");
MemoryStream ms = new MemoryStream();
img.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
ReplaceTexture("DynTexture", ms.ToArray(), img.Width, img.Height);
}
Sickes
24-12-2007 11:52:08
GermanDZ
24-12-2007 13:28:36
public static void ReplaceTexture(HardwarePixelBuffer buffer, byte[] frame, int ancho, int alto)
{
unsafe
{
buffer.Lock(HardwareBuffer.LockOptions.HBL_NORMAL);
PixelBox pBox = buffer.CurrentLock;
pBox.format = PixelFormat.PF_BYTE_BGRA;
Marshal.Copy(frame, 0, pBox.data, (alto * ancho * 4));
buffer.Unlock();
}
}
Sickes
26-12-2007 12:11:35
Sickes
26-12-2007 12:19:22
GermanDZ
26-12-2007 13:12:46
Sickes
26-12-2007 13:39:58
Entity ePlanoReverso = mgr.CreateEntity("cartaReverso1", "planoReverso");
//creacion de la imagen
System.Drawing.Image img = null;
img = System.Drawing.Image.FromFile("reverse2.bmp");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
//Creacion de la textura de forma manual
TexturePtr DynTexture = TextureManager.Singleton.CreateManual(
"texReverso",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
TextureType.TEX_TYPE_2D,
(uint)img.Width,
(uint)img.Height,
0,
PixelFormat.PF_BYTE_BGRA,
(int)TextureUsage.TU_DEFAULT);
MaterialPtr _material = MaterialManager.Singleton.Create("matReverso", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
TextureUnitState tState2 = _material.GetTechnique(0).GetPass(0).CreateTextureUnitState("texReverso");
tState2.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_BORDER);
//asignamos la imagen a la textura
ePlanoReverso.SetMaterialName("matReverso");
unsafe
{
HardwarePixelBuffer buffer = DynTexture.GetBuffer();
buffer.Lock(HardwareBuffer.LockOptions.HBL_NORMAL);
PixelBox pBox = buffer.CurrentLock;
pBox.format = PixelFormat.PF_BYTE_BGRA;
int length = (img.Height * img.Width);
System.Runtime.InteropServices.Marshal.Copy(ms.ToArray(), 0, pBox.data, length);
buffer.Unlock();
}
GermanDZ
26-12-2007 23:48:59
Sickes
12-01-2008 12:10:02
Sickes
12-01-2008 12:45:22
//creacion de la imagen
System.Drawing.Image img = null;
img = System.Drawing.Image.FromFile("reverse2.bmp");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
//Creacion del material
ePlanoReverso.SetMaterialName("matReverso");
//Creacion de la textura de forma manual
TexturePtr DynTexture = TextureManager.Singleton.CreateManual(
"texReverso",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
TextureType.TEX_TYPE_2D,
(uint)img.Width,
(uint)img.Height,
0,
PixelFormat.PF_BYTE_BGRA,
(int)TextureUsage.TU_DEFAULT);
MaterialPtr _material = MaterialManager.Singleton.Create("matReverso", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
TextureUnitState tState2 = _material.GetTechnique(0).GetPass(0).CreateTextureUnitState("texReverso");
tState2.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_BORDER);
//asignamos la imagen a la textura
ePlanoReverso.SetMaterialName("matReverso");
unsafe
{
HardwarePixelBuffer buffer = DynTexture.GetBuffer();
buffer.Lock(HardwareBuffer.LockOptions.HBL_NORMAL);
PixelBox pBox = buffer.CurrentLock;
pBox.format = PixelFormat.PF_BYTE_BGRA;
int length = (img.Height * img.Width)*4;
int lengthMS = ms.ToArray().Length;
int lengthBOX = (int)pBox.GetConsecutiveSize();
System.Runtime.InteropServices.Marshal.Copy(ms.ToArray(), 0, pBox.data, length);
buffer.Unlock();
}
Sickes
12-01-2008 13:01:06