How to get a Stream object from a Mogre resource [SOLVED]


29-01-2012 09:05:25

Hey there, i'm trying to figure out how to get a Stream ( object from a resource loaded in Mogre,
such as a text file, and would appreciate any help.

Thanks! :)

Edit: After some searching, i found where he had the same (unsolved) problem,
And, which had the solution :P

In a nutshell, here it is:

//DataStreamPtr dataPtr = ResourceGroupManager.Singleton.OpenResource("my resource");

public MemoryStream DataPtrToStream(DataStreamPtr dataPtr)
if (dataPtr.Size() != 0)
byte[] buffer = new byte[dataPtr.Size()];

//Get the pointer to the first element of our buffer of bytes (in C++, can just use 'buffer')
fixed (byte* bufferPtr = &buffer[0])
//Read buffer.Length amount of data into bufferPtr
dataPtr.Read(bufferPtr, (uint)buffer.Length);

MemoryStream stream = new MemoryStream(buffer);

return stream;

return null;

Thanks to bekas and Madmark for coming up with the above method, I just sort of put it together.


31-01-2012 05:02:05

I wonder if Mogre could be adapted to do this automatically for you. Just a thought.


31-01-2012 05:18:55

Seems easy enough to do, t'would be a good suggestion for the next release