Hello,
I'm trying to make a Gradient Fill of a rectangle, I looked in the documentation, and understand how it's done, but I can't convert my values to get my desired results.
Here is the source on MSDN of how to do this.
// Create an array of TRIVERTEX structures that describe
// positional and color values for each vertex. For a rectangle,
// only two vertices need to be defined: upper-left and lower-right.
TRIVERTEX vertex[2] ;
vertex[0].x = 0;
vertex[0].y = 0;
vertex[0].Red = 0x0000;
vertex[0].Green = 0x8000;
vertex[0].Blue = 0x8000;
vertex[0].Alpha = 0x0000;
vertex[1].x = 300;
vertex[1].y = 80;
vertex[1].Red = 0x0000;
vertex[1].Green = 0xd000;
vertex[1].Blue = 0xd000;
vertex[1].Alpha = 0x0000;
// Create a GRADIENT_RECT structure that
// references the TRIVERTEX vertices.
GRADIENT_RECT gRect;
gRect.UpperLeft = 0;
gRect.LowerRight = 1;
// Draw a shaded rectangle.
GradientFill(hdc, vertex, 2, &gRect, 1, GRADIENT_FILL_RECT_H);
I'm wondering why I have to use hex (i think that's what it is) in the TRIVERTEX.Alpha, TRIVERTEX.Red, TRIVERTEX.Green, and TRIVERTEX.Blue fields?
I looked up the TRIVERTEX structure, and it turns out they are COLOR16 variables, which are actually unsigned shorts. So my question is why can't i use regular numbers to give them their value. Like this
//for the color white
vertex[0].Alpha = 255;
vertex[0].Red = 255;
vertex[0].Green = 255;
vertex[0].Blue = 255;
yeah sure it compiles fine, but it doesn't work as intended.
Quote:
The color information of each channel is specified as a value from 0x0000 to 0xff00
I don't really understand how those values represent colors.
0 to 65280 in decimal...so to convert to the 0-255 system i'm used to
COLOR16 theirValue = 65280/255 * myValue;
That's really not how i'm expected to do it is it? Should I be reading up on bits and bytes and how they're stored (I think there's some kind of shift or something)
Thanks,
ArchG