You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.7 KiB

5 years ago
  1. #pragma once
  2. #include "CELLMath.hpp"
  3. namespace CELL
  4. {
  5. enum DRAWMODE
  6. {
  7. DM_POINTS = 0,
  8. DM_LINES = 1,
  9. DM_LINE_LOOP = 2,
  10. DM_LINE_STRIP = 3,
  11. };
  12. class Raster
  13. {
  14. public:
  15. Rgba* _buffer;
  16. int _width;
  17. int _height;
  18. Rgba _color;
  19. public:
  20. Raster(int w,int h,void* buffer);
  21. ~Raster(void);
  22. void clear();
  23. void drawPoint(int x,int y, Rgba color,int ptSize);
  24. void drawArrays(DRAWMODE mode,const float2* points,int count);
  25. void drawFilleRect(int startX,int startY,int w,int h);
  26. void drawRect(const int2* points,const Rgba* colors);
  27. public:
  28. void drawLine(int startX,int endX, int y,Rgba color1,Rgba color2)
  29. {
  30. float length = tmax<int>(endX - startX,1);
  31. for (int x = startX ; x <= endX ; ++ x)
  32. {
  33. Rgba color = colorLerp(color1,color2,( x - startX)/length);
  34. setPixel(x,y,color);
  35. }
  36. }
  37. void drawLine(float2 pt1,float2 pt2,Rgba color1,Rgba color2);
  38. void drawPoints(float2 pt1,Rgba4Byte color)
  39. {
  40. }
  41. inline void setPixelEx(unsigned x,unsigned y,Rgba color)
  42. {
  43. _buffer[y * _width + x] = color;
  44. }
  45. inline void setPixel(unsigned x,unsigned y,Rgba color)
  46. {
  47. if (x >= _width || y >= _height)
  48. {
  49. return;
  50. }
  51. _buffer[y * _width + x] = color;
  52. }
  53. };
  54. }