Improved block rendering a bit, should play much nicer with shaders now (thanks a ton to Ivorius for pointers).

This commit is contained in:
Florian Nücke 2015-02-04 17:49:45 +01:00
parent 806dda8827
commit 58056a837c
14 changed files with 39 additions and 30 deletions

View File

@ -118,11 +118,11 @@ abstract class TextureFontRenderer {
protected def textureCount: Int protected def textureCount: Int
protected def bindTexture(index: Int) protected def bindTexture(index: Int): Unit
protected def generateChar(char: Char) protected def generateChar(char: Char): Unit
protected def drawChar(tx: Float, ty: Float, char: Char) protected def drawChar(tx: Float, ty: Float, char: Char): Unit
private def drawQuad(color: Int, x: Int, y: Int, width: Int) = if (color != 0 && width > 0) { private def drawQuad(color: Int, x: Int, y: Int, width: Int) = if (color != 0 && width > 0) {
val x0 = x * charWidth val x0 = x * charWidth

View File

@ -63,6 +63,8 @@ object AssemblerRenderer extends TileEntitySpecialRenderer {
GL11.glRotatef(90, 0, 1, 0) GL11.glRotatef(90, 0, 1, 0)
} }
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()

View File

@ -56,6 +56,8 @@ object CaseRenderer extends TileEntitySpecialRenderer {
} }
} }
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()

View File

@ -68,6 +68,8 @@ object ChargerRenderer extends TileEntitySpecialRenderer {
t.draw() t.draw()
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()
} }

View File

@ -59,6 +59,8 @@ object DisassemblerRenderer extends TileEntitySpecialRenderer {
t.draw() t.draw()
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()
} }

View File

@ -66,6 +66,8 @@ object DiskDriveRenderer extends TileEntitySpecialRenderer {
t.addVertexWithUV(1, 0, 0, 1, 0) t.addVertexWithUV(1, 0, 0, 1, 0)
t.addVertexWithUV(0, 0, 0, 0, 0) t.addVertexWithUV(0, 0, 0, 0, 0)
t.draw() t.draw()
RenderState.enableLighting()
} }
GL11.glPopMatrix() GL11.glPopMatrix()

View File

@ -36,6 +36,8 @@ object GeolyzerRenderer extends TileEntitySpecialRenderer {
t.draw() t.draw()
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()

View File

@ -54,6 +54,8 @@ object MicrocontrollerRenderer extends TileEntitySpecialRenderer {
t.draw() t.draw()
} }
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()

View File

@ -60,6 +60,8 @@ object PowerDistributorRenderer extends TileEntitySpecialRenderer {
t.draw() t.draw()
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()
} }

View File

@ -45,6 +45,8 @@ object RaidRenderer extends TileEntitySpecialRenderer {
} }
} }
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()

View File

@ -12,6 +12,7 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11 import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL14
object ScreenRenderer extends TileEntitySpecialRenderer { object ScreenRenderer extends TileEntitySpecialRenderer {
private val maxRenderDistanceSq = Settings.get.maxScreenTextRenderDistance * Settings.get.maxScreenTextRenderDistance private val maxRenderDistanceSq = Settings.get.maxScreenTextRenderDistance * Settings.get.maxScreenTextRenderDistance
@ -66,7 +67,9 @@ object ScreenRenderer extends TileEntitySpecialRenderer {
RenderState.checkError(getClass.getName + ".renderTileEntityAt: overlay") RenderState.checkError(getClass.getName + ".renderTileEntityAt: overlay")
if (distance > fadeDistanceSq) { if (distance > fadeDistanceSq) {
RenderState.setBlendAlpha(math.max(0, 1 - ((distance - fadeDistanceSq) * fadeRatio).toFloat)) val alpha = math.max(0, 1 - ((distance - fadeDistanceSq) * fadeRatio).toFloat)
GL14.glBlendColor(0, 0, 0, alpha)
GL11.glBlendFunc(GL11.GL_CONSTANT_ALPHA, GL11.GL_ONE)
} }
RenderState.checkError(getClass.getName + ".renderTileEntityAt: fade") RenderState.checkError(getClass.getName + ".renderTileEntityAt: fade")
@ -75,6 +78,8 @@ object ScreenRenderer extends TileEntitySpecialRenderer {
draw() draw()
} }
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()

View File

@ -62,6 +62,8 @@ object ServerRackRenderer extends TileEntitySpecialRenderer {
} }
} }
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()

View File

@ -55,6 +55,8 @@ object SwitchRenderer extends TileEntitySpecialRenderer {
t.draw() t.draw()
RenderState.enableLighting()
GL11.glPopMatrix() GL11.glPopMatrix()
GL11.glPopAttrib() GL11.glPopAttrib()
} }

View File

@ -2,7 +2,8 @@ package li.cil.oc.util
import li.cil.oc.OpenComputers import li.cil.oc.OpenComputers
import li.cil.oc.Settings import li.cil.oc.Settings
import net.minecraft.client.renderer.OpenGlHelper import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.RenderHelper
import org.lwjgl.opengl._ import org.lwjgl.opengl._
import org.lwjgl.util.glu.GLU import org.lwjgl.util.glu.GLU
@ -27,41 +28,22 @@ object RenderState {
} }
def disableLighting() { def disableLighting() {
GL11.glDisable(GL11.GL_LIGHTING) Minecraft.getMinecraft.entityRenderer.disableLightmap(0)
if (arb) { RenderHelper.disableStandardItemLighting()
ARBMultitexture.glActiveTextureARB(OpenGlHelper.lightmapTexUnit)
GL11.glDisable(GL11.GL_TEXTURE_2D)
ARBMultitexture.glActiveTextureARB(OpenGlHelper.defaultTexUnit)
}
else {
GL13.glActiveTexture(OpenGlHelper.lightmapTexUnit)
GL11.glDisable(GL11.GL_TEXTURE_2D)
GL13.glActiveTexture(OpenGlHelper.defaultTexUnit)
}
} }
def enableLighting() { def enableLighting() {
GL11.glEnable(GL11.GL_LIGHTING) Minecraft.getMinecraft.entityRenderer.enableLightmap(0)
if (arb) { RenderHelper.enableStandardItemLighting()
ARBMultitexture.glActiveTextureARB(OpenGlHelper.lightmapTexUnit)
GL11.glEnable(GL11.GL_TEXTURE_2D)
ARBMultitexture.glActiveTextureARB(OpenGlHelper.defaultTexUnit)
}
else {
GL13.glActiveTexture(OpenGlHelper.lightmapTexUnit)
GL11.glEnable(GL11.GL_TEXTURE_2D)
GL13.glActiveTexture(OpenGlHelper.defaultTexUnit)
}
} }
def makeItBlend() { def makeItBlend() {
GL11.glEnable(GL11.GL_BLEND) GL11.glEnable(GL11.GL_BLEND)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
GL11.glDepthFunc(GL11.GL_LEQUAL)
} }
def setBlendAlpha(alpha: Float) = if (canUseBlendColor) { def setBlendAlpha(alpha: Float) = if (canUseBlendColor) {
GL14.glBlendColor(0, 0, 0, alpha) GL11.glColor4f(1, 1, 1, alpha)
GL11.glBlendFunc(GL11.GL_CONSTANT_ALPHA, GL11.GL_ONE) GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
} }
} }