color constants

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
CuteAlien
Admin
Posts: 10021
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

color constants

Post by CuteAlien »

Sometimes easier to use than those numbers:

Code: Select all

#ifndef COLOR_CONSTANTS_H
#define COLOR_CONSTANTS_H
 
#include <irrlicht.h>
 
const irr::video::SColor SCOL_BLACK     = irr::video::SColor(255, 0,   0,   0);
const irr::video::SColor SCOL_DARKBLUE  = irr::video::SColor(255, 0,   0,  139);
const irr::video::SColor SCOL_BLUE      = irr::video::SColor(255, 0,   0,  255);
const irr::video::SColor SCOL_CYAN      = irr::video::SColor(255, 0,  255, 255);
const irr::video::SColor SCOL_DARKGRAY  = irr::video::SColor(255, 64,  64, 64);
const irr::video::SColor SCOL_GRAY      = irr::video::SColor(255, 128,128, 128);
const irr::video::SColor SCOL_DARKGREEN = irr::video::SColor(255, 0,  100,  0);
const irr::video::SColor SCOL_GREEN     = irr::video::SColor(255, 0,  255,  0);
const irr::video::SColor SCOL_LIGHTGRAY = irr::video::SColor(255, 192, 192,192 );
const irr::video::SColor SCOL_MAGENTA   = irr::video::SColor(255, 255, 0,  255);
const irr::video::SColor SCOL_ORANGE    = irr::video::SColor(255, 255, 192,128);
const irr::video::SColor SCOL_PINK      = irr::video::SColor(255, 255, 176,176);
const irr::video::SColor SCOL_DARKRED   = irr::video::SColor(255, 139, 0,   0);
const irr::video::SColor SCOL_RED       = irr::video::SColor(255, 255, 0,   0);
const irr::video::SColor SCOL_YELLOW    = irr::video::SColor(255, 255, 255, 0);
const irr::video::SColor SCOL_WHITE     = irr::video::SColor(255, 255, 255, 255);
const irr::video::SColor SCOL_BROWN     = irr::video::SColor(255, 165, 42, 42);
const irr::video::SColor SCOL_GOLD      = irr::video::SColor(255, 255, 215, 0);
 
#endif // COLOR_CONSTANTS_H
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Yes, very cool CuteAlien. I agree that they are much easier to use, and believe that these (and some more) should be added into the engine.

I also use vector, and other constants, pretty much anywhere that I can to make things easier, and more readable.
TheQuestion = 2B || !2B
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Yeah vector definition like

Code: Select all

#define IDENTITY_V vector3df(1,1,1);
would be useful so you can just scale nodes like

Code: Select all

node->setScale(IDENTITY_V * 3.0f);
but offcourse that getting a bit pedantic.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The macro wastes cycles creating temporaries. Often they can be optimized out, but that isn't guaranteed.

Using constants like shown previously avoids this problem, though it does have the disadvantage that the values can't reliably be used until after dynamic initialization has completed. That is usually okay because most user code doesn't do anything anything before main() starts.

Travis
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Yeah, it would also be beneficial to have UNIT_X, UNIT_Y, and UNIT_Z, etc. I am not saying add this super l33t code right now, but, more or less, just telling what I am using.
TheQuestion = 2B || !2B
Post Reply