# Having a slow morning need HELP and coffee

## Recommended Posts

NovaBlack    166
Ok.. a part of my brain has collapsed overnight. Ive done this a MILLION times before but... If i have say an struct that contains an existing D3DCOLOR_RGBA, and i want to say leave the RGB components as they are and simply alter the existing alpha value to say a new value from a slider... how the HECK do i set that value..? ive probably got a typo or something lol but i cant seem to figure out how to leave the RGB untouched and just alter the alpha. yes.. a SLOW morning. i need to wake up.

##### Share on other sites
Drigovas    509
Well, according to this, the alpha value is the high order bits of the color DWORD, so:
alpha = (color >> 24)  & 0xFF
Really though, this is ugly, and should really be replaced by something a bit more straight forward that can be accessed per-part. Like, for example, a D3DXCOLOR structure, which is in fact 4 floats, or some sort of more friendly color representation that holds the channels separate.

##### Share on other sites
NovaBlack    166
yeah id LOVE to use something that forms a struct so the parts are easily accessible, but its part of a project i have to do for uni using existing code ...

ugh...

I have so far...

// Subtract Alpha decay value from existing stored value once per frame
// to slowly decrease it over time.

// Use mask and bitwise shift to insert new Alpha into right place in the
// D3DCOLOR Particles[particle].Colour.

Particles[particle].Colour = (Particles[particle].Colour & 0x00FFFFFF)
| ((BYTE)ParticleUpdates[particle].Alpha << 24);

//Kill if no longer visible

{
KillParticle(particle);
}

its doing... SOMETHING... but not working quite right... Pretty awkward to debug since this code is in a C++ DLL being used by a separate c# Particle System project

The value 'AlphaDecay' is read in from a slider in the c# particle system app

oh n im pretty sure the color is being stored as ARGB now. just to mess up what i was originally told of it being RGBA lol

##### Share on other sites
NovaBlack    166
AHH i think i fixed it... i completely forgot that the

was stored as a float in the range 0.0f to 1.0f

so i had to convert to 0.0f -> 255.0f so that it would be added properly !

thanks for your help though! (you were right with your shifting and the link helped!)

Ugh why doe tutors insist on making projects awkward like this!

##### Share on other sites
Drigovas    509
Also, for the future, implicit conversions are great for dealing with existing code like this.....

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account