top of page

Lesson #6: Colored Lines and Vector Functions

  • chrisbentley349
  • Nov 3, 2024
  • 1 min read

Updated: Dec 7, 2024



ree

Notes:





Code:




Hints:


Step #1: Adding per-pixel color


The only difference is the additional arguments for red, green, blue:

ree

Now we set color for every pixel we draw:

ree

Now we have to also swap colors and calculate color slopes:

ree

Step #2: Adding class/struct to encapsulate variables:


Add SWAP_POINT() function:

ree

Add class to hold pos[] and color[] data for POINT:

ree

Rewrite draw_line() function to use POINT class:

ree


Step #3: Use "vector" instructions to make code more compact:


Add "vector" functions:

ree

Rewrite draw_line() function using "vector" routines:

ree


Step #4: combining cases to make code shorter:

ree

Exercises:


write draw_quad() function to draw rectangle using POINTs:

ree

Write function to draw one quad:




Write function to draw many quads:




Comments


bottom of page