Jump to content
  • Advertisement
Sign in to follow this  

Having a slow morning need HELP and coffee

This topic is 3626 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post

Link to post
Share on other sites
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 this post

Link to post
Share on other sites
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 ...


I have so far...

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

ParticleUpdates[particle].Alpha -= AlphaDecay;

// 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

if(ParticleUpdates[particle].Alpha < 0.0f)

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 this post

Link to post
Share on other sites
AHH i think i fixed it... i completely forgot that the

'ParticleUpdates[particle].Alpha '

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 this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!