Difference between revisions of "API-Truecolor"

Jump to navigation Jump to search
1,822 bytes added ,  07:14, 9 July 2009
Line 37: Line 37:
#*If the setup was not successful, and your engine cannot run in 256 colors, display an error and return.
#*If the setup was not successful, and your engine cannot run in 256 colors, display an error and return.
#*Otherwise, initialize your engine to use the pixel format that getScreenFormat returned, and run normally.
#*Otherwise, initialize your engine to use the pixel format that getScreenFormat returned, and run normally.
==== Example ====
Here is an example of a simple engine that uses the best color depth available to display an RGB color-cycling gradient.
<syntax type="C++">
Common::Error QuuxEngine::run() {
Graphics::PixelFormat format = _system->getSupportedFormats().front();
initGraphics(640, 480, true, &format);
format = _system->getScreenFormat();
byte *offscreenBuffer = (byte *)malloc(640 * 480 * format.bytesPerPixel);
if (format.bytesPerPixel == 1) {
// Initialize palette to simulate RGB332
byte palette[1024];
memset(&palette,0,1024);
byte *dst = palette;
for (byte r = 0; r < 8; r++) {
for (byte g = 0; g < 8; g++) {
for (byte b = 0; b < 4; b++) {
dst[0] = r << 5;
dst[1] = g << 5;
dst[2] = b << 6;
dst[3] = 0;
dst += 4;
}
}
}
_system->setPalette(palette,0,256);
}
uint32 t = 0;
uint32 mask = (1 << (format.bytesPerPixel << 3)) - 1;
while (!shouldQuit()) {
for (int16 y = 0; y < 480; y++) {
uint8 *dst = offscreenBuffer + (y * 640 * format.bytesPerPixel);
for (int16 x = 0; x < 640; x++) {
uint32 color = (x * y) & mask;
t &= (format.bytesPerPixel << 3) - 1;
color = (color << t) | (color >> ((format.bytesPerPixel << 3) - t));
#ifdef SCUMM_BIG_ENDIAN
for (int i = 0; i < format.bytesPerPixel; i++)
{
dst[format.bytesPerPixel - i] = color & 0xFF;
color >>= 8;
}
dst += format.bytesPerPixel;
#else
for (int i = format.bytesPerPixel; i > 0; i--) {
*dst++ = color & 0xFF;
color >>= 8;
}
#endif
}
}
Common::Rect r;
r.top = 0;
r.left = 0;
r.bottom = 479;
r.right = 639;
_system->copyRectToScreen(offscreenBuffer, 640 * format.bytesPerPixel, 0, 0, 640, 480);
_system->updateScreen();
parseEvents();
_system->delayMillis(66);
t++;
}
return Common::kNoError;
}
</syntax>


=== Backend initialization protocol ===
=== Backend initialization protocol ===
20

edits

Navigation menu