UnixEspresso

Understading the stencil buffer

May 21st, 2022
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. GlStateManager.pushMatrix();
  2. GlStateManager.pushAttrib();
  3.  
  4. // Clear the stencil buffer
  5. GL11.glClearStencil(0);
  6. GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
  7.  
  8. GL11.glEnable(GL11.GL_STENCIL_TEST);
  9. GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_REPLACE, GL11.GL_REPLACE);
  10. GL11.glStencilFunc(GL11.GL_ALWAYS, 1, -1); // 1 is written into the buffer when we draw
  11. // Enable color mask
  12. glColorMask(true, true, true, true);
  13. GL11.glColor3f(255, 255, 255);
  14. Gui.drawRect(screen.getScaledWidth() / 2 - 40, screen.getScaledHeight() / 2 - 40, screen.getScaledWidth() / 2 + 40, screen.getScaledHeight() / 2 + 40, new Color(210, 100, 80).getRGB());
  15. // Disable color mask
  16. glColorMask(false, false, false, false);
  17. // Something something makes the fucking thing work (except it's not working)
  18. GL11.glStencilFunc(GL11.GL_NOTEQUAL, 1, -1); // Only draw if not equal to 1
  19. GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
  20. GL11.glColor3f(255, 255, 255);
  21. drawRect(0, 0, width, height, -1);
  22. // Disable color mask again(?)
  23. glColorMask(false, false, false, false);
  24. GlStateManager.popAttrib();
  25. GlStateManager.popMatrix();
Add Comment
Please, Sign In to add comment