So after a little testing I came up with this (for 1.12.2):
I created a Subclass of FontRenderer called GradientFontRenderer. In this class, I override the method renderDefaultChar (you should probably override the unicode method too.) so that It uses the above mentioned shadeModel and has the correct vertex order. The code for this is the following, and creates a gradient from red to blue:
@Override
protected float renderDefaultChar(int ch, boolean italic) {
float charXPos = ch % 16 * 8f;
float charYPos = (ch / 16) * 8f;
float italicOffset = italic ? 1f : 0f;
bindTexture(this.locationFontTexture);
int charWidth = this.charWidth[ch];
float width = (float)charWidth - 0.01F;
GlStateManager.shadeModel(GL11.GL_SMOOTH);
GlStateManager.glBegin(GL11.GL_QUADS);
GlStateManager.color(1.0f, 0.0f, 0.0f);
GlStateManager.glTexCoord2f(charXPos / 128.0F, charYPos / 128.0F); // 0 0
GlStateManager.glVertex3f(this.posX + italicOffset, this.posY, 0.0F);
GlStateManager.color(0.0f, 0.0f, 1.0f);
GlStateManager.glTexCoord2f(charXPos / 128.0F, (charYPos + 7.99F) / 128.0F); // 0 1
GlStateManager.glVertex3f(this.posX - italicOffset, this.posY + 7.99F, 0.0F);
GlStateManager.color(0.0f, 0.0f, 1.0f);
GlStateManager.glTexCoord2f((charXPos + width - 1.0F) / 128.0F, (charYPos + 7.99F) / 128.0F); // 1 1
GlStateManager.glVertex3f(this.posX + width - 1.0F - italicOffset, this.posY + 7.99F, 0.0F);
GlStateManager.color(1.0f, 0.0f, 0.0f);
GlStateManager.glTexCoord2f((charXPos + width - 1.0F) / 128.0F, charYPos / 128.0F); // 1 0
GlStateManager.glVertex3f(this.posX + width - 1.0F + italicOffset, this.posY, 0.0F);
GlStateManager.glEnd();
GlStateManager.shadeModel(GL11.GL_FLAT);
return (float)charWidth;
}
I'm sure you can expand on this code by adding parameters and auxiliary functions to control the gradient colors to your desire.
For instantiating the GradientFontRenderer, I just created an Instance in the constructor of my Gui class. You also need to call onResourceManagerReload to load the texture for the fontrenderer and all. This is the GuiScreen code:
public class TestGuiScreen extends GuiScreen {
private GradientFontRenderer gradientFontRenderer;
public TestGuiScreen() {
Minecraft mc = Minecraft.getMinecraft();
gradientFontRenderer = new GradientFontRenderer(mc.gameSettings, new ResourceLocation("textures/font/ascii.png"), mc.renderEngine, false);
gradientFontRenderer.onResourceManagerReload(null);
}
public void render() {
ScaledResolution res = new ScaledResolution(Minecraft.getMinecraft());
this.width = res.getScaledWidth();
this.height = res.getScaledHeight();
int x = (this.width) / 2;
int y = (this.height) / 2;
drawHelloTextWithGradient(x, y-16, 0xFFFFFFFF, 0xFFFF0000);
}
private void drawHelloTextWithGradient(int x, int y, int topColor, int bottomColor) {
drawRect(x-20, y-8, x+20, y+8, 0x7F000000);
drawCenteredGradientString(gradientFontRenderer, "hello", x, y-4, topColor, bottomColor);
}
public void drawCenteredGradientString(GradientFontRenderer fontRendererIn, String text, int x, int y, int color, int colorBottom)
{
fontRendererIn.drawString(text, x - fontRendererIn.getStringWidth(text) / 2, y, color);
}
}
Here is a screenshot of how it looks.
I hope this was helpful. If you have any further questions, just ask