Jump to content
  • Advertisement
Sign in to follow this  
RealityMeltdown

2-D in Managed DirectX 9

This topic is 4832 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

I had some working DirectX 8 code in C++ but decided to port it over to C#. My problem has been drawing a rectangle from a file to the screen(One of my 32x32 tiles). I can move in on the screen just fine, but I've had some rather odd effects on-screen. Trying to track this down, I've simplified my drawing to the following: using: Device mDevice; Sprite mSprite; Texture mTexture; Point dest = new Point(0,0); Size size = new Size(32,32); mDevice.Clear(ClearFlags.Target, Color.Black, 0, 0); mDevice.BeginScene(); mSprite.Begin(SpriteFlags.None); mSprite.Draw2D(mTexture, new Rectangle(new Point(0,0), size), new Rectangle(dest, size), dest, Color.Transparent); mSprite.End(); mDevice.EndScene(); mDevice.Present(); I've found this copies a (roughly) 24 by 32 square and stretches it to 32 by 32. The other variables are intialiazed as follows: presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; mDevice = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); mSprite = new Sprite(mDevice); mTexture = TextureLoader.FromFile(mDevice, filename, 0, 0, 1, 0, Format.Unknown, Pool.Managed, Filter.Linear, Filter.None, TRANS_COLOR); Anyone else seen this sort of thing? I'd perfer not to use the deprecated DirectDraw API; and .. as I mentioned, it worked in C++ for DirectX8... but I've also got to get it to use transparency properly (might just be able to make a bitmap with an alpha layer, but I'd fiddle with that after this is done).

Share this post


Link to post
Share on other sites
Advertisement
I'll say up-front that I'm not a managed programmer, but I have seen this in native D3D before - so maybe its the same thing [smile]

mTexture = TextureLoader.FromFile(mDevice, filename, 0, 0, 1, 0, Format.Unknown, Pool.Managed, Filter.Linear, Filter.None, TRANS_COLOR);

The two params I bolded above are the height/width iirc? and that specifying them to be 0 tells MDX that you want it to create a texture based on whatever dimensions it reads from the file.

I don't know the managed syntax for it (I'll have a look when I get back from my break), but in C++ there are ways to get the information on a texture's surface - height/width/format etc... if you can get this information and verify that the loaded file is actually 32x32 in size, it'd be useful.

I know it might sound obvious to check the actual source file, but thats not always a guarantee I've found (don't know why).

What I saw some time ago was that I accidently loaded some 64x28 textures in using a similar technique - my artist told me they were 64x32, and I took his word for it (more fool me [grin]). D3D found that '28' is not a valid size, so padded it out to being a 64x32 texture and did some linear stretching to make it fit...

Might be worth double-checking that your internal buffers contain exactly what you think they do [smile].

hth
Jack

Share this post


Link to post
Share on other sites
Well, I followed your advice and found the issue.
I ran the following:
TextureRequirements texReq;
Console.WriteLine(TextureLoader.ImageInformationFromFile(filename));
TextureLoader.CheckTextureRequirements(mDevice, 0, Pool.Default, out texReq);
Console.WriteLine(texReq);

Got this:
ImageFileFormat: Bmp
ResourceType: Textures
Format: A8R8G8B8
MipLevels: 1
Depth: 1
Height: 128
Width: 96

Format: A8R8G8B8
NumberMipLevels: 1
Height: 1
Width: 1

Which looks correct (Well, the width and height being 1 are weird).

Since that was all working, I decided to try making the image 128 by 128.
And it worked.

Aparently it scales them on some obscure pattern for images that aren't square.

Share this post


Link to post
Share on other sites
Quote:
Original post by RealityMeltdown
Since that was all working, I decided to try making the image 128 by 128.
And it worked.

Aparently it scales them on some obscure pattern for images that aren't square.

What sort of hardware are you running this on? I haven't seen it in a long time - but there is the possibility for your hardware not supporting "non square" textures. I don't know what the exact CAP-bit is in the managed world, but it should be in the documentation...

I would expect, for a 96x128 texture, that it'll stretch the width to 128x128 or 64x128. 96 is a non-power-of-2 dimension, so it'll try and avoid it.

You'll probably get a good answer on this if you go and query the texture information after loading it. Find out what dimensions its stored once it's been loaded... if I'm correct about the stretching thing, you won't have a 96 width [smile]

hth
Jack

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!