#Struct

43 messages · Page 1 of 1 (latest)

storm basin
#

Is there a better way to do this?

mild pasture
#

Just do a normal RGBA structure

#

and then add skycolor as member in the sky class

wary stratus
#

#define RGB2GL 1.0f / 255.0f

...

float r = 224.0f * RGB2GL;

leaden grotto
iron hazelBOT
#

@leaden grotto has reached level 3. GG!

storm basin
iron hazelBOT
#

@storm basin has reached level 14. GG!

leaden grotto
#

because you can't pass to any functions unless their type is Color_sky

#

it should be an instance of an rgb struct

storm basin
#

it works normally

leaden grotto
#

you aren't passing the whole struct in, just its individual fields

storm basin
#

yeah

leaden grotto
#

either way, that's a bad design imo

storm basin
#

can you send better code

#

im not a pro

#

so idk wym by "an instance of an rgb struct"

leaden grotto
#
struct rgb_t {
  float r, g, b, a;
};

// assuming this is at global scope
static rgb_t constexpr COLOR_SKY { .r = ..., .b = ..., .g = ..., .a = ...};
#

replace the ellipsis with the values you used above

#

like this, you can freely define other colors as well:

void whatever(){
  rgb_t const red { .r = 1.f, .b = 0.f, .g = 0.f, .a = 1.f };
  // blah blah blah
}
storm basin
#

alright thanks

#

didnt think of this

leaden grotto
#

btw im not sure this syntax will work

#

it is only supported by c++ since c++17 i think

storm basin
#

it works but without the rgba names

#

just nums

#

and no dots

#

so like cpp .......... COLOR_SKY {1, 2, 3, 4};

leaden grotto
#

which is funny because this is available in c99

wary stratus
thorny dust
#

to retrieve values simply do skyColor.x,y,z, or w

#

You already have a Vec4f object in the glm namespace

#

use it or make your own vec4f

leaden grotto
thorny dust
#

it's a preference

thorny dust
#

curious

leaden grotto
#

as long as all members are public

wary stratus