00001 //=========================================================================== 00002 /* 00003 This file is part of the CHAI 3D visualization and haptics libraries. 00004 Copyright (C) 2003-2009 by CHAI 3D. All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License("GPL") version 2 00008 as published by the Free Software Foundation. 00009 00010 For using the CHAI 3D libraries with software that can not be combined 00011 with the GNU GPL, and for taking advantage of the additional benefits 00012 of our support services, please contact CHAI 3D about acquiring a 00013 Professional Edition License. 00014 00015 \author <http://www.chai3d.org> 00016 \author Francois Conti 00017 \author Dan Morris 00018 \version 2.0.0 $Rev: 253 $ 00019 */ 00020 //=========================================================================== 00021 00022 //--------------------------------------------------------------------------- 00023 #ifndef CColorH 00024 #define CColorH 00025 //--------------------------------------------------------------------------- 00026 #include "extras/CGlobals.h" 00027 #include "math/CMaths.h" 00028 //--------------------------------------------------------------------------- 00029 struct cColorb; 00030 struct cColorf; 00031 //--------------------------------------------------------------------------- 00032 00033 //=========================================================================== 00041 //=========================================================================== 00042 00043 //=========================================================================== 00051 //=========================================================================== 00052 struct cColorf 00053 { 00054 public: 00055 00056 //----------------------------------------------------------------------- 00057 // CONSTRUCTOR & DESTRUCTOR: 00058 //----------------------------------------------------------------------- 00059 00060 //----------------------------------------------------------------------- 00064 //----------------------------------------------------------------------- 00065 cColorf() 00066 { 00067 // initialize color components R,G,B,A 00068 m_color[0] = 1.0; 00069 m_color[1] = 1.0; 00070 m_color[2] = 1.0; 00071 m_color[3] = 1.0; 00072 } 00073 00074 00075 //----------------------------------------------------------------------- 00085 //----------------------------------------------------------------------- 00086 cColorf(const GLfloat a_red, const GLfloat a_green, const GLfloat a_blue, 00087 const GLfloat a_alpha = 1.0) 00088 { 00089 m_color[0] = cClamp( a_red, 0.0f, 1.0f); 00090 m_color[1] = cClamp( a_green, 0.0f, 1.0f); 00091 m_color[2] = cClamp( a_blue, 0.0f, 1.0f); 00092 m_color[3] = cClamp( a_alpha, 0.0f, 1.0f); 00093 }; 00094 00095 00096 //----------------------------------------------------------------------- 00100 //----------------------------------------------------------------------- 00101 ~cColorf() {}; 00102 00103 00104 //----------------------------------------------------------------------- 00105 // METHODS: 00106 //----------------------------------------------------------------------- 00107 00108 //----------------------------------------------------------------------- 00117 //----------------------------------------------------------------------- 00118 inline void set(const GLfloat a_red, const GLfloat a_green, const GLfloat a_blue, 00119 const GLfloat a_alpha = 1.0) 00120 { 00121 m_color[0] = cClamp( a_red, 0.0f, 1.0f); 00122 m_color[1] = cClamp( a_green, 0.0f, 1.0f); 00123 m_color[2] = cClamp( a_blue, 0.0f, 1.0f); 00124 m_color[3] = cClamp( a_alpha, 0.0f, 1.0f); 00125 }; 00126 00127 00128 //----------------------------------------------------------------------- 00135 //----------------------------------------------------------------------- 00136 inline void setMem3(const GLfloat* a_colorRGB) 00137 { 00138 m_color[0] = a_colorRGB[0]; 00139 m_color[1] = a_colorRGB[1]; 00140 m_color[2] = a_colorRGB[2]; 00141 m_color[3] = 1.0; 00142 } 00143 00144 00145 //----------------------------------------------------------------------- 00152 //----------------------------------------------------------------------- 00153 inline void setMem4(const GLfloat* a_colorRGBA) 00154 { 00155 m_color[0] = a_colorRGBA[0]; 00156 m_color[1] = a_colorRGBA[1]; 00157 m_color[2] = a_colorRGBA[2]; 00158 m_color[3] = a_colorRGBA[3]; 00159 } 00160 00161 00162 //----------------------------------------------------------------------- 00168 //----------------------------------------------------------------------- 00169 inline GLfloat operator[](const unsigned int n) const 00170 { 00171 if (n<4) return m_color[n]; 00172 else return 0.0f; 00173 } 00174 00175 00176 //----------------------------------------------------------------------- 00182 //----------------------------------------------------------------------- 00183 inline GLfloat& operator[](const unsigned int n) 00184 { 00185 if (n<4) return m_color[n]; 00186 else return m_color[0]; 00187 } 00188 00189 00190 //----------------------------------------------------------------------- 00196 //----------------------------------------------------------------------- 00197 inline void setR(const GLfloat a_red) 00198 { 00199 m_color[0] = cClamp( a_red, 0.0f, 1.0f); 00200 } 00201 00202 00203 //----------------------------------------------------------------------- 00207 //----------------------------------------------------------------------- 00208 inline GLfloat getR() const 00209 { 00210 return(m_color[0]); 00211 } 00212 00213 00214 //----------------------------------------------------------------------- 00220 //----------------------------------------------------------------------- 00221 inline void setG(const GLfloat a_green) 00222 { 00223 m_color[1] = cClamp( a_green, 0.0f, 1.0f); 00224 } 00225 00226 00227 //----------------------------------------------------------------------- 00231 //----------------------------------------------------------------------- 00232 inline GLfloat getG() const 00233 { 00234 return(m_color[1]); 00235 } 00236 00237 00238 //----------------------------------------------------------------------- 00244 //----------------------------------------------------------------------- 00245 inline void setB(const GLfloat a_blue) 00246 { 00247 m_color[2] = cClamp( a_blue, 0.0f, 1.0f); 00248 } 00249 00250 00251 //----------------------------------------------------------------------- 00255 //----------------------------------------------------------------------- 00256 inline GLfloat getB() const 00257 { 00258 return(m_color[2]); 00259 } 00260 00261 00262 //----------------------------------------------------------------------- 00268 //----------------------------------------------------------------------- 00269 inline void setA(const GLfloat a_alpha) 00270 { 00271 m_color[3] = cClamp( a_alpha, 0.0f, 1.0f); 00272 } 00273 00274 00275 //----------------------------------------------------------------------- 00279 //----------------------------------------------------------------------- 00280 inline GLfloat getA() const 00281 { 00282 return(m_color[3]); 00283 } 00284 00285 00286 //----------------------------------------------------------------------- 00292 //----------------------------------------------------------------------- 00293 inline void render() const 00294 { 00295 glColor4fv(&m_color[0]); 00296 }; 00297 00298 00299 //----------------------------------------------------------------------- 00303 //----------------------------------------------------------------------- 00304 inline const GLfloat* pColor() const 00305 { 00306 return (&m_color[0]); 00307 } 00308 00309 00310 //----------------------------------------------------------------------- 00314 //----------------------------------------------------------------------- 00315 cColorb getColorb() const; 00316 00317 public: 00318 00319 //----------------------------------------------------------------------- 00320 // MEMBERS: 00321 //----------------------------------------------------------------------- 00322 00324 GLfloat m_color[4]; 00325 }; 00326 00327 00328 //=========================================================================== 00336 //=========================================================================== 00337 struct cColorb 00338 { 00339 public: 00340 00341 //----------------------------------------------------------------------- 00342 // CONSTRUCTOR & DESTRUCTOR: 00343 //----------------------------------------------------------------------- 00344 00345 //----------------------------------------------------------------------- 00349 //----------------------------------------------------------------------- 00350 cColorb() 00351 { 00352 // initialize color components R,G,B,A 00353 m_color[0] = 0xff; 00354 m_color[1] = 0xff; 00355 m_color[2] = 0xff; 00356 m_color[3] = 0xff; 00357 } 00358 00359 00360 //----------------------------------------------------------------------- 00370 //----------------------------------------------------------------------- 00371 cColorb(const GLubyte a_red, const GLubyte a_green, const GLubyte a_blue, 00372 const GLubyte a_alpha = 0xff) 00373 { 00374 m_color[0] = a_red; 00375 m_color[1] = a_green; 00376 m_color[2] = a_blue; 00377 m_color[3] = a_alpha; 00378 }; 00379 00380 00381 //----------------------------------------------------------------------- 00385 //----------------------------------------------------------------------- 00386 ~cColorb() {}; 00387 00388 00389 //----------------------------------------------------------------------- 00390 // METHODS: 00391 //----------------------------------------------------------------------- 00392 00393 //----------------------------------------------------------------------- 00402 //----------------------------------------------------------------------- 00403 inline void set(const GLubyte a_red, const GLubyte a_green, const GLubyte a_blue, 00404 const GLubyte a_alpha = 0xff) 00405 { 00406 m_color[0] = a_red; 00407 m_color[1] = a_green; 00408 m_color[2] = a_blue; 00409 m_color[3] = a_alpha; 00410 }; 00411 00412 00413 //----------------------------------------------------------------------- 00420 //----------------------------------------------------------------------- 00421 inline void setMem3(const GLubyte* a_colorRGB) 00422 { 00423 m_color[0] = a_colorRGB[0]; 00424 m_color[1] = a_colorRGB[1]; 00425 m_color[2] = a_colorRGB[2]; 00426 m_color[3] = 0xff; 00427 } 00428 00429 00430 //----------------------------------------------------------------------- 00437 //----------------------------------------------------------------------- 00438 inline void setMem4(const GLubyte* a_colorRGBA) 00439 { 00440 m_color[0] = a_colorRGBA[0]; 00441 m_color[1] = a_colorRGBA[1]; 00442 m_color[2] = a_colorRGBA[2]; 00443 m_color[3] = a_colorRGBA[3]; 00444 } 00445 00446 00447 //----------------------------------------------------------------------- 00453 //----------------------------------------------------------------------- 00454 inline void setR(const GLubyte a_red) 00455 { 00456 m_color[0] = a_red; 00457 } 00458 00459 00460 //----------------------------------------------------------------------- 00464 //----------------------------------------------------------------------- 00465 inline GLfloat getR() const 00466 { 00467 return(m_color[0]); 00468 } 00469 00470 00471 //----------------------------------------------------------------------- 00477 //----------------------------------------------------------------------- 00478 inline void setG(const GLubyte a_green) 00479 { 00480 m_color[1] = a_green; 00481 } 00482 00483 00484 //----------------------------------------------------------------------- 00488 //----------------------------------------------------------------------- 00489 inline GLfloat getG() const 00490 { 00491 return(m_color[1]); 00492 } 00493 00494 00495 //----------------------------------------------------------------------- 00501 //----------------------------------------------------------------------- 00502 inline void setB(const GLubyte a_blue) 00503 { 00504 m_color[2] = a_blue; 00505 } 00506 00507 00508 //----------------------------------------------------------------------- 00512 //----------------------------------------------------------------------- 00513 inline GLfloat getB() const 00514 { 00515 return(m_color[2]); 00516 } 00517 00518 00519 //----------------------------------------------------------------------- 00525 //----------------------------------------------------------------------- 00526 inline void setA(const GLubyte a_alpha) 00527 { 00528 m_color[3] = a_alpha; 00529 } 00530 00531 00532 //----------------------------------------------------------------------- 00536 //----------------------------------------------------------------------- 00537 inline GLfloat getA() const 00538 { 00539 return(m_color[3]); 00540 } 00541 00542 00543 //----------------------------------------------------------------------- 00548 //----------------------------------------------------------------------- 00549 inline void render() const 00550 { 00551 glColor4bv((const signed char*)(&m_color[0])); 00552 }; 00553 00554 00555 //----------------------------------------------------------------------- 00561 //----------------------------------------------------------------------- 00562 inline const GLubyte* pColor() const 00563 { 00564 return (&m_color[0]); 00565 } 00566 00567 00568 //----------------------------------------------------------------------- 00572 //----------------------------------------------------------------------- 00573 cColorf getColorf() const; 00574 00575 00576 public: 00577 00578 //----------------------------------------------------------------------- 00579 // MEMBERS: 00580 //----------------------------------------------------------------------- 00581 00583 GLubyte m_color[4]; 00584 }; 00585 00586 00587 //--------------------------------------------------------------------------- 00588 // GENERAL CONSTANTS 00589 //--------------------------------------------------------------------------- 00590 00592 extern cColorf CHAI_COLOR_RED; 00593 00595 extern cColorf CHAI_COLOR_GREEN; 00596 00598 extern cColorf CHAI_COLOR_BLUE; 00599 00601 extern cColorf CHAI_COLOR_YELLOW; 00602 00604 extern cColorf CHAI_COLOR_CYAN; 00605 00607 extern cColorf CHAI_COLOR_MAGENTA; 00608 00610 extern cColorf CHAI_COLOR_BLACK; 00611 00613 extern cColorf CHAI_COLOR_WHITE; 00614 00615 00616 //--------------------------------------------------------------------------- 00617 #endif 00618 //--------------------------------------------------------------------------- 00619