Sign in to follow this  
sascoo

[SlimDX] Texture class not working?

Recommended Posts

sascoo    138
I have a byte[] i wish to write to a texture. For some reason I cannot get the texture initialized... Texture t = Texture.FromFile(device, "cheese.jpg"); // Works t.FromMemory(device,frame); // Doesnt work? if(t == null) t = new Texture(device, (int)Width, (int)Height, 1, Usage.Dynamic, Format.X8B8G8R8, Pool.Default); // Doesnt work...? I have the latest build from August and I am wondering if this is a bug in the framework. Any suggestions would be appreciated. Thanks, John

Share this post


Link to post
Share on other sites
MJP    19786
The FromMemory methods expect an array of data from an image file, not just an array of raw pixel values.

Also please be specific instead of saying "doesn't work". I assume that some sort of exception is thrown? Which exception? What is the message from that exception?

Share this post


Link to post
Share on other sites
unbird    8338
Quote:
t = new Texture(device, (int)Width, (int)Height, 1, Usage.Dynamic, Format.X8B8G8R8, Pool.Default); // Doesnt work...?

Make sure the Format.X8B8G8R8 is supported by checking your device capabilities (my NVidia GT 8500 for instance doesn't). You probably want Format.A8R8G8B8 or Format.X8R8G8B8.

Share this post


Link to post
Share on other sites
sascoo    138
Quote:
Original post by unbird
Quote:
t = new Texture(device, (int)Width, (int)Height, 1, Usage.Dynamic, Format.X8B8G8R8, Pool.Default); // Doesnt work...?

Make sure the Format.X8B8G8R8 is supported by checking your device capabilities (my NVidia GT 8500 for instance doesn't). You probably want Format.A8R8G8B8 or Format.X8R8G8B8.


Doh... I totally thought I was using X8R8G8B8

Thanks, that fixed it.

Share this post


Link to post
Share on other sites
sascoo    138
One more thing before I go back to my cave...

Is this the correct way to write to texture?

byte[] frame = some data
if (t == null)
t = new Texture(device, (int)Width, (int)Height, 1, Usage.Dynamic, Format.X8R8G8B8, Pool.Default);
DataRectangle r = t.LockRectangle(0,LockFlags.None)
r.Data.Write(frame,0,frame.Length);
t.UnlockRectangle(0);

When I render the texture it only has a single line of pixels that go straight down from the top-left corner. What am I doing incorrectly?

Share this post


Link to post
Share on other sites
unbird    8338
Well, depends on what's in that "some data" array. How do you initialize it and what do you expect ? What size is the byte array and what are Width and Height ?

Probably a differently typed array is more suited, for instance int[] (since you're using XRGB) and then use DataStream.WriteRange<T>(T[] data).
Also, check if you get a non-zero pitch from the DataRectangle (dunno if SlimDX will handle pitch with a byte-array automatically), maybe that's a problem.

PS: By the way:
Quote:
t.FromMemory(device,frame); // Doesnt work?

You used that method the wrong way: It's a static method, so the correct call is:

Texture t = Texture.FromMemory(device,frame);


Share this post


Link to post
Share on other sites
unbird    8338
No, it creates a new Texture instance, so it's something like a constructor. There are some overloads of this method which allow different initialization (usage, format, etc.), though.

And as MJP pointed out, Texture.FromMemory cannot be fed with raw pixel values. It's similar to Texture.FromFile, only that the data comes from an array.

Only wanted to show you the correct use of static methods, that's why I put the PS (postscript). Please apologize if I confused you.

So again: What is in that frame-array ?

Is it actually raw pixel data ? Then you have to resort to LockRectangle.

Or some DirectX supported image data (see D3DXIMAGE_FILEFORMAT)? Only then, FromMemory should work.

Share this post


Link to post
Share on other sites
sascoo    138
Yeah, I have raw data that I get out of a surface in DirectX that I am trying to write to the Texture. I know I am just missing a trivial step at this point but I cannot figure out where. I think it is probably the pitch from the datarectangle. I will check that out when I get home.

Thanks

Share this post


Link to post
Share on other sites

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