that is not too advanced. you just flip the rows. row max and row zero exchange.
just draw it the way the tool wants it, and flip your iteration.
1 2 3 4 5 6 7 8 9 10 11 12
for(rows = maxrow; rows; rows--) //if maxrow is the size, you need -1 here
for(cols = 0; cols <= maxcol; cols++) //if maxcol is the size, use < not <= here
{
img[rows][cols] = pixeldata; //its correct to think top down here, but its filling it bottom up
}
what-if you had a top down and a bottom up then? adding a top-down source to copy from:
for(rows = maxrow; rows; rows--) //if maxrow is the size, you need -1 here
for(cols = 0; cols <= maxcol; cols++) //if maxcol is the size, use < not <= here
{
img[rows][cols] = topdown[maxrow-row][cols];
}
it may be faster to have an extra iteration variable for maxrow-row that goes 0-maxrow.
but that is code tweaking, the logic is identical.
The problem is that memory_buffer uses has origin (0,0) the bottom left corner of screen. I want to pass (0,0) to top left corner of screen with a formula. No success so far. Memory buffer is continuos. Your go through with a pointer. Doesn't have rows or columns.
p - pointer to buffer memory
x,y - coords
*4 = 4 bytes per color in buffer memory
p += y * 4 * buffer_width;
p += x * 4;
This formula will start your pixels origin from bottom left corner. I want it to start on top left corner of screen.
you can make a 1-d to 2-d.
the standard formula is:
oned[desired row* number_cols + desired_col];
that is C/C++ memory layout.
a different and more complex mapping for going over it your way is doable. But its inefficient: you will go much faster iterating it forward as it is in memory. And the subtraction costs a bit too.
what you do is take the above formula and do what I did in the code above to revere the rows.
so instead of desired_row you get (maxrow-desired_row) I think, or something like that.
My memory buffer starts putting pixels from bottom left corner, line by line, all the way up on screen. It's bottom top. I want to start on top left corner moving down. Struggling with a working formula for that.
Also make sure to choose 32 bits-per-pixel so that exactly zero bytes of padding are required after the end of a scan line. Row stride (the offset from the start of one scan line to the next) must be a multiple of four. Moreover the start of each scan line must be aligned on a 4-byte boundary.
If you use the windows memory functions to get space for the bitmaps you are guaranteed a DWORD alignment, but honestly, the C and C++ memory managers should do that for you on Windows as well, unless you fiddle with some compiler flags to turn that off.