D3DXCreateTexture

Started by
9 comments, last by neneboricua19 19 years ago
I am using D3DXCreateTexture to create a texture that I will be able to call LockRect() with. I know that you must call LockRect() from a texture created with D3DUSAGE_RENDERTARGET, and therefore not D3DPOOL_DEFAULT. They are lockable, however, when using D3DUSAGE_DYNAMIC, which means then that I must use D3DPOOL_SYSTEMMEM. So here is my creation method: D3DXCreateTexture( pd3dDevice, x, y, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture); pd3dDevice is legit, x and y are both between 1 and 10...and yet it fails every time. Where else in my program should I be looking to find out why? Thanks!
Advertisement
What error does it fail with?

Perhaps you can't create non-power-of-two textures (I don't know what your x/y values are...)
Also, if you're using D3DUSAGE_DYNAMIC you *can* use D3DPOOL_DEFAULT and it will be lockable.

-Mezz
Indeed, I reread the directx info on msdn and you are right about the D3DPOOL_DEFAULT and D3DUSAGE_DYNAMIC. My x and y values are 16...which certainly are powers of 2...

Thanks for the help so far.
The error I am getting is: D3DERR_NOTAVAILABLE, which means my device does not support my queried technique...which ain't cool.

Thoughts? Is there something I could change somewhere so that my device WOULD?
        D3DCAPS9 devCaps;	pd3dDevice->GetDeviceCaps(&devCaps);	if(!(devCaps.Caps2 & D3DCAPS2_DYNAMICTEXTURES))	{		CLog::Log("Yay for dynamic textures");	}


Guess what showed up in my logs?

So, I can make em, but they aren't working? Sweet...
That code you posted will log "Yay for dynamic textures" if dynamic textures *aren't* supported.

You need to do this, instead:

D3DCAPS9 devCaps;pd3dDevice->GetDeviceCaps(&devCaps);if(devCaps.Caps2 & D3DCAPS2_DYNAMICTEXTURES){   CLog::Log("Yay for dynamic textures");}


Unfortunately, now you already know that your card doesn't support dynamic textures [wink]
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Yeah, I realized that after I crawled into bed...im such a moron when I am tired.

Any recommendations on what to do? Maybe I can user surfaces and UpdateTexture()?
Yeah, in this case UpdateTexture() UpdateSurface() or StretchRect() are your only probable options, which one you use depends on your texture formats and usages.

-Mezz
Wait a sec. You don't have to create a texture as a render target to be able to lock it. You just have to be able to access it from system memory. But that doesn't mean that it must ONLY reside in system memory. Use D3DPOOL_MANAGED and you'll be able to lock your textures just fine without having to make them rendertargets.

neneboricua
Yes, that is another solution, but that's very slow if you regularly lock your texture.

-Mezz

This topic is closed to new replies.

Advertisement