News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Directx9 SpriteDraw

Started by RedXVII, April 21, 2006, 11:57:26 AM

Previous topic - Next topic

RedXVII

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.

u

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.
Please use a smaller graphic in your signature.

RedXVII

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?

u

#3
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
Please use a smaller graphic in your signature.

u

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.
Please use a smaller graphic in your signature.

RedXVII

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:

RedXVII

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?

u

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
Please use a smaller graphic in your signature.