/* * colour.cpp * * Created on: Dec 16, 2012 * Author: gregor */ #include "GLTB/colour.h" namespace gltb { #ifdef USE_GLM glm::vec4 webColour(const std::string &colour) { static std::string hex("0123456789abcdef"); glm::vec4 c; if((colour.length() == 6) || (colour.length() == 8)) { c.r = ((hex.find_first_of(colour.at(0)) << 4) + hex.find_first_of(colour.at(1))) / 255.0f; c.g = ((hex.find_first_of(colour.at(2)) << 4) + hex.find_first_of(colour.at(3))) / 255.0f; c.b = ((hex.find_first_of(colour.at(4)) << 4) + hex.find_first_of(colour.at(5))) / 255.0f; if(colour.length() == 8) c.a = ((hex.find_first_of(colour.at(6)) << 4) + hex.find_first_of(colour.at(7))) / 255.0f; else c.a = 1.0f; } else { c.r = 0; c.g = 0; c.b = 0; c.a = 0; } return c; } #endif }