How to draw sprites using a palette in GM Studio:
...I just found it too =/. Well, if you ever move to studio, heres some important code:
Notes:
"uniform sampler2D Palette" refer to a sampler texture that is an externally loaded sprites since GM will auto batch sprites into a "Texture Page". When that happens, GM will change the UV coords to something unexpected. But, I need to know the exact UV coords of the palette image, so instead I externally load them to reserve the original UV coords.
The drawn sprite (gm_BaseTexture) is an indexed sprite, where each pixel's color.r (indexPixel.x) refers to the x coordinate of the correct color within the palette (domain [0,255]) and color.g (indexPixel.y) refers to the y coordinate of the correct color within the palette (domain [0,255]).
___
I'm just typing this up for other people and for my own reference. If you ever move to GM Studio or any other graphics library (OpenGL, Direct X), you can still refer to the above to draw sprites with arbitrary palettes.
...I just found it too =/. Well, if you ever move to studio, heres some important code:
Notes:
"uniform sampler2D Palette" refer to a sampler texture that is an externally loaded sprites since GM will auto batch sprites into a "Texture Page". When that happens, GM will change the UV coords to something unexpected. But, I need to know the exact UV coords of the palette image, so instead I externally load them to reserve the original UV coords.
The drawn sprite (gm_BaseTexture) is an indexed sprite, where each pixel's color.r (indexPixel.x) refers to the x coordinate of the correct color within the palette (domain [0,255]) and color.g (indexPixel.y) refers to the y coordinate of the correct color within the palette (domain [0,255]).
___
I'm just typing this up for other people and for my own reference. If you ever move to GM Studio or any other graphics library (OpenGL, Direct X), you can still refer to the above to draw sprites with arbitrary palettes.