1717
1818#include "raylib.h"
1919
20- #include <stdlib.h> // Required for: malloc() and free()
21-
2220//------------------------------------------------------------------------------------
2321// Program main entry point
2422//------------------------------------------------------------------------------------
@@ -39,26 +37,31 @@ int main(void)
3937 UnloadImage (fudesumiRaw ); // Unload CPU (RAM) image data
4038
4139 // Generate a checked texture by code
42- int width = 960 ;
43- int height = 480 ;
40+ int imWidth = 960 ;
41+ int imHeight = 480 ;
4442
4543 // Dynamic memory allocation to store pixels data (Color type)
46- Color * pixels = (Color * )malloc (width * height * sizeof (Color ));
44+ // WARNING: Using raylib provided MemAlloc() that uses default raylib
45+ // internal memory allocator, so this data can be freed using UnloadImage()
46+ // that also uses raylib internal memory de-allocator
47+ Color * pixels = (Color * )MemAlloc (imWidth * imHeight * sizeof (Color ));
4748
48- for (int y = 0 ; y < height ; y ++ )
49+ for (int y = 0 ; y < imHeight ; y ++ )
4950 {
50- for (int x = 0 ; x < width ; x ++ )
51+ for (int x = 0 ; x < imWidth ; x ++ )
5152 {
52- if (((x /32 + y /32 )/1 )%2 == 0 ) pixels [y * width + x ] = ORANGE ;
53- else pixels [y * width + x ] = GOLD ;
53+ if (((x /32 + y /32 )/1 )%2 == 0 ) pixels [y * imWidth + x ] = ORANGE ;
54+ else pixels [y * imWidth + x ] = GOLD ;
5455 }
5556 }
5657
5758 // Load pixels data into an image structure and create texture
59+ // NOTE: We can assign pixels directly to data because Color is R8G8B8A8
60+ // data structure defining that pixelformat, format must be set properly
5861 Image checkedIm = {
59- .data = pixels , // We can assign pixels directly to data
60- .width = width ,
61- .height = height ,
62+ .data = pixels ,
63+ .width = imWidth ,
64+ .height = imHeight ,
6265 .format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 ,
6366 .mipmaps = 1
6467 };
0 commit comments