Draw Vector

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.

Define 2D vector

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

A function for draw pixel:

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;
  }  
}

I think this was really common to draw dot on the screen..so no case here :)

Resources: pikuma course

Date: 2023-12-25 Mon 00:00

Author: Terry Fung

Created: 2024-11-10 Sun 14:09

Emacs 29.4 (Org mode 9.6.15)

Validate