Skip to main content
gamedev.net
🔒 Locked

D3DXCreateTextureFromFileEx problem

Started by MuruGuru Nov 21, 2003 at 10:33 AM 9 replies 1.9k views
Original Post
MuruGuru
MuruGuru
Greetings. I have a problem in my game,i use dx8 and c++ and since my game is 2d, i don''t want my textures to be filtered or blurred. The problem is i load with the D3DXCreateTextureFromFileEx function with D3DX_DEFAULT as texture filtering parameter. When i change D3DX_DEFAULT into D3DX_FILTER_NONE the picture gets shrunk and lots of weird stuff. I do not know what the problem is, but i simple cannot change D3DX_DEFAULT into D3DX_FILTER_NONE without getting the picture all messed up. If you think it''s to any help the picture is 640*480, but even when i try it with small ones like 64*64 they get weird. I really need help, the graphics would look ten timess better if i got rid of this problem.
Your memory is like cheese. It's full of holes, and most of it stinks
MuruGuru
MuruGuru
Noone has replied yet.
Can''t anyone help me?
Your memory is like cheese. It's full of holes, and most of it stinks
MindWipe
MindWipe
Sorry, dunno what''s the problem. I''m not into 3D that much(yet).

I just felt bad that nobody replied.

/MindWipe
"To some its a six-pack, to me it's a support group."
purple_code
purple_code
I don''t know if this will work, or if this is the problem, but, make sure that the polygon you are rendering takes up exactly the same number of pixels on the screen as the size of the texture.

For example, if you have a 64x64 texture, draw a polygon so that after all the transformations the polygon will take up 64x64 pixels on the screen.

If you use the D3DFVF_XYZRHW vertex format, just simply make the polygon to be 64.0f wide and 64.0f high.

I hope this helped a bit.

Cheers,
Rados
Blabberboy [disabled]
Blabberboy [disabled]
I think I sorta get what the problem is... I''m not sure what the value for it is, but try setting the filtering to D3DX_FILTER_NEAREST or whatever. what might be happening is that when you tell it to not filter at all, it has no way of stretching the image, so it doesn''t. so, using a Nearest filter, it''ll just use the nearest pixel (texel or whatever) to the one it wants. It won''t look at nice as if you draw the polygons to be the exact size of the texture though.
MuruGuru
MuruGuru
Thanks MindWipe.

I do use D3DFVF_XYZRHW and the background is 640*480, with the coordinates 640.0f and 480.0f. When i use D3DX_DEFAULT it shows up right size but blurry. It is only when i try to make it look non-blurry by changing it to D3DX_FILTER_NONE that it gets weird and shrunk.

BlabberBoy, it''s a possibility that when it has no filter it won''t stretch. But, the source file, for instance "bg.PNG" is 640*480 pixels and that should mean no stretching. Anyway, if it is the problem, does anyone know how to have no filtering but making it able to scale?

Also, there is no filter called D3DX_FILTER_NEAREST.

I haven''t solved the problem yet, but i''m grateful for the replies.
Your memory is like cheese. It's full of holes, and most of it stinks
S1CA
S1CA
Random assortment of thoughts:

1. Remember to check the device caps and use the Check* calls to find suitable formats when creating textures. In particular:

a) The dimensions. Many cards only support textures with power-of-2 dimensions (i.e. 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048).

b) The shape. Some cards only support square textures.

c) The format. Different cards support different formats. Some expose D3DFMT_R5G6B5 as their only 16bit format, others only expose D3DFMT_X1R5G5B5, others expose both, some older ones don''t even support 32bit textures.

If you disobey any of the above caps for the particular device you''re running on, then problems can manifest themselves elsewhere - what you''re seeing could very easily be a red herring caused elsewhere.

"Stretching" and general wrongness (modulo/skewed image, random pixels etc) is the kind of thing I''ve personally seen when disobeying the above caps.



2. Link with D3DX8D.LIB instead of D3DX8.LIB, make sure the debug D3D runtime is enabled in the contol panel and its level is up high then check your output window after running again.
The debug runtimes and debug D3DX library perform a ton of extra parameter validation so can give you good early warnings and advice about bad things that may cause problems later on.


3. Try using D3DX_FILTER_POINT instead of D3DX_FILTER_NONE. That''s the name for the flag BlabberBoy was thinking of.


4. What other parameters you''re passing to D3DXCreateTextureFromFileEx()? - are you generating a mip map chain for example - if you are, set the MipFilter value to D3DX_FILTER_POINT as well.


5. A screenshot would be very handy to help identify the problem. Once we can "see" exactly what your problem is, the answer will be obvious if anyone reading has "seen" the problem before in their own apps. "shrunk and lots of weird stuff" and "messed up" don''t really tell us enough.

--
Simon O''Connor
3D Game Programmer &
Microsoft DirectX MVP
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
MuruGuru
MuruGuru
Well, thanks a lot S1CA.
I tried to use D3DX_FILTER_POINT on the sprites and they came out exactly as i wanted them. Note: they''re square.(149*149)
Now about the background, if it doesn''t work just because it isn''t square, then i have a big problem, since it''s going to be background for a 640*480 game, and it should be that exact size.

Anyway, here are the screenshots about the bg problem:
With D3DX_DEFAULT

With D3DX_FILTER_NONE

Now if anyone have had this problem they should recognize it.
Your memory is like cheese. It's full of holes, and most of it stinks
S1CA
S1CA
quote:
Original post by MuruGuru
Now about the background, if it doesn't work just because it isn't square, then i have a big problem, since it's going to be background for a 640*480 game, and it should be that exact size.


You can check the caps for your card in the DirectX Caps Viewer - in particular check:

DirectX Graphics Adapters ->
[YourCard] ->
D3D Device Types ->
HAL ->
Caps ->
TextureCaps ->


for:
D3DPTEXTURECAPS_POW2 - indicates that the device will only *properly* support textures that have power of two dimensions. Any texture that disobeys this cap but still works is pure fluke - if you do disobey it, expect random behaviour (e.g. some sprites work, others don't) and compatibility issues (e.g. works on one revision of a driver but not another, works on one graphics card but not another).


D3DPTEXTURECAPS_SQUAREONLY - only square textures are supported. See above for the kinds of things that happen if you disobey it.


D3DPTEXTURECAPS_NONPOW2CONDITIONAL - the device WILL support textures that aren't power of 2 in dimension (such as 149x149), but will only work properly if you also obey the following additional conditions:

* The texture addressing mode for the texture stage is set to D3DTADDRESS_CLAMP.

* Texture wrapping for the texture stage is disabled (D3DRS_WRAPn set to 0).

* Mipmapping is not in use (use magnification filter only).

* Texture formats must not be DXT1-5.


D3DPTEXTURECAPS_MIPMAP - the device support mip map chains. If this isn't shown, you should make sure the number of mip map levels in your create call is set to 1.


I suspect your graphics card has the D3DPTEXTURECAPS_NONPOW2CONDITIONAL and D3DPTEXTURECAPS_POW2 caps set and either

a) the render states you have set up for you 640x480 map are different than the ones for your sprites in some way that is causing them to disobey the rules for D3DPTEXTURECAPS_NONPOW2CONDITIONAL.

or..

b) the fact that the sprites are working but the background isn't is a fluke and could potentially break.


The usual solution to the problem of how to load and display a 640x480 background when the graphics hardware has limitations such as power-of-2 (nearly all cards have that limitation - it helps with mip mapping and video memory management) is to split the background up into multiple textures that DO comply with the device caps when you load it. Rough recipe:

- Use the D3DPOOL_SCRATCH pool with your CreateTextureFromFileEx() call when you load the 640x480 image file - that pool is a temporary [non-renderable] pool that is free from hardware restrictions. Specify one mip map level and no filtering.

- Create multiple normal textures that DO comply with the device caps to split the 640x480 into.

- Use D3DXLoadSurfaceFromSurface() and its RECT parameters to copy from the relevant parts of the 640x480 texture into the relevent compliant texture.

- Use D3DXFilterTexture() to create the mip map levels and filter for each of the compliant textures.

- Render as multiple quads instead of one big quad.

A suggested layout for the quads which works with pow2 and squareonly cards would be:

+-------+--+
| |B1|
| A +--+
| |B2|
+-------+--+


A = a 512x512 texture
B1 = a 128x256 slice of a 256x256 texture
B2 = a 128x256 slice of a 256x256 texture

If squareonly isn't a problem, B1 and B2 can be a single 128x512 texture.

There is a small bit of memory wastage because the above gives you a 640x512 area of texture and you're only displaying a 640x480 part of that - but it isn't much, and you could use that texture area for other texture or as scroll borders for things like earthquake effects anyway.

An alternative if sacrificing/wasting memory isn't a problem is to use an even larger power of 2 texture for the whole screen (say 1024x1024).

BTW the D3DXCheckTextureRequirements() call may be of use to you too.

[EDIT: clipboard madness within my post]



[edited by - s1ca on November 22, 2003 8:20:36 PM]
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
johnnyBravo
johnnyBravo
if you want the settings heres what iuse
D3DXCreateTextureFromFileEx( D3D::lp_Device, filename,
fileInfo.Width, fileInfo.Height, 1, D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, colourKey, &d3dxImageInfo, NULL, &lp_Texture );
MuruGuru
MuruGuru
Thank you very much S1CA! I got it working now, using the 1024*1024 method. Now i don''t need to worry about that any more.
Your memory is like cheese. It's full of holes, and most of it stinks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.