Draw grid
Define Color buffer
uint32_t *color_buffer = (uint32_t*) malloc(sizeof(uint32_t) * window_width * window_height);
In my case, window size set as 800 x 600. Define an uint32t represent as 4 bytes * 800 * 600 size buffer array.
draw 10 X 10 grid in SDL
void draw_grid(void) { for(int y = 0; y < window_height; y += 10) { for(int x = 0; x < window_width; x ++) { color_buffer[(window_width * y) + x ] = 0xFFFFFFFF; } } for(int x = 0; x < window_width; x += 10) { for(int y = 0; y < window_height; y ++) { color_buffer[(window_width * y) + x ] = 0xFFFFFFFF; } } }
Result:
Resources: pikuma course