Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

dos-like

Engine for making things with a MS-DOS feel, but for modern platforms · By Mattias Gustavsson

How the color and palette system works?

A topic by Vitor Almeida created 13 days ago Views: 28 Replies: 5
Viewing posts 1 to 4

Hey everyone!

I'm having trouble understanding how the color and palette system works in the library.

Currently, I'm drawing a simple Pong game (using white for the elements and other simple drawing functions like line and rectangle).

However, I've created a simple palette with some shades of green that I want to use to simulate a color decay effect using the framebuffer.

My problem is that I can't change (and especially compare) the colors in the drawn framebuffer to know which color I need to "decay".

I don't understand the combined concept of being able to change the framebuffer and the color palette.

Could you please help me?
Thanks.

One question: for example, the code "getpixel(x, y)" returns a color or an index from the palette? If it's a color, this color can be different from the defined/default palette?

I think I understood: the library only works in terms of a palette index: it means that when I use putpixel, getpixel (or setcolor) they will work with an index that will use the color  (rgb) specified in the setpal function.

Developer

Yeah, each pixel in the frame buffer is an index into the palette, a pixel can only have values between 0 and 255. the palette can have 256 entries, and pixels are displayed using the rgb value at that index in the palette. if you change, for example, the palette entry 3, it will affect ALL pixels in the frame buffer that points to that index (all pixels that have value 3)

Thank you very much, Mattias.

Thanks to your explanation about colors, I was able to understand and implement some more effects (scanlines and green phosphor effect) in my pong game.

Developer

Nice, that looks great :)