D3D9 Texture Pixels
Hi there, I want to be able to plot pixels onto a Direct3D Texture.. I really need to be able to do this one way or the other..
Here is a stripped down version of what I have, and what I'm trying to do..
LPDIRECT3DTEXTURE9 Texture = NULL;
D3DXCreateTexture(Direct3DDevice,200,200,D3DUSAGE_AUTOGENMIPMAP,D3DUSAGE_RENDERTARGET,
D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&Texture);
D3DLOCKED_RECT LockedRect;
Texture->LockRect(0,&LockedRect,0,0);
DWORD *pDst = (DWORD *)LockedRect.pBits;
int DPitch = LockedRect.Pitch;
for(int Y=0; Y<200; Y++)
for(int X=0; X<200; X++)
pDst[Y*DPitch + X] = 0xFF00FFFF;
Texture->UnlockRect(0);
What I want this to do is draw a 200x200 fuscia square onto my texture, but it crashes when I try run this..
Any ideas?
try
and see if it still crashes. If it does not, your lock didn't succeed and the variable hr stores the reason why!
Maybe the creation parameters for your texture are wrong(?)
D3DLOCKED_RECT LockedRect;HRESULT hr = Texture->LockRect(0,&LockedRect,0,0);if (SUCCEEDED(hr)){DWORD *pDst = (DWORD *)LockedRect.pBits;int DPitch = LockedRect.Pitch;for(int Y=0; Y<200; Y++)for(int X=0; X<200; X++) pDst[Y*DPitch + X] = 0xFF00FFFF;Texture->UnlockRect(0);}
and see if it still crashes. If it does not, your lock didn't succeed and the variable hr stores the reason why!
Maybe the creation parameters for your texture are wrong(?)
1: Quoting from D3DPOOL documentation:
2:
Does your card support non-powers-of-two texture dimensions (not 2, 4, 8, 16 etc.)?
Quote:Textures placed in the D3DPOOL_DEFAULT pool cannot be locked unless they are dynamic textures or they are private, four-character code (FOURCC), driver formats. To access unlockable textures, you must use functions such as IDirect3DDevice9::UpdateSurface, IDirect3DDevice9::UpdateTexture, IDirect3DDevice9::GetFrontBufferData, and IDirect3DDevice9::GetRenderTargetData. D3DPOOL_MANAGED is probably a better choice than D3DPOOL_DEFAULT for most applications.
2:
Does your card support non-powers-of-two texture dimensions (not 2, 4, 8, 16 etc.)?
Hey guys, thanks for the fast response.. So I tried D3DPOOL_MANAGED and it threw D3DERR_INVALIDCALL, so maybe this is a problem with how my texture is created.. I found the exact lines causing the crash..
LPDIRECT3DTEXTURE9 Texture = NULL;
D3DXCreateTexture(Direct3DDevice,200,200,D3DUSAGE_AUTOGENMIPMAP,D3DUSAGE_RENDERTARGET,
D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&Texture);
D3DLOCKED_RECT LockedRect;
Texture->LockRect(0,&LockedRect,0,0);
DWORD *pDst = (DWORD *)LockedRect.pBits;
int DPitch = LockedRect.Pitch;
//for(int Y=0; YUnlockRect(0);
This runs without any visible problems.. Yep I'm pretty sure its the texture creation :), now how do I fix it?
LPDIRECT3DTEXTURE9 Texture = NULL;
D3DXCreateTexture(Direct3DDevice,200,200,D3DUSAGE_AUTOGENMIPMAP,D3DUSAGE_RENDERTARGET,
D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&Texture);
D3DLOCKED_RECT LockedRect;
Texture->LockRect(0,&LockedRect,0,0);
DWORD *pDst = (DWORD *)LockedRect.pBits;
int DPitch = LockedRect.Pitch;
//for(int Y=0; YUnlockRect(0);
This runs without any visible problems.. Yep I'm pretty sure its the texture creation :), now how do I fix it?
Hi,
If you wont ever update the texture contents then just load it from a BMP. But if you are planning to update this info, then dont do this.
Instead try taking advantage of the D3D path. That is:
a. Learn how to render a vertex buffer as points into the screen. You may like to read about transformed-lit coords
b. Once you know how to render points to the screen, create a texture and use it as a rendertarget. That is, render into the texture instead of the screen.
c. Once you have the texture, render it into the screen as a quad.
Of course this is more complicated, but believe me it won't as much time as Locking/Unlocking and rendering (it may stall the pipeline).
Luck!
Guimo
If you wont ever update the texture contents then just load it from a BMP. But if you are planning to update this info, then dont do this.
Instead try taking advantage of the D3D path. That is:
a. Learn how to render a vertex buffer as points into the screen. You may like to read about transformed-lit coords
b. Once you know how to render points to the screen, create a texture and use it as a rendertarget. That is, render into the texture instead of the screen.
c. Once you have the texture, render it into the screen as a quad.
Of course this is more complicated, but believe me it won't as much time as Locking/Unlocking and rendering (it may stall the pipeline).
Luck!
Guimo
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement