Small OpenGL based c++ rendering library
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.

color.cpp 783B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "color.h"
  2. namespace segl {
  3. Color::Color() {
  4. set(0.0f, 0.0f, 0.0f, 1.0f);
  5. setalpha = true;
  6. }
  7. Color::Color(float _r, float _g, float _b, float _a) {
  8. set(_r, _g, _b, _a);
  9. }
  10. Color::Color(const SDL_Color &c) {
  11. set(c.r/255.0f, c.g/255.0f, c.b/255.0f);
  12. setalpha = true;
  13. }
  14. void Color::set(float _r, float _g, float _b, float _a) {
  15. r = _r;
  16. g = _g;
  17. b = _b;
  18. a = _a;
  19. }
  20. SDL_Color Color::getSDLColor() {
  21. SDL_Color c = {(Uint8)(r*255.0f), (Uint8)(g*255.0f), (Uint8)(b*255.0f), (Uint8)(a*255.0f)};
  22. return c;
  23. }
  24. void Color::print(std::string m) {
  25. std::cout << m << " Color: " << r << ", " << g << ", " << b << std::endl;
  26. }
  27. } // namespace segl
  28. void glColorGLC(segl::Color c) {
  29. if(c.setalpha) {
  30. glColor4f(c.r, c.g, c.b, c.a);
  31. } else {
  32. glColor3f(c.r, c.g, c.b);
  33. }
  34. }