1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-06 13:58:34 +00:00

Merge pull request #192 from Lignum/render-improvements

Small terminal & monitor rendering improvements
This commit is contained in:
Daniel Ratcliffe 2017-05-04 23:09:48 +01:00 committed by GitHub
commit 6271555c45
5 changed files with 63 additions and 57 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@ deploy
*.ipr *.ipr
*.iws *.iws
*.iml *.iml
.idea
.gradle .gradle
luaj-2.0.3/lib luaj-2.0.3/lib
luaj-2.0.3/*.jar luaj-2.0.3/*.jar

View File

@ -8,6 +8,7 @@ package dan200.computercraft.client.gui;
import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Colour;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureManager;
@ -35,19 +36,23 @@ public class FixedWidthFontRenderer
int column = index % 16; int column = index % 16;
int row = index / 16; int row = index / 16;
Colour colour = Colour.values()[ 15 - color ]; Colour colour = Colour.values()[ 15 - color ];
renderer.pos( x, y, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT ) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 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( colour.getR(), colour.getG(), colour.getB(), 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( colour.getR(), colour.getG(), colour.getB(), 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( colour.getR(), colour.getG(), colour.getB(), 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( colour.getR(), colour.getG(), colour.getB(), 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( colour.getR(), colour.getG(), colour.getB(), 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( colour.getR(), colour.getG(), colour.getB(), 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( colour.getR(), colour.getG(), colour.getB(), 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( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
renderer.pos( x, y, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT ) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
} }
private void drawQuad( VertexBuffer renderer, double x, double y, int color, double width ) private void drawQuad( VertexBuffer renderer, double x, double y, int color, double width )
{ {
Colour colour = Colour.values()[ 15 - color ]; Colour colour = Colour.values()[ 15 - color ];
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( 0.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( x, y, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
renderer.pos( x + width, y + FONT_HEIGHT, 0.0 ).tex( 1.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
renderer.pos( x + width, y, 0.0 ).tex( 1.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( x + width, y, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
renderer.pos( x, y, 0.0 ).tex( 0.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( x + width, y, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
renderer.pos( x + width, y + FONT_HEIGHT, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
} }
private boolean isGreyScale( int colour ) private boolean isGreyScale( int colour )
@ -60,7 +65,7 @@ public class FixedWidthFontRenderer
// Draw the quads // Draw the quads
Tessellator tessellator = Tessellator.getInstance(); Tessellator tessellator = Tessellator.getInstance();
VertexBuffer renderer = tessellator.getBuffer(); VertexBuffer renderer = tessellator.getBuffer();
renderer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR ); renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_COLOR );
if( leftMarginSize > 0.0 ) if( leftMarginSize > 0.0 )
{ {
int colour1 = "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) ); int colour1 = "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) );
@ -88,7 +93,9 @@ public class FixedWidthFontRenderer
} }
drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH ); drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH );
} }
GlStateManager.disableTexture2D();
tessellator.draw(); tessellator.draw();
GlStateManager.enableTexture2D();
} }
public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale ) public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale )
@ -96,7 +103,7 @@ public class FixedWidthFontRenderer
// Draw the quads // Draw the quads
Tessellator tessellator = Tessellator.getInstance(); Tessellator tessellator = Tessellator.getInstance();
VertexBuffer renderer = tessellator.getBuffer(); VertexBuffer renderer = tessellator.getBuffer();
renderer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR ); renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_TEX_COLOR );
for( int i = 0; i < s.length(); i++ ) for( int i = 0; i < s.length(); i++ )
{ {
// Switch colour // Switch colour

View File

@ -407,23 +407,22 @@ public class WidgetTerminal extends Widget
TextBuffer colour = terminal.getTextColourLine( line ); TextBuffer colour = terminal.getTextColourLine( line );
TextBuffer backgroundColour = terminal.getBackgroundColourLine( line ); TextBuffer backgroundColour = terminal.getBackgroundColourLine( line );
fontRenderer.drawString( text, x, y, colour, backgroundColour, m_leftMargin, m_rightMargin, greyscale ); fontRenderer.drawString( text, x, y, colour, backgroundColour, m_leftMargin, m_rightMargin, greyscale );
if( tblink && ty == line ) y += FixedWidthFontRenderer.FONT_HEIGHT;
{ }
if( tx >= 0 && tx < tw )
{ if( tblink && tx >= 0 && ty >= 0 && tx < tw && ty < th )
TextBuffer cursor = new TextBuffer( '_', 1 ); {
TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 ); TextBuffer cursor = new TextBuffer( '_', 1 );
fontRenderer.drawString( TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 );
cursor,
x + FixedWidthFontRenderer.FONT_WIDTH * tx, fontRenderer.drawString(
y, cursor,
cursorColour, null, x + FixedWidthFontRenderer.FONT_WIDTH * tx,
0, 0, startY + m_topMargin + FixedWidthFontRenderer.FONT_HEIGHT * ty,
greyscale cursorColour, null,
); 0, 0,
} greyscale
} );
y = y + FixedWidthFontRenderer.FONT_HEIGHT;
} }
} }
} }

View File

@ -27,6 +27,7 @@ import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.turtle.entity.TurtleVisionCamera; import dan200.computercraft.shared.turtle.entity.TurtleVisionCamera;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.ItemMeshDefinition; import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.model.ModelResourceLocation;
@ -256,7 +257,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
@Override @Override
public void deleteDisplayLists( int list, int range ) public void deleteDisplayLists( int list, int range )
{ {
GL11.glDeleteLists( list, range ); GlStateManager.glDeleteLists( list, range );
} }
@Override @Override

View File

@ -11,7 +11,6 @@ import dan200.computercraft.client.gui.FixedWidthFontRenderer;
import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.shared.common.ClientTerminal; import dan200.computercraft.shared.common.ClientTerminal;
import dan200.computercraft.shared.common.ITerminal;
import dan200.computercraft.shared.peripheral.monitor.TileMonitor; import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.DirectionUtil;
@ -21,11 +20,8 @@ import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.MinecraftForgeClient;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMonitor> public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMonitor>
@ -111,7 +107,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
// Allocate display lists // Allocate display lists
if( origin.m_renderDisplayList < 0 ) if( origin.m_renderDisplayList < 0 )
{ {
origin.m_renderDisplayList = GL11.glGenLists( 3 ); origin.m_renderDisplayList = GlStateManager.glGenLists( 3 );
redraw = true; redraw = true;
} }
@ -135,7 +131,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
if( redraw ) if( redraw )
{ {
// Build background display list // Build background display list
GL11.glNewList( origin.m_renderDisplayList, GL11.GL_COMPILE ); GlStateManager.glNewList( origin.m_renderDisplayList, GL11.GL_COMPILE );
try try
{ {
double marginXSize = TileMonitor.RENDER_MARGIN / xScale; double marginXSize = TileMonitor.RENDER_MARGIN / xScale;
@ -143,18 +139,18 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
double marginSquash = marginYSize / (double) FixedWidthFontRenderer.FONT_HEIGHT; double marginSquash = marginYSize / (double) FixedWidthFontRenderer.FONT_HEIGHT;
// Top and bottom margins // Top and bottom margins
GL11.glPushMatrix(); GlStateManager.pushMatrix();
try try
{ {
GL11.glScaled( 1.0, marginSquash, 1.0 ); GlStateManager.scale( 1.0, marginSquash, 1.0 );
GL11.glTranslated( 0.0, -marginYSize / marginSquash, 0.0 ); GlStateManager.translate( 0.0, -marginYSize / marginSquash, 0.0 );
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( 0 ), marginXSize, marginXSize, greyscale ); fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( 0 ), marginXSize, marginXSize, greyscale );
GL11.glTranslated( 0.0, ( marginYSize + height * FixedWidthFontRenderer.FONT_HEIGHT ) / marginSquash, 0.0 ); GlStateManager.translate( 0.0, ( marginYSize + height * FixedWidthFontRenderer.FONT_HEIGHT ) / marginSquash, 0.0 );
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( height - 1 ), marginXSize, marginXSize, greyscale ); fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( height - 1 ), marginXSize, marginXSize, greyscale );
} }
finally finally
{ {
GL11.glPopMatrix(); GlStateManager.popMatrix();
} }
// Backgrounds // Backgrounds
@ -170,7 +166,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
} }
finally finally
{ {
GL11.glEndList(); GlStateManager.glEndList();
} }
} }
GlStateManager.callList( origin.m_renderDisplayList ); GlStateManager.callList( origin.m_renderDisplayList );
@ -180,7 +176,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
if( redraw ) if( redraw )
{ {
// Build text display list // Build text display list
GL11.glNewList( origin.m_renderDisplayList + 1, GL11.GL_COMPILE ); GlStateManager.glNewList( origin.m_renderDisplayList + 1, GL11.GL_COMPILE );
try try
{ {
// Lines // Lines
@ -196,7 +192,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
} }
finally finally
{ {
GL11.glEndList(); GlStateManager.glEndList();
} }
} }
GlStateManager.callList( origin.m_renderDisplayList + 1 ); GlStateManager.callList( origin.m_renderDisplayList + 1 );
@ -206,7 +202,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
if( redraw ) if( redraw )
{ {
// Build cursor display list // Build cursor display list
GL11.glNewList( origin.m_renderDisplayList + 2, GL11.GL_COMPILE ); GlStateManager.glNewList( origin.m_renderDisplayList + 2, GL11.GL_COMPILE );
try try
{ {
// Cursor // Cursor
@ -226,7 +222,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
} }
finally finally
{ {
GL11.glEndList(); GlStateManager.glEndList();
} }
} }
if( ComputerCraft.getGlobalCursorBlink() ) if( ComputerCraft.getGlobalCursorBlink() )
@ -243,13 +239,17 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
{ {
// Draw a big black quad // Draw a big black quad
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.background ); mc.getTextureManager().bindTexture( FixedWidthFontRenderer.background );
renderer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR ); final Colour colour = Colour.Black;
Colour colour = Colour.Black;
renderer.pos( -TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).tex( 0.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); final float r = colour.getR();
renderer.pos( xSize + TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).tex( 1.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); final float g = colour.getG();
renderer.pos( xSize + TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0D ).tex( 1.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); final float b = colour.getB();
renderer.pos( -TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0D ).tex( 0.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
renderer.pos( -TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).tex( 0.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.begin( GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION_TEX_COLOR );
renderer.pos( -TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0D ).tex( 0.0, 0.0 ).color( r, g, b, 1.0f ).endVertex();
renderer.pos( -TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).tex( 0.0, 1.0 ).color( r, g, b, 1.0f ).endVertex();
renderer.pos( xSize + TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0D ).tex( 1.0, 0.0 ).color( r, g, b, 1.0f ).endVertex();
renderer.pos( xSize + TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).tex( 1.0, 1.0 ).color( r, g, b, 1.0f ).endVertex();
tessellator.draw(); tessellator.draw();
} }
} }
@ -264,13 +264,11 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
try try
{ {
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.background ); mc.getTextureManager().bindTexture( FixedWidthFontRenderer.background );
renderer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR ); renderer.begin( GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION );
Colour colour = Colour.Black; renderer.pos( -TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0 ).endVertex();
renderer.pos( -TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).tex( 0.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( -TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).endVertex();
renderer.pos( xSize + TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).tex( 1.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( xSize + TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0 ).endVertex();
renderer.pos( xSize + TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0D ).tex( 1.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( xSize + TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).endVertex();
renderer.pos( -TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0D ).tex( 0.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
renderer.pos( -TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).tex( 0.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex();
tessellator.draw(); tessellator.draw();
} }
finally finally