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 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* libsegl - Sebas Extended GL Library
  2. * Collection of Opengl/3D-Math helpers
  3. *
  4. * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
  5. * http://www.seba-geek.de
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301, USA.
  21. */
  22. #include "color.h"
  23. namespace segl {
  24. Color::Color() {
  25. set(0.0f, 0.0f, 0.0f, 1.0f);
  26. setalpha = true;
  27. }
  28. Color::Color(float _r, float _g, float _b, float _a) {
  29. set(_r, _g, _b, _a);
  30. }
  31. Color::Color(const SDL_Color &c) {
  32. set(c.r/255.0f, c.g/255.0f, c.b/255.0f);
  33. setalpha = true;
  34. }
  35. void Color::set(float _r, float _g, float _b, float _a) {
  36. r = _r;
  37. g = _g;
  38. b = _b;
  39. a = _a;
  40. }
  41. SDL_Color Color::getSDLColor() {
  42. SDL_Color c = {(Uint8)(r*255.0f), (Uint8)(g*255.0f), (Uint8)(b*255.0f), (Uint8)(a*255.0f)};
  43. return c;
  44. }
  45. void Color::print(std::string m) {
  46. std::cout << m << " Color: " << r << ", " << g << ", " << b << std::endl;
  47. }
  48. } // namespace segl
  49. void glColorGLC(segl::Color c) {
  50. if(c.setalpha) {
  51. glColor4f(c.r, c.g, c.b, c.a);
  52. } else {
  53. glColor3f(c.r, c.g, c.b);
  54. }
  55. }