directx sprite problem

Started by
5 comments, last by exgex 15 years, 11 months ago
ok i have the following code

	D3DXCreateSprite(d3ddev, &d3dspt);    // create the Direct3D Sprite object
	D3DXCreateTextureFromFileEx(d3ddev,"MousePtr.bmp",D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,NULL,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,D3DCOLOR_XRGB(0, 255, 0),NULL,NULL,&cursor);
	D3DXCreateTextureFromFileEx(d3ddev,"background.png",D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,NULL,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,D3DCOLOR_XRGB(0, 255, 0),NULL,NULL,&background);


void DrawMouse()
{
	POINT cur;
	GetCursorPos(&cur);
	RECT part;
	
	static int frame;
	if(frame < 20) frame ++;
	if(frame >= 20) frame = 0;
	xpos = frame * 51;

	part.left = xpos + 1;
	part.right = part.left + 51 + 1;
	part.top = 0;
	part.bottom = 33;

	d3dspt->Begin(D3DXSPRITE_ALPHABLEND);
	D3DXVECTOR3 center(0.0f,0.0f,0.0f);
	D3DXVECTOR3 position((float)cur.x,(float)cur.y,0.0f);
	d3dspt->Draw(cursor, &part, &center, &position, D3DCOLOR_ARGB(255, 255, 255, 255));
    d3dspt->End();
}


void DrawBackground()
{
	d3dspt->Begin(D3DXSPRITE_ALPHABLEND);
	D3DXVECTOR3 center(0.0f,0.0f,0.0f);
	D3DXVECTOR3 position(0.0f,0.0f,0.0f);
	d3dspt->Draw(background, NULL, &center, &position, D3DCOLOR_ARGB(255, 255, 255, 255));
    d3dspt->End();
}

and i am using 2 images for this cursor: 760x27 px background: 1024x768 px and the 1st problem 1)My sprites for the cursor are 38 px apart, but it will only work fine when i use 51px as shown in the DrawMouse function 2)My background isnt drawn completely, like some parts are off the screen, my images are all power 2, why does that still happen 3)My cursor (the rendered sprite) also isn't accurate, at 0,0 it correpsonds with the real cursor, but at the bottom, well lets just say, that rendered cursor cant reach the bottom Thanks
Advertisement
If you don't want your textures the be scaled to power-of-2 sizes, you need to specify D3DX_DEFAULT_NONPOW2 as the Width and Height parameters of D3DXCreateTextureFromFileEx. See the documentation for more info. Also note that while the overwhelming majority of DX9-class GPU's support non-power-of-2 textures, many of them have restrictions (mainly that you can't use wrap texture addressing modes with them, you can't use mipmapping, and you can't use DXT texture compression). Make sure you check the TextureCaps member of the D3DCAPS9 structure returned by IDirect3DDevice9::GetDeviceCaps to make sure the device supports what you need it to do (you may need to load your sprites to power-of-2 sizes and then scale them back to their original size when rendering).
i did that, but the problem still remains... anyone else know how to solve it ?
if it helps i can upload the zip of my project folder for you to see
A screenshot of what is going on might be even more useful at this point than the rest of your code. Maybe it's a problem that will look familiar to someone, and they will remember how they solved it.
From the factors it's obvious that your cursor image gets upsized to 1024x32.

Modify that cursor image to be 1024x32 size and move the actual image to the upper left corner (so the offset stays the same).

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Quote:Original post by exgex


and i am using 2 images for this
cursor: 760x27 px
background: 1024x768 px

and the 1st problem

1)My sprites for the cursor are 38 px apart, but it will only work fine when i use 51px as shown in the DrawMouse function
2)My background isnt drawn completely, like some parts are off the screen, my images are all power 2, why does that still happen
3)My cursor (the rendered sprite) also isn't accurate, at 0,0 it correpsonds with the real cursor, but at the bottom, well lets just say, that rendered cursor cant reach the bottom

Thanks


Hi

part.top = 0;
part.bottom = 33;

Why is part.bottom 33 pixel high, if your cursor texture is 27 pixel high?

2) 760x27 & 1024x 768 are not power of two dimensions power of two are: 1,2,4,8,16,32,64,128,256,512,1024,2048 etc
3) Well it is possible that you are using 3d space for your drawing, and that is why some pieces are missing and cursor are nt moving to the bottom.

my question exactly ... when i put 27 and 38 .. it doesnt display properly ...

for the other problems, i have solved them last night with help from #gamedev especially from MythicalManMoth

This topic is closed to new replies.

Advertisement