Colours Splitting?

BlitzMax Forums/BlitzMax Beginners Area/Colours Splitting?

Hotshot2005(Posted 2014) [#1]
I have done Colours Splitting Bars(Just like Amiga Background) and what I would like to know is How do I get Rainbow colours on to the fonts?


Calibrator(Posted 2014) [#2]
AFAIK there is a fundamental difference in programming because of the different hardware involved (and not because BMax isn't able to):

On the Amiga the rainbow fonts were made by changing the contents of the color palette registers on the fly (while the electron beam flies back to the beginning of the next line - think cathode tube monitor!).
This means that the pixel data in the frame buffer is an index into a palette but not the color data itself (RGB shades). In the palette (color) register you then have values that define the color.
This was easily possible because the Amiga (like other computers of the time) used a palette-based graphics mode and had sophisticated custom chips, hardware interrupts, display lists etc. to control those registers.
The Amiga, to be specific, used a custom chip called "Copper" hence those multicolored bars were called "Copper Bars" and the color change was programmable as scanline interrupts were available. The Amiga was even able to change the graphics mode at a specific scanline with this, for instance.

Nowadays, with graphics processors way speedier than what was used in the Amiga and much more memory for the frame buffer etc. there are less necessary compromises. Nowadays you simply activate a resolution of 1920x1080 (for example) with 32-bit colors (=24 color bits + 8 alpha channel bits). Done.

The only problem is: When you want to change the colors you have to change the actual data in the frame buffer because this data doesn't point to a palette anymore (at least any mode with 16 or more bits per pixel) but *is* the actual color data.
This is especially true if you don't use a "custom" full-screen graphics mode but draw your graphics in a window on your desktop.
"Older" graphics modes with only 8 bits per pixel may still support palette registers but you still would need scanline interrupts and AFAIK those don't exist on PC and Mac graphic cards (modern or old).

The answer to your question therefore is:
You probably have to design custom multicolored fonts or create them on the fly (which would be a bit more difficult).

I have no demo code for that but I'm relatively sure that I have seen stuff like that here somewhere. Perhaps somebody more active here can point you to it?


jkrankie(Posted 2014) [#3]
You can do it, but you'd need to write your own bitmap font routines as you'd need access to the vertex colour data you send to the GPU.

Basically, you'd create the vertices for the quad/triangles that you're going to apply your letter texture/textures too, and set the vertex colour to whatever you want. OpenGL (and presumably DirectX too) will automagically interpolate the colours between vertices, so you'd just need to work out which vertices need which colours to make your rainbow.

This would likely be neater using a fragment shader, where given a range of colours you could do all sorts of neat tricks (scroll the rainbow colours, or apply a sin wave to them or whatever) in the shader, removing the need to update the vertex colour buffer/values each frame on the CPU. I appreciate that this is somewhat difficult to do with Max2d though.

Alternatively, you may (may) be able to draw a rectangular texture over the text and use one of the OpenGL blend modes to only colour where the font textures are. Here's a useful tool to find out what glbendfunc can do. http://www.andersriggelsen.dk/glblendfunc.php
Try setting the blend equation to GL_MIN, and imagine the flamingo's are your font textures...

Changing the blend equation would require less work to add to max2d. i think, having not checked, you could add your own blend mode to work with the set blend function. Take a look at the Max2d source to see how ALPHABLEND and LIGHTBLEND are done. It may be as simple as adding an extra if statement with your own blendmode constant.


Cheers
Charlie


Bremer(Posted 2014) [#4]
If you draw a negative font, where the pixels of the characters are full alpha and all others are black. Then you can draw the "copper" colors and then draw the font on top of that. Then the colors will show through the pixels of the characters.


GfK(Posted 2014) [#5]
If you draw a negative font, where the pixels of the characters are full alpha and all others are black. Then you can draw the "copper" colors and then draw the font on top of that. Then the colors will show through the pixels of the characters.
That will only work if you have a black background.