Creating textures programmatically (Urgent!)

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
bigfish
Posts: 19
Joined: Fri Mar 23, 2007 6:18 pm

Creating textures programmatically (Urgent!)

Post by bigfish »

Hey all,

My apologies in advance - this is a cross post from the Irrlicht.NET CP forum, not the official Irrlicht.NET port. I'm desperate for help!! I posted two messages over there tonight, here they are:
I need to be able to create a texture in memory and apply that to a material in Irrlicht. The C++ version of Irrlicht has IVideoDriver::createImageFromData, which looks like it's exactly what I need. However, I'm using Irrlicht.NET CP and it doesn't look like that function is part of the wrapper. Is there any way to do what I'm after in Irrlicht.NET CP? This is super, super urgent!! Any help would be very appreciated.
Well here's a status update... I've been trying to add that function to the wrapper but haven't been successful. I keep getting a System.EntryPointNotFoundException. I've never done any p-invoke stuff before so I'm not sure if there's something I'm missing. I've tried every different function signature I could think of but still no luck. My most recent version looks like this:

Code: Select all

public Image CreateImageFromData(ColorFormat fmt, Dimension2D size, IntPtr data)
{
    return (Image)

    NativeElement.GetObject(VideoDriver_CreateImageFromData(_raw, fmt, size.ToUnmanaged(), data, false), typeof(Image));
}

[DllImport(Native.Dll)]
static extern IntPtr VideoDriver_CreateImageFromData(IntPtr videodriver, ColorFormat fmt, int[] size, IntPtr data, bool ownForeignMemory);
Assuming I have the function signature right, is there anything more that I need to do? I've only been building Irrlicht.NET.dll and Irrlicht.Extensions.dll and have not touched my original copies of Irrlicht.dll and IrrlichtW.dll.

Thanks,
bigfish
bigfish
Posts: 19
Joined: Fri Mar 23, 2007 6:18 pm

Post by bigfish »

Time for one more!
Okay, another status update. :) It seems that IrrlichtW.dll was in fact the missing link. I added the necessary stuff to that and I'm now able to get past the CreateImageFromData call without throwing an exception! However, I also added the missing AddTexture(string name, Image img) function to the wrapper and that's not working... I'm not getting an exception thrown with that one either but it's just hanging the process. Any guesses? Has anyone used that in standard Irrlicht?

Code: Select all

byte[] test = new byte[256 * 256 * 3];
for(int i = 0; i < 256 * 256 * 3; i += 3)
{
    test[i] = 0;
    test[i + 1] = 0;
    test[i + 2] = 255;
}
IrrlichtNETCP.Image irrImage = null;
fixed(byte* bp = test)
{
    irrImage = driver.CreateImageFromData(ColorFormat.R8G8B8, new Dimension2D(256, 256), (IntPtr)(bp));
}
material.Texture1 = driver.AddTexture("mytexture", irrImage);
Locked