Basically, your last post loops through
i and
ii but doesn't do anything to change x or y. So, you keep setting the same pixel, possibly incorectly (see below).
Also,
y should be multiplied by the
pitch and
x should be multiplied by the
number-of-bytes-per-pixel when using
u8 pointers to pixels .
(ITexture::getColorFormat() indicates the number of bytes-per-pixel if you understand how to interpret ECOLOR_FORMAT).
See
ITexture::getPitch(); The pitch is the number-of-pixels-on-a-line
* Number-of-bytes-per-pixel (e.g. 4 for ARGB)
+ some-amount-of-overhead-bytes-that-hang-onto-the-end-of-a-line-of-pixels (typically 0 to 4 bytes, depending on the video hardware.) Irrlicht will figure that out for you at run-time, so if you're using
u8's as a pointer, using (y*pitch) is a convenient way to jump down "y number of rows" on your texture before adding x*bytes-per-pixel.
If you are using
u8's as pointers to a specific position in the texture, once you find the pixel you will need to offset the pointer by 0 to 3 bytes before setting it, in order to point it at the specific A, R, G or B value. So, like
Code: Select all
pixel[(y*pitch) + (x*bytesPerPixel) + 3]=255;
will set the last byte of a pixel to 255.
Also, the format that the video card uses to represent a pixel may not be ARGB like we think. Grrr
! ( Mine, for instance, uses BGRA.) I totally forget the rules to figuring this out, though hybrid has explained this at least a few times somewhere here on the boards. (I forget what to search on though. It would be nice to be able to find that in the docs. I just can't right now
)
Also, for efficiency, try to remove as much code between lock() and unlock() as possible, so, don't initialize
texSize, x, or
y there.