Jump to content
  • Advertisement
Sign in to follow this  
draytek

D3D9 Texture Pixels

This topic is 4830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
try


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(?)

Share this post


Link to post
Share on other sites
1: Quoting from D3DPOOL documentation:

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.)?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
Pitch is in bytes, not pixels so you need to divide by the byte size of a pixel.

Share this post


Link to post
Share on other sites
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






Share this post


Link to post
Share on other sites
Hey, I would like to load from a straight bmp, but I have my own graphic file format which I designed for DirectDraw.. I am now trying to port this across, for this I need to pixel plot..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!