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

Date: 2023-12-24 Sun 00:00

Author: Terry Fung

Created: 2024-11-10 Sun 14:09

Emacs 29.4 (Org mode 9.6.15)

Validate