Advertisement
StormWhisper

Multiple ScissorTest

Feb 22nd, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. public class ScissorTest
  2. {
  3.     private static final int max = 100;
  4.     private static ScissorTest[] objects = new ScissorTest[max];
  5.     private static int lastObject = -1;
  6.    
  7.     private int index;
  8.     private Body body;
  9.    
  10.     public ScissorTest(int x, int y, int width, int height)
  11.     {
  12.         lastObject++;
  13.         if (lastObject < max)
  14.         {
  15.             index = lastObject;
  16.             objects[index] = this;
  17.            
  18.             body = new Body(x, y, width, height);
  19.            
  20.             resume();
  21.         }
  22.         else
  23.         {
  24.             new Exception("\nScissor count limit reached: " + max).printStackTrace();
  25.             System.exit(1);
  26.         }
  27.     }
  28.    
  29.     private void resume()
  30.     {
  31.         GL11.glScissor(body.x, body.y, body.width, body.height);
  32.         GL11.glEnable(GL11.GL_SCISSOR_TEST);
  33.     }
  34.    
  35.     public void destroy()
  36.     {
  37.         if (index < lastObject)
  38.         {
  39.             new Exception("\nThere are scissors below this one").printStackTrace();
  40.             System.exit(1);
  41.         }
  42.        
  43.         GL11.glDisable(GL11.GL_SCISSOR_TEST);
  44.        
  45.         objects[index] = null;
  46.         lastObject--;
  47.        
  48.         if (lastObject > -1)
  49.             objects[lastObject].resume(); // Resuming previous scissor
  50.     }
  51.    
  52.     protected void finalize()
  53.     {
  54.         destroy();
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement