Hello again, time for another off the wall question. I am writing an MD2 loader for my small 3D engine project. In my old language (C) I could define a structure and then read() from an open file directly into the structure. I have a structure to hold the header information from the MD2 file, as follows:
[StructLayout(LayoutKind.Sequential)]
public struct MD2_Header
{
public int FourCC;
public int Version;
public int TextureWidth;
public int TextureHeight;
public int FrameSizeInBytes;
public int NbrTextures;
public int NbrVertices;
public int NbrTextureCoords;
public int NbrTriangles;
public int NbrOpenGLCmds;
public int NbrFrames;
public int TextureOffset;
public int TexCoordOffset;
public int TriangleOffset;
public int FrameOffset;
public int OpenGLCmdOffset;
public int EndOffset;
}
In my reader code, I would like to do something like:
// Suck the MD2 header into a structure, it is 68 bytes long.
Classic.Util.MD2_Header md2hdr = new Classic.Util.MD2_Header();
md2hdr = reader.ReadBytes(sizeof(Classic.Util.MD2_Header));
I realize this is not correct, as it breaks type safety somewhat oddly, but you get the idea of what I want to accomplish. I could do this with separate calls to reader.ReadInt32(), but I am curious if there is anyway to get this to work the way I am wanting using normal library calls.
I have looked a little into the Marshal.Copy() method, but it seems to be for going between managed and unmanaged memory, which is not really what I am doing here.
Any suggestions?