Advertisement
keybode

source engine gradient using ISurface

Feb 11th, 2015
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. void Renderer::DrawRectGradV(int x, int y, int w, int h, Color from, Color to) {
  2.     float r = (to.R() - from.R()) / h;
  3.     float g = (to.G() - from.G()) / h;
  4.     float b = (to.B() - from.B()) / h;
  5.     float a = (to.A() - from.A()) / h;
  6.  
  7.     for (int i = 0; i < h; i++) {
  8.         int R = from.R() + r * i;
  9.         int G = from.G() + g * i;
  10.         int B = from.B() + b * i;
  11.         int A = from.A() + a * i;
  12.  
  13.         DrawRect(x, y + i, w, 1, Color(R, G, B, A));
  14.     }
  15. }
  16.  
  17. void Renderer::DrawRectGradH(int x, int y, int w, int h, Color from, Color to) {
  18.     float r = (to.R() - from.R()) / w;
  19.     float g = (to.G() - from.G()) / w;
  20.     float b = (to.B() - from.B()) / w;
  21.     float a = (to.A() - from.A()) / w;
  22.  
  23.     for (int i = 0; i < h; i++) {
  24.         int R = from.R() + r * i;
  25.         int G = from.G() + g * i;
  26.         int B = from.B() + b * i;
  27.         int A = from.A() + a * i;
  28.  
  29.         DrawRect(x + i, y, 1, h, Color(R, G, B, A));
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement