Hello,
I’m trying to draw something directly on a pixel buffer off-screen. For that I am getting the pixels of an ofImage and manipulating them directly. It should be very easy, but trying to draw a simple rectangle results in a mishmash of pixels that show misalignments. I think I’m not getting the byte size of the pixels correctly. Can someone please explain how the buffer of an image is organized. Is there an easier way to draw to a buffer off-screen. (I want it to generate procedural textures).
Thanks in advance!
void imgPattern::setPixel(int x, int y, int c) {
switch(myPixels.bitsPerPixel)
{
case 32:
case 24:
int* buffer = (int *)myPixels.pixels;
buffer[ ((y * myPixels.height) + x) ] = c;
break;
case 8:
myPixels.pixels[ ((y * myPixels.height) + x) ] = (unsigned char) (c & 0x000000ff);
break;
}
}
void imgPattern::drawRectangle(int x, int y, int w, int h, int c) {
for(int i = y; i < (y + h); i++) {
for(int j = x; j < (x + w); j++) {
setPixel( j, i, c);
}
}
}