Skip to main content
gamedev.net
🔒 Locked

Sprite problem

Started by beebs1 5 replies 600+ views
Original Post
beebs1
beebs1
Hi, I have set up D3D in exlusive mode to 800x600, but when drawing a sprite near that resolution (for example 790x590), it is drawn way too big and extends past the edges of the screen. With a 400x300 sprite, it should cover half the width and half the height of the screen, but instead it is drawn at about 550x600 (at a guess), which is also too big. Incidentally, if I try to draw a 450x350 sprite, it occupies exactly the same area as the 400x300... I probably havn't explained very well, but if anyone could suggest what might cause this it would be very much appreciated.
Captain P
Captain P
Sounds like they're rendered at various distances from the camera? I've got no experience with D3D, but you should probably look for a orthogonal view mode, or however it's called in D3D.
beebs1
beebs1
Hi -

Thanks for the idea Captain P. It seems that when I call D3DXCreateTextureFromFile a 300x450 pixel bitmap file is automatically set as having a width and height of 512...

Does anyone know why this would be? I can't find any mention of it in the DX Documentation.
Mastaba
Mastaba
Actually, the documentation says exactly that the dimensions will be rounded up, unless you request otherwise.
beebs1
beebs1
Erm... where?

Quote:

D3DXCreateTextureFromFile
Creates a texture from a file.

HRESULT D3DXCreateTextureFromFile(
LPDIRECT3DDEVICE9 pDevice,
LPCTSTR pSrcFile,
LPDIRECT3DTEXTURE9 * ppTexture
);
Parameters
pDevice
[in] Pointer to an IDirect3DDevice9 interface, representing the device to be associated with the texture.
pSrcFile
[in] Pointer to a string that specifies the filename. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the string data type resolves to LPCSTR. See Remarks.
ppTexture
[out] Address of a pointer to an IDirect3DTexture9 interface, representing the created texture object.
Return Values
If the function succeeds, the return value is D3D_OK. If the function fails, the return value can be one of the following:

D3DERR_NOTAVAILABLED3DERR_OUTOFVIDEOMEMORYD3DERR_INVALIDCALLD3DXERR_INVALIDDATAE_OUTOFMEMORY
Remarks
The compiler setting also determines the function version. If Unicode is defined, the function call resolves to D3DXCreateTextureFromFileW. Otherwise, the function call resolves to D3DXCreateTextureFromFileA because ANSI strings are being used.

This function supports the following file formats: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga. See D3DXIMAGE_FILEFORMAT.

The function is equivalent to D3DXCreateTextureFromFileEx(pDevice, pSrcFile, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, ppTexture).

Mipmapped textures automatically have each level filled with the loaded texture.

When loading images into mipmapped textures, some devices are unable to go to a 1x1 image and this function will fail. If this happens, the images need to be loaded manually.

Note that a resource created with this function will be placed in the memory class denoted by D3DPOOL_MANAGED.

Filtering is automatically applied to a texture created using this method. The filtering is equivalent to D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER in D3DX_FILTER.

For the best performance when using D3DXCreateTextureFromFile:

Doing image scaling and format conversion at load time can be slow. Store images in the format and resolution they will be used. If the target hardware requires power of two dimensions, create and store images using power of two dimensions.
Consider using DirectDraw surface (DDS) files. Because DDS files can be used to represent any Direct3D 9 texture format, they are very easy for D3DX to read. Also, they can store mipmaps, so any mipmap-generation algorithms can be used to author the images.
Requirements
Header: Declared in D3dx9tex.h.

See Also
D3DXCreateTextureFromFileEx, Texturing Functions



I hope that wasn't breaking any copyright law(s).
Mastaba
Mastaba
In the part where it says:
Quote:

The function is equivalent to D3DXCreateTextureFromFileEx(pDevice, pSrcFile, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, ppTexture).

Neocolis
Neocolis
It happens in the background of the d3dx function, if u check the documentation for the D3DXCreateTextureFromFileEx function u'll see this for these 2 parameters

Width
[in] Width in pixels. If this value is zero or D3DX_DEFAULT, the dimensions are taken from the file and rounded up to a power of two. If the device supports non-power of 2 textures and D3DX_DEFAULT_NONPOW2 is specified, the size will not be rounded.

Height
[in] Height, in pixels. If this value is zero or D3DX_DEFAULT, the dimensions are taken from the file and rounded up to a power of two. If the device supports non-power of 2 textures and D3DX_DEFAULT_NONPOW2 is sepcified, the size will not be rounded.

Basically unless the video card you're using supports non power of 2 textures and you tell direct3d to use those non power of 2 sizes(ie. through the D3DX_DEFAULT_NONPOW2 flag), it'll resize it to the nearest power of 2, in your case the 512x512.

Topic Locked

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

Sign in to reply to this topic.