Sign in to follow this  

[MDX] Creating textures from raw data [solved]

This topic is 4277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all. What I'm trying to do is create an 8-bit paletted texture from raw byte data from a file. However since the bytes in the file have to be "transformed" the real data will come from memory. The documentation didn't provide much info and Google just gave me how to load image files. So I whipped up this as a test:
    public class Texture
    {
    	
        protected Microsoft.DirectX.Direct3D.Texture Direct3D_Texture = null;

        public int Height
        {
        	get
        	{
        		return Information.Height;
        	}
        }
        
        private ImageInformation Information = new ImageInformation();
        
        public int Width
        {
        	get
        	{
        		return Information.Width;
        	}
        }
        
        public Texture()
        {
            Direct3D_Texture = null;
        }

        ~Texture()
        {
        	if( Direct3D_Texture != null )
        	{
        		if( Direct3D_Texture.Disposed == false )
        		{
            		    Direct3D_Texture.Dispose();
        		}
        	}
            return;
        }
        
        public void Create( BinaryReader Reader, Device Direct3D_Device )
        { 
        	MemoryStream Stream = new MemoryStream();	
        	for( int i = 0; i < 64 * 64; i++ )
        	{
        		Stream.WriteByte( 0 );
        	}
        	PaletteEntry[] Palette = new PaletteEntry[256];
        	for( int i = 0; i < Palette.Length; i++ )
        	{
        		Palette[i] = new PaletteEntry( 255, 255, 255, 255 );
        	}
        	Direct3D_Texture = TextureLoader.FromStream( Direct3D_Device, Stream, (int)Stream.Length, 64, 64, 1, Usage.SoftwareProcessing, Format.P8, Pool.Managed, Filter.None, Filter.None, 0, ref Information, out Palette );
        	Stream.Close();
        	Stream.Dispose();
        	return;
        }

     }


I'm not actually using the file data yet, I'm just trying to get this to work( by creating a blank 64x64 texture). I'm getting Exception Microsoft.DirectX.Direct3D.InvalidDataException from FromStream, not sure what that's all about. I know I could probably just use dynamic textures for this, but they only need to be written to at start up. Does anyone know the solution or (likely) a better one? [Edited by - Scet on April 1, 2006 10:18:25 PM]

Share this post


Link to post
Share on other sites
I'm no expert, and I've never done anything along these lines, so take this for what it's worth. I don't see any need for the ImageInformation part. I mean you don't really do anything with it except instantiate it and then pass it to FromStream. Maybe you could try using the overload that has everything from the overload you used, except the ImageInformation parameter. Worth a shot and I hope it helps.

-AJ

Share this post


Link to post
Share on other sites
Edit: Nevermind. I've figured it out. I forgot about the different texture constructors and LockRectangle, [rolleyes].


public void Create( BinaryReader Reader, Device Direct3D_Device )
{
Direct3D_Texture = new Microsoft.DirectX.Direct3D.Texture( Direct3D_Device, 64, 64, 1, Usage.SoftwareProcessing, Format.A8R8G8B8, Pool.Managed );
GraphicsStream Stream = Direct3D_Texture.LockRectangle( 0, LockFlags.None );
for( int i = 0; i < 64 * 64; i++ )
{
Stream.WriteByte( 255 );
Stream.WriteByte( 255 );
Stream.WriteByte( 255 );
Stream.WriteByte( 255 );
}
Direct3D_Texture.UnlockRectangle( 0 );

Information.Width = 64;
Information.Height = 64;
return;
}





I still don't have it paletted but I don't think I can(not supported). I'll have to figure out a way around that.

Edit: u235 thanks for trying to help, but my card doesn't support P8 in HAL mode. The palette only changes during loading screens so it's not that important.

[Edited by - Scet on April 1, 2006 10:47:03 PM]

Share this post


Link to post
Share on other sites
If I was at my computer I could try the code out myself and I could probably be of much more help. As it is, though, the only other thing I can think of might be that maybe you're not supposed to initialize the PaletteEntry array since it's an out parameter. Maybe DirectX fills the array based on the pixel format. Stabbin' in the dark here, sorry. I hope that helps, and if not, I hope someone comes along who has the answer.

-AJ

Share this post


Link to post
Share on other sites

This topic is 4277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this