The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: RedXVII on April 21, 2006, 11:57:26 AM

Title: Directx9 SpriteDraw
Post by: RedXVII on April 21, 2006, 11:57:26 AM
Ok, ive a query about directx9. I hope someone here knows something about it :) See, i was going to write a tutorial in assembly on it, but even I cant get it right. :( 

So, Ive come accross the D3DXCreateTextureFromFile, D3DXCreateSprite, etc. commands which make it "oh so simple" to render 2D stuff to screen. I thaught, yipee; but when i did an example just to load a simple bitmap to screen, i can compare the one i open with paint with the one in my window. The one in the paint of course looks really nice, pixels all in the right place; the one in my window all blotchy and blurred. So i thaught Rasterisation and maybe something wrong there.

Apparently not, because with a closer look i realised my image is being stretched on the Y-axis ONLY. Im just useing standard defaults on gSprite->Draw ...  without any transform matrices for stretching/rotation. And it renders absolutely CRAP, it looks like shit. Why the hell is it stretching on the Y-Axis as default? Anyone got any suggestions?

Thanks for any enlightenment here.  :U

Id rather not post the code because i'd have to tidy it up to make it readable for other people =) but i will if someone wants me to, screenies and all.
Title: Re: Directx9 SpriteDraw
Post by: u on April 21, 2006, 12:29:51 PM
Maybe the problem is in setting up your window's size and maintaining constant aspect ratio :/ ?
Try setting up D3D in fullscreen (640x480, for instance), and see again the result.
Title: Re: Directx9 SpriteDraw
Post by: RedXVII on April 21, 2006, 05:07:01 PM
Yeah, aspect ratio is a good idea, i checked it out. Im kinda new to directx and ive only been using windows soo far. I tried to get it to do fullscreen, but it shouted at me so i stopped.

What i did was i made a trasformation matrix gSprite->SetTransform ... to see how much it was off by.

I got to the following matrix when it almost looked perfect (although its still blurry, Rasterisation? any idea on how to get rid of it with sprites?)

1.0  0.0      0.0  0.0
0.0  0.875  0.0  0.0
0.0  0.0      1.0  0.0
0.0  0.0      0.0  1.0

0.875? isnt that like, an aspect ratio of 7:8 off? Eeeek! It seems it would be the quite likely that aspect ratio is the cause. My monitor is a dodgey LCD 1400x1050  (dont ask) but thats still 4:3.

Any ideas?
Title: Re: Directx9 SpriteDraw
Post by: u on April 21, 2006, 08:04:42 PM
I just made a D3D framework for myself, tested a bit, and found the reason:

Your bitmap is not 256x256, 512x256 or 512x512...
Demonstration+src are attached
Title: Re: Directx9 SpriteDraw
Post by: u on April 21, 2006, 08:22:08 PM
IDirect3DTexture9->GetLevelDesc returns Width and Height of the "odd.png" as 512x512, thus I conclude that during loading of the texture, it gets resized to fit the larger regular rectangle (wid=2^x; hei=2^y;) . Thus, we can't save VRAM anyway. And we'd get our images blurred if our own images were not of regular size by default.
Title: Re: Directx9 SpriteDraw
Post by: RedXVII on April 21, 2006, 08:39:52 PM
what the hell!? i just checked, and youre absolutley right. How the jellybabies did you know that?  :eek  With my lack of experiance, I would have never have got that.  :clap:

my bitmap size was 128x448. And coincidenly, 512x0.875=448 which explains my lame ass scaling. And ive now extended it to 128x512 and its soooooo beautifully crisp now in 1:1 rendering, in its amazing original quality!!!

Thank you sooo much Ultrano, youve made my day!   :dance:
Title: Re: Directx9 SpriteDraw
Post by: RedXVII on April 22, 2006, 01:55:35 AM
While im on the topic, does anyone know how to flip the image vertically/horizontally? I geuss i'd have to use the gSprite->SetTransform somehow? But because directx9 is "meant to be a 3D" 2D surface, i cant see how you could just flip it. Any ideas?
Title: Re: Directx9 SpriteDraw
Post by: u on April 22, 2006, 03:51:18 AM
In the DX9 SDK version that I have, (ver 34), there's no sprite->SetTransform... man I see lots of big changes in the API among these sub-versions  :eek. At least they're only for good :)

The transform matrices for a 512x512 texture are:

vertical flip:
1  0 0 0
0 -1 0 0
0 0  1 0
0 512 0 1

horizontal flip:
-1 0 0 0
0 1 0 0
0 0 1 0
512 0 0 1

Change the "512" values to your sprite's height and width respectively.


lol I lost 1 hour in ignorance that D3DXMatrixReflect, D3DXMatrixTranslation and the like are not the matrix operations themselves  :red