Advertisement
GamingLVScripts

Untitled

Apr 3rd, 2024
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. public class BasicRenderUtil {
  2.     public static void push() {
  3.         GL11.glPushMatrix();
  4.     }
  5.  
  6.     public static void pop() {
  7.         GL11.glPopMatrix();
  8.     }
  9.  
  10.     public static void enable(int enable) {
  11.         GL11.glEnable(enable);
  12.     }
  13.  
  14.     public static void disable(int disable) {
  15.         GL11.glDisable(disable);
  16.     }
  17.  
  18.     public static void begin(int mode) {
  19.         GL11.glBegin(mode);
  20.     }
  21.  
  22.     public static void end() {
  23.         GL11.glEnd();
  24.     }
  25.  
  26.     public static void vertex(double x, double y) {
  27.         GL11.glVertex2d(x, y);
  28.     }
  29.  
  30.     public static void vertex(float x, float y) {
  31.         GL11.glVertex2f(x, y);
  32.     }
  33.  
  34.     public static void vertex(int x, int y) {
  35.         GL11.glVertex2i(x, y);
  36.     }
  37.  
  38.     public static void blend(int one, int two) {
  39.         GL11.glBlendFunc(one, two);
  40.     }
  41.  
  42.     public static void color(Color color) {
  43.         GlStateManager.color(
  44.                 color.getRed() / 255.0F,
  45.                 color.getGreen() / 255.0F,
  46.                 color.getBlue() / 255.0F,
  47.                 color.getAlpha() / 255.0F
  48.         );
  49.     }
  50.  
  51.     public static void start() {
  52.         push();
  53.  
  54.         enable(GL_BLEND);
  55.  
  56.         blend(
  57.                 GL_SRC_ALPHA,
  58.                 GL_ONE_MINUS_SRC_ALPHA
  59.         );
  60.  
  61.         GlStateManager.disableTexture2D();
  62.         GlStateManager.disableCull();
  63.  
  64.         GlStateManager.disableAlpha();
  65.         GlStateManager.disableDepth();
  66.     }
  67.  
  68.     public static void stop() {
  69.         GlStateManager.enableAlpha();
  70.         GlStateManager.enableDepth();
  71.  
  72.         GlStateManager.enableCull();
  73.         GlStateManager.enableTexture2D();
  74.  
  75.         disable(GL_BLEND);
  76.  
  77.         color(Color.WHITE);
  78.  
  79.         pop();
  80.     }
  81.  
  82.     public static void rectangle(double x, double y, double width, double height, boolean filled, Color color) {
  83.         start();
  84.  
  85.         if (color != null)
  86.             color(color);
  87.  
  88.         begin(filled ? GL_TRIANGLE_FAN : GL_LINE_LOOP);
  89.  
  90.         {
  91.             vertex(x, y);
  92.             vertex(x + width, y);
  93.             vertex(x + width, y + height);
  94.             vertex(x, y + height);
  95.         }
  96.  
  97.         end();
  98.         stop();
  99.     }
  100.  
  101.     public static void scale(float x, float y, float scale, Runnable runnable) {
  102.         GlStateManager.pushMatrix();
  103.  
  104.         glTranslatef(x, y, 1);
  105.         glScalef(scale, scale, 1);
  106.         glTranslatef(-x, -y, 1);
  107.  
  108.         runnable.run();
  109.  
  110.         GlStateManager.popMatrix();
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement