why does D3DXSprite render my textures upside down!?!?

Started by
4 comments, last by metalmidget 15 years, 11 months ago
Here are some snippets of my code:

//texture loading
IDirect3DTexture9* temptex;
D3DXCreateTextureFromFile(gD3DDevice, "Images\\frames.bmp", &temptex);
mTextures.push_back(temptex); //pointer to texture is now stored in a vector

//rendering
//(HR() is a debugging macro that handles return values of HRESULT functions
HR(gD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0));
HR(gD3DDevice->BeginScene());
	HR(mSprite->Begin(D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_DONOTMODIFY_RENDERSTATE));
		HR(gD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true));
		mSprite->Draw(mpResourceManager->GetTexture(TEX_FRAMES), NULL, NULL, NULL, 0xFFFFFFFF);
		mSprite->Draw(/*other stuff*/)
		mSprite->Draw(/*other stuff*/)
		HR(mSprite->Flush()); //stick them all on the buffer
		HR(gD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false));
	HR(mSprite->End());
HR(gD3DDevice->EndScene());
HR(gD3DDevice->Present(0, 0, 0, 0));

Everything seems to work fine except that my sprites all come out upside down :( I guess I could just use a transformation matrix to flip everything back the way it should be, but I'd rather know why stuff is coming out upside down in the first place... cheers, metal
Advertisement
As a random guess, it probably has something to do with using the D3DXSPRITE_OBJECTSPACE flag on Sprite->Begin() and not setting up any object space -> screen space transforms, nor supplying any object space info in the first place as far as I can tell.

It depends on what you need, but if you just want to render textures to the screen you could try removing this flag and see if it works like you expected.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
According to a book I have, that flag "means the sprite's coordinates are relative to its own local coordinate system. Omitting this flag means the sprite's coordinates are specified in screen space (ie, in units of pixels with the positive y-axis going down and the positive x-axis going to the right)."
I already tried taking out the flag, but that just makes nothing at all show on the screen. I'll wait for more responses but in the meantime I guess I'll read what the SDK says about the flags for ID3DXSprite::Begin().

cheers,
metal
OK, the problem was the D3DXSPRITE_DONOTMODIFY_RENDERSTATE flag. It's gone now and my sprites are the right way up.

cheers,
metal
thanks metalmidget, I can learn how to draw sprite from your code.
Just keep doing!
No worries. PM me if you have any questions.

This topic is closed to new replies.

Advertisement