Created
March 28, 2017 00:21
-
-
Save robotgryphon/b0a6ef332b733d1125515ba7bba55a10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void drawForeground(Point mouse) { | |
// GuiUtils.drawRectangle(contentArea, Color.MAGENTA); | |
Point drawOffset = displayedContentArea.getLocation(); | |
drawOffset.translate(contentArea.x, contentArea.y); | |
GlStateManager.pushMatrix(); | |
GlStateManager.disableLighting(); | |
StencilBuilder db = new StencilBuilder() | |
.unmask((VertexBuffer vb) -> { | |
vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); | |
vb.pos(contentArea.x + contentArea.width, contentArea.y + contentArea.height, 0).endVertex(); | |
vb.pos(contentArea.x + contentArea.width, contentArea.y, 0).endVertex(); | |
vb.pos(contentArea.x, contentArea.y, 0).endVertex(); | |
vb.pos(contentArea.x, contentArea.y + contentArea.height, 0).endVertex(); | |
}).startDraw(); | |
GlStateManager.pushMatrix(); | |
elementDisplayCache.forEach(e -> e.drawForeground(mouse)); | |
GlStateManager.popMatrix(); | |
db.endDraw(); | |
GlStateManager.popMatrix(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package codebirb.guilib.utils; | |
import codebirb.guilib.utils.stencil.StencilFunctionOption; | |
import net.minecraft.client.renderer.Tessellator; | |
import net.minecraft.client.renderer.VertexBuffer; | |
import org.lwjgl.opengl.GL11; | |
import java.util.function.Consumer; | |
import static org.lwjgl.opengl.GL11.*; | |
public class StencilBuilder { | |
private Consumer<VertexBuffer> stenciler; | |
public StencilBuilder() { } | |
public StencilBuilder unmask(Consumer<VertexBuffer> stenciler) { | |
this.stenciler = stenciler; | |
return this; | |
} | |
private void enable() { | |
glEnable(GL_STENCIL_TEST); | |
} | |
private void disable() { | |
glDisable(GL_STENCIL_TEST); | |
} | |
private void clear() { | |
glClearStencil(0); | |
glClear(GL_STENCIL_BUFFER_BIT); | |
} | |
@Deprecated | |
public static void stencilOption(StencilFunctionOption opt, int val) { | |
int STENCIL_TEST = glGetInteger(GL_STENCIL_FUNC); | |
int STENCIL_FAIL = glGetInteger(GL_STENCIL_FAIL); | |
int DEPTH_FAIL = glGetInteger(GL_STENCIL_PASS_DEPTH_FAIL); | |
int glDefault = GL_KEEP; | |
switch(opt) { | |
} | |
} | |
private void startDrawingMask() { | |
glStencilMask(0xFF); | |
} | |
private void finishMask() { | |
glStencilMask(0x00); | |
} | |
public StencilBuilder startDraw() { | |
enable(); | |
clear(); | |
// GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT); // Flush old data | |
startDrawingMask(); | |
// GL11.glStencilMask(0xFF); // Writing = ON | |
GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 0xFF); // Always "add" to frame | |
GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE); // Replace on success | |
Tessellator t = Tessellator.getInstance(); | |
VertexBuffer vb = t.getBuffer(); | |
this.stenciler.accept(vb); | |
t.draw(); | |
finishMask(); | |
// GL11.glStencilMask(0x00); // Writing = OFF | |
GL11.glStencilFunc(GL11.GL_NOTEQUAL, 0, 0xFF); // Anything that wasn't defined above will not be rendered. | |
return this; | |
} | |
public void endDraw() { | |
clear(); | |
disable(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment