ex12bit(3)
β¨ NAME β¨
ex12bit β the little legend that shows you how to fake a 12-bit truecolor mode on an 8-bit card π¨β¨
It's part of the Allegro game programming library, bestie. iykyk.
πΈ SYNOPSIS πΈ
#include <allegro.h>
Example ex12bit
π DESCRIPTION π
Okay so boom: this program sets up a 12-bit mode on any 8-bit card. The trick? You build a 256-colour palette that literally gaslights the human eye into grouping two 8-bit pixels into one 12-bit pixel. it's giving optical illusion, it's giving main character energy. π§
Here's the recipe, no cap:
- You make your 256-colour palette out of all the combos of blue and green, where green ranges from
0-15and blue ranges from0-14. - That eats up
16x15=240colours. slay, math. - Which leaves you 16 colours 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. π«Ά iconic behaviour tbh.
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. And here's the galaxy-brain part β 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! π
π Things to note π
- The horizontal width is halved, so you get resolutions like
320x480,400x600, and512x768. - 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! π
- This code only works in linear screen modes (don't try Mode-X). fr fr, don't.
π₯ SEE ALSO π₯
BITMAP(3)END_OF_MAIN(3)MATRIX(3)PALETTE(3)RGB(3)allegro_error(3)allegro_init(3)allegro_message(3)apply_matrix(3)blit(3)circle(3)clear_bitmap(3)clear_keybuf(3)clear_to_color(3)create_bitmap(3)create_bitmap_ex(3)destroy_bitmap(3)ellipsefill(3)fade_out(3)fixcos(3)fixed(3)fixsin(3)fixtoi(3)font(3)get_rotation_matrix(3)getpixel(3)install_keyboard(3)itofix(3)keypressed(3)line(3)makecol(3)masked_blit(3)putpixel(3)rest(3)screen(3)set_clip_rect(3)set_color(3)set_gfx_mode(3)set_palette(3)text_height(3)text_length(3)textout_ex(3)textprintf_ex(3)
okay that's the whole page, go forth and render ur 12-bit dreams on ur crusty 8-bit card, bestie π
Allegro β version 4.4.3 β ex12bit(3) π¦β¨ bye ily, go code something cute πβ
π¦ where this page comes from
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms