DX9.NET: Texture.FromBitmap() fails?

Contrast

New member
Joined
Jan 25, 2003
Messages
4
Im trying to piece together a bitmap and then make a nondynamic texture from it. I use the static method Texture.FromBitmap() in the Microsoft.DirectX.Direct3D namespace, but I get an IllegalArgumentException regardless of the arguments I feed it. My code looks like this:

Code:
Bitmap bitmap = new Bitmap(blockWidth, blockHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
Graphics graphics = Graphics.FromImage(bitmap);
(... draw with graphics object ...)
Texture texture = Texture.FromBitmap(Game.device, bitmap, 0, Pool.Default);

The last line throws the exception. Ive tried several different Usage enumerations (3rd argument), and three or four PixelFormats for the Bitmap object, but I cant get rid of the exception. The worst part is that the exception doesnt explicitly tell me whats wrong, and neither does MSDN and its preliminary documentation. Can anybody point me in the right direction please?

Thanks in advance,
Contrast
 
Im not at a machine that has DX installed right now but I can help (hopefully)!

Look in the folder DXSDK\bin\dxutils for a program called dbmon.exe (I may have dxutils and bin swapped in the actual path).

Run this program before you run your DX9 app. Its a console app that picks up a bunch of messages from DX9 - some informational, but a lot of error information, too. It should be able to tell you whats wrong. Especially with textures, DX9 is very particular about the pool a texture is located in as well as the usages defined when youre creating or copying textures. Hopefully DBMon will tell you whats wrong (like you cant use the Default pool for textures loaded from bitmaps or something like that).

Alternatively, if you really want a lot of info spewed out, turn on managed debugging (go to the Project Properties to turn this on). If you look in the Output window (ctrl-alt-o) youll see the *real* DX9 errors get spit out, along with a ton of other information.

If you still cant get it working by tomorrow, let us know. Ill try and create a test project here to see what I get.

-ner
 
Thanks a lot, I turned on that unmanaged debugging flag and was provided immediate insight, after MSDN didnt give me a thing (of course thats partly due to the SQL Server worm slowing us all down). It turns out that it creates the texture surface and then draws the image onto it, not vice-versa, so that the texture has to either be dynamic or be in a different pool. Since my driver apparently doesnt support dynamic textures, I switched it to the managed pool and it works like a charm. Thanks a bunch.
 
For future reference, you may have finer control of where textures (and vertex buffers, and more) go when using different pools, but for just starting with .NET Id go with the Managed pool for pretty much everything. In the managed pool, you dont have to worry about freeing resources when the device is lost or reset. By using the Default pool youll have to sync up the devices reset so that all of your resources are freed and re-created at that time.

Also, I noticed that turning on the managed debugging added a TON of information whereas dbmon only spits out messages from DirectX. If you have a not-so-fast machine like me then it may be better to just use dbmon. Glad you got the problem worked out though :)

-nerseus
 
apanjocko, this thread is REALLY old. But yes, if you have DX SDK installed with the Debug runtime, you can turn on the UnManaged Debugging to see a TON of info (not just on DX, but from all the System DLLs as well).

-Ner
 
Back
Top