Indexed graphics for retro engine?
norm
norm.rowtree at gmail.com
Thu Sep 19 23:32:13 UTC 2019
On Thursday, 19 September 2019 at 20:47:45 UTC, Shadowblitz16
wrote:
> On Thursday, 19 September 2019 at 19:16:03 UTC, Mike Parker
> wrote:
>> On Thursday, 19 September 2019 at 18:25:05 UTC, Shadowblitz16
>> wrote:
>>
>>> I wanted to do 4bpp 16 color graphics.
>>> and I didn't want to load anything unnecessary in the image
>>> like the palette but instead supply it myself as a Color[16];
>>
>> I see. In that case, I suggest you find some tutorials on
>> software rendering in C or C++ and adapt them to D. Most of
>> the modern stuff out there is going to be targeting 24-bit or
>> 32-bit graphics. You might find some older tutorials on
>> indexed 8-bit rendering that you can adapt to 4-bit. Nothing
>> to it but storing the palette indices in a byte array.
>
> can I do this in D and draw them to a 32bpp bitmap pixel by
> pixel?
> I would prefer do do this on the gpu but I don't know how.
I'd create a fragment shader to convert each pixel to 8 bit.
There are many examples on the web about creating fragment
shaders and 2d opengl scenes, i.e. a 2d scene where OpenGL
coordinates are integer pixel coordinates. Once you get that you
then just implement the conversion routine.
Using the shader you can render the image as a textured quad and
send the colour look up table down as an additional 1d texture.
This way you can have several D arrays for each colour table and
simply swap the texture buffer pointer to instantly switch
colours.
You can also get cool effects this way when you move to 3d using
8 bit colour tables.
More information about the Digitalmars-d-learn
mailing list