procedural texture

Started by
1 comment, last by sirob 15 years, 12 months ago
If I create a 256x256 texture, how do i edit any block in the texture after locking, and assign a color?
Advertisement
The D3DLOCKED_RECT structure has a pBits member which points to the data and a Pitch member which says how many bytes per row. Accessing a specific pixel would depend on the texture format, but assuming A8R8G8B8, the address of the pixel (x,y) (both in range 0 to 255) would be:

reinterpret_cast<uint32_t*>(pBits) + y * Pitch + x
Also, to convert your color from seperate R, G, B and A components, you can use the D3DCOLOR_RGBA macro (or any of the D3DCOLOR_* macros). D3DCOLOR_RGBA expects values in the 0..255 range.

If you're hardcoding values, you can use hex format to get the color simply:
(example for bright green, with 255 alpha)
D3DCOLOR myColor = 0xFF00FF00;

The format is 0xAARRGGBB.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.

This topic is closed to new replies.

Advertisement