Skip to main content TerryFunggg Blog

Draw Vector

Define Color buffer

c code snippet start


uint32_t *color_buffer = (uint32_t*) malloc(sizeof(uint32_t) * window_width * window_height);

c code snippet end

Define 2D vector

c code snippet start

typedef struct {
  float x;
  float y;
} vec2_t;

c code snippet end

A function for draw pixel:

c code snippet start

void draw_pixel(int x, int y, uint32_t color) {
  if (x >= 0 && x < window_width && y >= 0 && y < window_height) {
    color_buffer[(window_width * y) + x] = color;
  }
}

c code snippet end