Open main menu

Difference between revisions of "API-Truecolor"

727 bytes added ,  08:50, 9 July 2009
→‎Example: a few more comments and a minor formatting correction
(→‎Example: a few more comments and a minor formatting correction)
Line 97: Line 97:
uint32 t = 0;
uint32 t = 0;
// Create a mask to limit the color from exceeding the bitdepth
// The result is equivalent to:
// uint32 mask = 0;
// for (int i = format.bytesPerPixel; i > 0; i--) {
// mask <<= 8;
// mask |= 0xFF;
// }
uint32 mask = (1 << (format.bytesPerPixel << 3)) - 1;
uint32 mask = (1 << (format.bytesPerPixel << 3)) - 1;
// Repeat this until the event manager tells us to stop
while (!shouldQuit()) {
while (!shouldQuit()) {
// Keep t from exceeding the number of bits in each pixel.
// I think this is faster than "t %= (format.bytesPerPixel * 8);" would be.
t &= (format.bytesPerPixel << 3) - 1;


// Draw the actual gradient
// Draw the actual gradient
Line 105: Line 119:
for (int16 x = 0; x < 640; x++) {
for (int16 x = 0; x < 640; x++) {
uint32 color = (x * y) & mask;
uint32 color = (x * y) & mask;
t &= (format.bytesPerPixel << 3) - 1;
color = (color << t) | (color >> ((format.bytesPerPixel << 3) - t));
color = (color << t) | (color >> ((format.bytesPerPixel << 3) - t));


Line 114: Line 127:


#ifdef SCUMM_BIG_ENDIAN
#ifdef SCUMM_BIG_ENDIAN
for (int i = 0; i < format.bytesPerPixel; i++)
for (int i = 0; i < format.bytesPerPixel; i++) {
{
dst[format.bytesPerPixel - i] = color & 0xFF;
dst[format.bytesPerPixel - i] = color & 0xFF;
color >>= 8;
color >>= 8;
Line 128: Line 140:
}
}
}
}
// Copy our gradient to the screen. The pitch of our image is the width * the number of bytes per pixel.
_system->copyRectToScreen(offscreenBuffer, 640 * format.bytesPerPixel, 0, 0, 640, 480);
_system->copyRectToScreen(offscreenBuffer, 640 * format.bytesPerPixel, 0, 0, 640, 480);
// Tell the system to update the screen.
_system->updateScreen();
_system->updateScreen();
// Get new events from the event manager so the window doesn't appear non-responsive.
parseEvents();
parseEvents();


// Wait a semi-arbitrary length in order to animate fluidly, but not insanely fast
// Wait a semi-arbitrary length in order to animate fluidly, but not insanely fast
_system->delayMillis(66);
_system->delayMillis(66);
// Increment our time variable, which doubles as our bit-shift counter.
t++;
t++;
}
}
20

edits