It looks like day 56 is missing some utilities that you might find useful.
Now we have PushSize, which would be a better candidate for allocating memory for a bitmap, but it just calls PushSize_, which already exists on day 56.
We also have the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 | internal void
ClearBitmap(loaded_bitmap *Bitmap)
{
if(Bitmap->Memory)
{
int32 TotalBitmapSize = Bitmap->Width*Bitmap->Height*BITMAP_BYTES_PER_PIXEL;
ZeroSize(TotalBitmapSize, Bitmap->Memory);
}
}
internal loaded_bitmap
MakeEmptyBitmap(memory_arena *Arena, int32 Width, int32 Height, bool32 ClearToZero = true)
{
loaded_bitmap Result = {};
Result.AlignPercentage = V2(0.5f, 0.5f);
Result.WidthOverHeight = SafeRatio1((r32)Width, (r32)Height);
Result.Width = Width;
Result.Height = Height;
Result.Pitch = Result.Width*BITMAP_BYTES_PER_PIXEL;
int32 TotalBitmapSize = Width*Height*BITMAP_BYTES_PER_PIXEL;
Result.Memory = PushSize(Arena, TotalBitmapSize, 16);
if(ClearToZero)
{
ClearBitmap(&Result);
}
return(Result);
}
|
There's a good chance that the loaded_bitmap struct changed since day 56, but that's pretty much what you'd want to do to create an empty loaded_bitmap of the correct size.
After that, you just need to copy over the pixel data that you get from stb_image (and possibly rearrange the pixel components).