in Education by
Ok. I'm working with the FW1FontWrapper code for use with DirectX : https://archive.codeplex.com/?p=fw1 This has removed my need to use an outdated and useless font engine powered by textures. However, the DrawString function within this Wrapper has a peculiar requirement for a Colour representation. UINT32 Color : In the format 0xAaBbGgRr The data I am given for this task is a constant Alpha value: 1.0f. And 3 variable float values for R, G and B ranging from 0.0f to 1.0f. Given the peculiar arrangement of colours within the UNIT32, I'm attempting to write a function that will create this UNIT32 using the 3 float values I am given. My Attempt UINT32 TextClassA::getColour(SentenceType* sentence) { //Convert each float value to its percentage of 255 int colorb = 255 * sentence->blue; int colorg = 255 * sentence->green; int colorr = 255 * sentence->red; //convert each int to 8 bit Hex UINT8 ucolorb = colorb; UINT8 ucolorg = colorg; UINT8 ucolorr = colorr; //Push each hex back onto a UNIT32 UINT32 color = 0xFF + (ucolorb << 6) + (ucolorg << 4) + (ucolorr << 2); return color; } SentenceType red, green and blue are simply floats for each value of RGB from 0.0-1.0f My Idea. Was roughly that I could: convert each float value to its percentage of 255 (not too worried about perfect accuracy. Convert those integer values to UINT8s Then push those back onto a UINT32 JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The implementation can be made clearer by avoiding all the temporary variables and using something like the code below. That said, any reasonable optimizing compiler should generate the same code in both cases. UINT32 TextClassA::getColour(SentenceType* sentence) { //Convert color components to value between 0 and 255. UINT32 r = 255 * sentence->red; UINT32 b = 255 * sentence->blue; UINT32 g = 255 * sentence->green; //Combine the color components in a single value of the form 0xAaBbGgRr return 0xFF000000 | r | (b << 16) | (g << 8); }

Related questions

0 votes
    Ok. I'm working with the FW1FontWrapper code for use with DirectX : https://archive.codeplex.com/?p=fw1 This has removed ... hex back onto a UNIT32 UINT32 color = 0xFF + (ucolorb...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Ok. I'm working with the FW1FontWrapper code for use with DirectX : https://archive.codeplex.com/?p=fw1 This has removed ... hex back onto a UNIT32 UINT32 color = 0xFF + (ucolorb...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I've seen examples that allow you to create a manipulator that inserts delimiters but none of those manipulators are sticky. That is, ... . I want to be able to do this: std::cout...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    _____________ will produce a sequential vector c( (1,2,3,4,5,6,7,8,9)). (a) Seq(9) (b) Seq ... Functions and Debugging of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Two vectors M and N are defined as M...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Our core application changed from Python 2.6 to Python 2.7 maybe to Python 3 in later release. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I have a QGraphicsItem element (subclassesed from QGraphicsItem) that has as child a QGraphicsTextItem. The problem ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    The code below copies data from one vector into another. If the vectors are large then I guess this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    The code below copies data from one vector into another. If the vectors are large then I guess this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    A couple months ago I did a project in C++ with Visual Studio that I needed pthreads for, so I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Is there a way to utilise the GCC compiler whilst still being able to develop via the Visual Studio IDE ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 30, 2022 in Education by JackTerrance
0 votes
    Is there a way to utilise the GCC compiler whilst still being able to develop via the Visual Studio IDE ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    Is there a way to utilise the GCC compiler whilst still being able to develop via the Visual Studio IDE ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    I'd like to ensure my RAII class is always allocated on the stack. How do I prevent a class from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I'd like to ensure my RAII class is always allocated on the stack. How do I prevent a class from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
...