1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-04-27 13:13:17 +00:00

Fix texture artifacts when rendering monitors

- Adds a 1px margin around every glyph. This is generally empty,
   with the exception of teletext characters where it continues their
   pattern.
 - Uses GL_CLAMP with the font texture.

Closes #300
This commit is contained in:
SquidDev 2017-07-10 22:20:07 +01:00
parent 94d701b1f7
commit 1cf3d78eac
3 changed files with 19 additions and 10 deletions

View File

@ -20,7 +20,7 @@ import java.util.Arrays;
public class FixedWidthFontRenderer public class FixedWidthFontRenderer
{ {
public static ResourceLocation font = new ResourceLocation( "computercraft", "textures/gui/term_font.png" ); private static ResourceLocation font = new ResourceLocation( "computercraft", "textures/gui/term_font.png" );
public static ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/term_background.png" ); public static ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/term_background.png" );
public static int FONT_HEIGHT = 9; public static int FONT_HEIGHT = 9;
@ -52,12 +52,15 @@ public class FixedWidthFontRenderer
float g = (float)colour[1]; float g = (float)colour[1];
float b = (float)colour[2]; float b = (float)colour[2];
renderer.pos( x, y, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT ) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); int xStart = 1 + column * (FONT_WIDTH + 2);
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); int yStart = 1 + row * (FONT_HEIGHT + 2);
renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); renderer.pos( x, y, 0.0 ).tex( xStart / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).endVertex();
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( xStart / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
renderer.pos( x + FONT_WIDTH, y + FONT_HEIGHT, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (xStart + FONT_WIDTH) / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).endVertex();
renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (xStart + FONT_WIDTH) / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).endVertex();
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( xStart / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
renderer.pos( x + FONT_WIDTH, y + FONT_HEIGHT, 0.0 ).tex( (xStart + FONT_WIDTH) / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
} }
private void drawQuad( VertexBuffer renderer, double x, double y, int color, double width, Palette p, boolean greyscale ) private void drawQuad( VertexBuffer renderer, double x, double y, int color, double width, Palette p, boolean greyscale )
@ -164,7 +167,7 @@ public class FixedWidthFontRenderer
if( s != null && textColour != null ) if( s != null && textColour != null )
{ {
// Bind the font texture // Bind the font texture
m_textureManager.bindTexture( font ); bindFont();
// Draw the quads // Draw the quads
drawStringTextPart( x, y, s, textColour, greyScale, p ); drawStringTextPart( x, y, s, textColour, greyScale, p );
@ -179,4 +182,10 @@ public class FixedWidthFontRenderer
} }
return s.length() * FONT_WIDTH; return s.length() * FONT_WIDTH;
} }
public void bindFont()
{
m_textureManager.bindTexture( font );
GlStateManager.glTexParameteri( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
}
} }

View File

@ -179,7 +179,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
GlStateManager.callList( origin.m_renderDisplayList ); GlStateManager.callList( origin.m_renderDisplayList );
// Draw text // Draw text
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.font ); fontRenderer.bindFont();
if( redraw ) if( redraw )
{ {
// Build text display list // Build text display list
@ -206,7 +206,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
GlStateManager.callList( origin.m_renderDisplayList + 1 ); GlStateManager.callList( origin.m_renderDisplayList + 1 );
// Draw cursor // Draw cursor
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.font ); fontRenderer.bindFont();
if( redraw ) if( redraw )
{ {
// Build cursor display list // Build cursor display list

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB