Skip to main content
gamedev.net
🔒 Locked

Accessing Texture Memory directly!!!

Started by ji yan Apr 19, 2002 at 11:52 PM 1 replies 200+ views
Original Post
ji yan
ji yan
I created a texture with the function: if(FAILED(m_pd3dDevice->CreateTexture(256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED , &m_pFiremap))) { return E_FAIL; } Notice that the format of this texture I used is D3DFMT_A8R8G8B8 which reserves 32-bit of memory for it. 8 bits of it serve as blue, 8 as red, green, alpha, respectively. And here is the code used to color the texture; D3DLOCKED_RECT surfaceBit; D3DSURFACE_DESC descBit; if(FAILED(m_pFiremap->LockRect(0, &surfaceBit, NULL, 0))) return E_FAIL; char* surface = (char*)surfaceBit.pBits; m_pFiremap->GetLevelDesc(0, &descBit); UINT wtex = descBit.Width; UINT htex = descBit.Height; for(UINT y = 0; y < htex; y++) { for(UINT x = 0; x < wtex; x = x + 4) { surface[y * surfaceBit.Pitch + x] = (char)255; surface[y * surfaceBit.Pitch + x + 1] = (char)0; surface[y * surfaceBit.Pitch + x + 2] = (char)0; surface[y * surfaceBit.Pitch + x + 3] = (char)0; } } m_pFiremap->UnlockRect(0); I found out that in the 32-bit memory of one pixel on my texture, first 8 is for blue, second 8 is for green, third 8 is for red. It makes sense that the forth 8-bit is for alpha. However, no matter what value I set to the forth 8-bit(I have tried to assign it 0, 1, 255), there is no effect on my texture at all. Can anyone tell me why?
a person
a person
you need to turn on blending, check the docs for the renderstate you need to change.

EDIT: btw you should read/write an entire pixel using a unsigned long. then break/assemble the colors using the shift operator. its MUCH faster then the way you are doing it.

  
// simple macros

#define ARGB(a, r, g, b) (((a)<<24)|((r)<<16)|((g)<<8)|(b))
#define G_ALPHA(color) (((color)>>24)&0xFF)
#define G_RED(color) (((color)>>16)&0xFF)
#define G_GRN(color) (((color)>>8)&0xFF)
#define G_BLU(color) ((color)&0xFF)


they should work, if not they i either made a type or you are using them wrong.



[edited by - a person on April 20, 2002 2:57:34 AM]
FuzzyBunny
FuzzyBunny
Are you using D3DColorARGB(a, r, g, b) function?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.