ex12bit(3alleg4)

πŸ’– ex12bit β€” bestie edition πŸ’–

ok so this is a page from the Allegro manual, and it's all about ex12bit(3alleg4) β€” a whole example program, in the Allegro game programming library. sit down, grab a strawberry drink πŸ“, we're doing fake truecolor today.


✨ NAME ✨

ex12bit β€” the way you fake a 12-bit truecolor mode on an 8-bit card. literally the glow-up of palettes. part of the Allegro game programming library. πŸ’…


🌈 SYNOPSIS 🌈

#include <allegro.h>

Example ex12bit

πŸ‘‘ DESCRIPTION πŸ‘‘

okok so here's the tea πŸ«–: this program sets up a 12-bit mode on any 8-bit card. how?? by building a 256-colour palette that lowkey gaslights the eye into grouping two 8-bit pixels into one 12-bit pixel. iconic behaviour honestly.

to pull this off, you make your 256-colour palette out of all the combinations of blue and green, where green ranges from 0-15 and blue ranges from 0-14. that eats up 16x15=240 colours. cute, right? that leaves 16 colours left over to use as red (red ranges from 0-15). then you put your green/blue in one pixel, and your red in the pixel right next to it. the eye gets fooled into thinking it's all one pixel. no cap, that's the whole scam 🧚

the example starts by setting a normal 256 color mode, and constructs a special palette for it. but then comes the trick πŸ‘€: you need to write to a set of two adjacent pixels to form a single 12 bit dot. two eight bit pixels is the same as one 16 bit pixel, so after setting the video mode you need to hack the screen bitmap about, halving the width and changing it to use the 16 bit drawing code. then, once you have packed a color into the correct format (using the makecol12() function below), any of the normal Allegro drawing functions can be used with this 12 bit display! obsessed. πŸ”₯

things to note πŸ“:

  • the horizontal width is halved, so you get resolutions like 320x480, 400x600, and 512x768.
  • because each dot is spread over two actual pixels, the display will be darker than in a normal video mode. πŸ₯²
  • any bitmap data will obviously need converting to the correct 12 bit format: regular 15 or 16 bit images won't display correctly...
  • although this works like a truecolor mode, it is actually using a 256 color palette, so palette fades are still possible! slay. ✨
🚨 bestie listen: this code only works in linear screen modes (don't try Mode-X). do not test it. i'm serious. πŸ™ˆ

πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, bestie!! this was Allegro version 4.4.3, ex12bit(3alleg4), and yes i read the entire thing so you don't have to. go build a fake truecolor mode, you got this. mwah πŸ’œπŸŽ€πŸ¦‹