Merge pull request #1359 from dgtized/extractGLcolor

Extract GL.color(int color) for unpacking hex RGB
This commit is contained in:
CovertJaguar 2013-12-08 16:53:33 -08:00
commit eed53376aa
9 changed files with 34 additions and 53 deletions

View file

@ -11,6 +11,7 @@ import net.minecraftforge.fluids.Fluid;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import buildcraft.core.utils.GL;
import buildcraft.core.render.FluidRenderer; import buildcraft.core.render.FluidRenderer;
public abstract class GuiAdvancedInterface extends GuiBuildCraft { public abstract class GuiAdvancedInterface extends GuiBuildCraft {
@ -187,10 +188,7 @@ public abstract class GuiAdvancedInterface extends GuiBuildCraft {
@Override @Override
public void drawSprite(int cornerX, int cornerY) { public void drawSprite(int cornerX, int cornerY) {
if (fluid != null) { if (fluid != null) {
float red = (float) (colorRenderCache >> 16 & 255) / 255.0F; GL.color(colorRenderCache);
float green = (float) (colorRenderCache >> 8 & 255) / 255.0F;
float blue = (float) (colorRenderCache & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1);
} }
super.drawSprite(cornerX, cornerY); super.drawSprite(cornerX, cornerY);
} }

View file

@ -6,6 +6,7 @@ import buildcraft.core.gui.tooltips.IToolTipProvider;
import buildcraft.core.gui.tooltips.ToolTip; import buildcraft.core.gui.tooltips.ToolTip;
import buildcraft.core.gui.tooltips.ToolTipLine; import buildcraft.core.gui.tooltips.ToolTipLine;
import buildcraft.core.gui.widgets.Widget; import buildcraft.core.gui.widgets.Widget;
import buildcraft.core.utils.GL;
import buildcraft.core.utils.SessionVars; import buildcraft.core.utils.SessionVars;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -437,11 +438,7 @@ public abstract class GuiBuildCraft extends GuiContainer {
protected void drawBackground(int x, int y) { protected void drawBackground(int x, int y) {
float colorR = (overlayColor >> 16 & 255) / 255.0F; GL.color(overlayColor);
float colorG = (overlayColor >> 8 & 255) / 255.0F;
float colorB = (overlayColor & 255) / 255.0F;
GL11.glColor4f(colorR, colorG, colorB, 1.0F);
mc.renderEngine.bindTexture(LEDGER_TEXTURE); mc.renderEngine.bindTexture(LEDGER_TEXTURE);
drawTexturedModalRect(x, y, 0, 256 - currentHeight, 4, currentHeight); drawTexturedModalRect(x, y, 0, 256 - currentHeight, 4, currentHeight);

View file

@ -8,6 +8,7 @@
package buildcraft.core.render; package buildcraft.core.render;
import buildcraft.core.render.RenderEntityBlock.RenderInfo; import buildcraft.core.render.RenderEntityBlock.RenderInfo;
import buildcraft.core.utils.GL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -66,10 +67,7 @@ public class FluidRenderer {
return; return;
int color = fluidstack.getFluid().getColor(fluidstack); int color = fluidstack.getFluid().getColor(fluidstack);
float red = (float) (color >> 16 & 255) / 255.0F; GL.color(color);
float green = (float) (color >> 8 & 255) / 255.0F;
float blue = (float) (color & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1);
} }
public static int[] getFluidDisplayLists(FluidStack fluidStack, World world, boolean flowing) { public static int[] getFluidDisplayLists(FluidStack fluidStack, World world, boolean flowing) {

View file

@ -0,0 +1,12 @@
package buildcraft.core.utils;
import org.lwjgl.opengl.GL11;
public class GL {
public static void color(int color) {
float red = (float) (color >> 16 & 255) / 255.0F;
float green = (float) (color >> 8 & 255) / 255.0F;
float blue = (float) (color & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1.0F);
}
}

View file

@ -17,6 +17,7 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import buildcraft.core.fluids.Tank; import buildcraft.core.fluids.Tank;
import buildcraft.core.utils.GL;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.energy.TileEngineIron; import buildcraft.energy.TileEngineIron;
import buildcraft.energy.TileEngineWithInventory; import buildcraft.energy.TileEngineWithInventory;
@ -63,16 +64,12 @@ public class GuiCombustionEngine extends GuiEngine {
Icon liquidIcon = null; Icon liquidIcon = null;
Fluid fluid = liquid.getFluid(); Fluid fluid = liquid.getFluid();
int color = tank.colorRenderCache;
if (fluid != null && fluid.getStillIcon() != null) { if (fluid != null && fluid.getStillIcon() != null) {
liquidIcon = fluid.getStillIcon(); liquidIcon = fluid.getStillIcon();
} }
mc.renderEngine.bindTexture(BLOCK_TEXTURE); mc.renderEngine.bindTexture(BLOCK_TEXTURE);
float red = (float) (color >> 16 & 255) / 255.0F; GL.color(tank.colorRenderCache);
float green = (float) (color >> 8 & 255) / 255.0F;
float blue = (float) (color & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1.0F);
if (liquidIcon != null) { if (liquidIcon != null) {
while (true) { while (true) {
int x; int x;

View file

@ -11,6 +11,7 @@ import buildcraft.core.DefaultProps;
import buildcraft.core.IInventoryRenderer; import buildcraft.core.IInventoryRenderer;
import buildcraft.core.fluids.Tank; import buildcraft.core.fluids.Tank;
import buildcraft.core.render.FluidRenderer; import buildcraft.core.render.FluidRenderer;
import buildcraft.core.utils.GL;
import buildcraft.factory.TileRefinery; import buildcraft.factory.TileRefinery;
import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.model.ModelRenderer;
@ -187,10 +188,7 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
if (list1 != null) { if (list1 != null) {
bindTexture(FluidRenderer.getFluidSheet(liquid1)); bindTexture(FluidRenderer.getFluidSheet(liquid1));
float red = (float) (color1 >> 16 & 255) / 255.0F; GL.color(color1);
float green = (float) (color1 >> 8 & 255) / 255.0F;
float blue = (float) (color1 & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1.0F);
GL11.glCallList(list1[getDisplayListIndex(tile.tank1)]); GL11.glCallList(list1[getDisplayListIndex(tile.tank1)]);
} }
} }
@ -202,10 +200,7 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef(0, 0, 1); GL11.glTranslatef(0, 0, 1);
bindTexture(FluidRenderer.getFluidSheet(liquid2)); bindTexture(FluidRenderer.getFluidSheet(liquid2));
float red = (float) (color2 >> 16 & 255) / 255.0F; GL.color(color2);
float green = (float) (color2 >> 8 & 255) / 255.0F;
float blue = (float) (color2 & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1.0F);
GL11.glCallList(list2[getDisplayListIndex(tile.tank2)]); GL11.glCallList(list2[getDisplayListIndex(tile.tank2)]);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
@ -219,10 +214,7 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef(1, 0, 0.5F); GL11.glTranslatef(1, 0, 0.5F);
bindTexture(FluidRenderer.getFluidSheet(liquidResult)); bindTexture(FluidRenderer.getFluidSheet(liquidResult));
float red = (float) (colorResult >> 16 & 255) / 255.0F; GL.color(colorResult);
float green = (float) (colorResult >> 8 & 255) / 255.0F;
float blue = (float) (colorResult & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1.0F);
GL11.glCallList(list3[getDisplayListIndex(tile.result)]); GL11.glCallList(list3[getDisplayListIndex(tile.result)]);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }

View file

@ -8,6 +8,7 @@
package buildcraft.factory.render; package buildcraft.factory.render;
import buildcraft.core.render.FluidRenderer; import buildcraft.core.render.FluidRenderer;
import buildcraft.core.utils.GL;
import buildcraft.factory.TileTank; import buildcraft.factory.TileTank;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -40,11 +41,8 @@ public class RenderTank extends TileEntitySpecialRenderer {
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
bindTexture(FluidRenderer.getFluidSheet(liquid)); bindTexture(FluidRenderer.getFluidSheet(liquid));
float red = (float) (color >> 16 & 255) / 255.0F; GL.color(color);
float green = (float) (color >> 8 & 255) / 255.0F;
float blue = (float) (color & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1.0F);
GL11.glTranslatef((float) x + 0.125F, (float) y + 0.5F, (float) z + 0.125F); GL11.glTranslatef((float) x + 0.125F, (float) y + 0.5F, (float) z + 0.125F);
GL11.glScalef(0.75F, 0.999F, 0.75F); GL11.glScalef(0.75F, 0.999F, 0.75F);
GL11.glTranslatef(0, -0.5F, 0); GL11.glTranslatef(0, -0.5F, 0);

View file

@ -2,6 +2,7 @@ package buildcraft.transport.render;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.core.CoreConstants; import buildcraft.core.CoreConstants;
import buildcraft.core.utils.GL;
import buildcraft.transport.ItemFacade; import buildcraft.transport.ItemFacade;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -23,10 +24,7 @@ public class FacadeItemRenderer implements IItemRenderer {
try { try {
int color = Item.itemsList[decodedBlockId].getColorFromItemStack(new ItemStack(decodedBlockId, 1, decodedMeta), 0); int color = Item.itemsList[decodedBlockId].getColorFromItemStack(new ItemStack(decodedBlockId, 1, decodedMeta), 0);
float r = (float) (color >> 16 & 0xff) / 255F; GL.color(color);
float g = (float) (color >> 8 & 0xff) / 255F;
float b = (float) (color & 0xff) / 255F;
GL11.glColor4f(r, g, b, 1.0F);
} catch (Throwable error) { } catch (Throwable error) {
} }

View file

@ -16,6 +16,7 @@ import buildcraft.core.CoreConstants;
import buildcraft.core.render.RenderEntityBlock; import buildcraft.core.render.RenderEntityBlock;
import buildcraft.core.render.RenderEntityBlock.RenderInfo; import buildcraft.core.render.RenderEntityBlock.RenderInfo;
import buildcraft.core.utils.EnumColor; import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.GL;
import buildcraft.core.utils.MatrixTranformations; import buildcraft.core.utils.MatrixTranformations;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
@ -665,10 +666,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
default: default:
} }
bindTexture(TextureMap.locationBlocksTexture); bindTexture(TextureMap.locationBlocksTexture);
float red = (float) (color >> 16 & 255) / 255.0F; GL.color(color);
float green = (float) (color >> 8 & 255) / 255.0F;
float blue = (float) (color & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1.0F);
GL11.glCallList(list); GL11.glCallList(list);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
@ -683,10 +681,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1)); int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
bindTexture(TextureMap.locationBlocksTexture); bindTexture(TextureMap.locationBlocksTexture);
float red = (float) (color >> 16 & 255) / 255.0F; GL.color(color);
float green = (float) (color >> 8 & 255) / 255.0F;
float blue = (float) (color & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1.0F);
if (above) { if (above) {
GL11.glCallList(d.centerVertical[stage]); GL11.glCallList(d.centerVertical[stage]);
@ -766,11 +761,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
block.minX = min; block.minX = min;
block.maxX = max; block.maxX = max;
int cHex = color.getLightHex(); GL.color(color.getLightHex());
float r = (float) (cHex >> 16 & 0xff) / 255F;
float g = (float) (cHex >> 8 & 0xff) / 255F;
float b = (float) (cHex & 0xff) / 255F;
GL11.glColor4f(r, g, b, 1.0F);
RenderEntityBlock.INSTANCE.renderBlock(block, null, 0, 0, 0, false, true); RenderEntityBlock.INSTANCE.renderBlock(block, null, 0, 0, 0, false, true);
} }
GL11.glPopMatrix(); GL11.glPopMatrix();