Advertisement
Guest User

gravenwitch openglutils null color fix

a guest
May 10th, 2025
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package Gravenwitch.CinematicCombat.util;
  2.  
  3. import java.awt.Color;
  4. import org.lwjgl.opengl.GL11;
  5.  
  6. public final class OpenGLUtils {
  7. public static void glColor(Color color) {
  8. // Null‐guard: fallback to white if color is null
  9. if (color == null) {
  10. GL11.glColor4ub((byte)255, (byte)255, (byte)255, (byte)255);
  11. return;
  12. }
  13. GL11.glColor4ub(
  14. (byte) color.getRed(),
  15. (byte) color.getGreen(),
  16. (byte) color.getBlue(),
  17. (byte) color.getAlpha()
  18. );
  19. }
  20.  
  21. public static void glColor(Color color, float alphaMult) {
  22. // Null‐guard: fallback to white if color is null
  23. if (color == null) {
  24. GL11.glColor4ub((byte)255, (byte)255, (byte)255, (byte)255);
  25. return;
  26. }
  27. GL11.glColor4ub(
  28. (byte) color.getRed(),
  29. (byte) color.getGreen(),
  30. (byte) color.getBlue(),
  31. (byte) ((float) color.getAlpha() * alphaMult)
  32. );
  33. }
  34.  
  35. public static void setupRendering() {
  36. GL11.glPushAttrib(1048575);
  37. GL11.glDisable(3553);
  38. GL11.glEnable(2848);
  39. GL11.glHint(3154, 4354);
  40. GL11.glEnable(3042);
  41. GL11.glBlendFunc(770, 771);
  42. GL11.glTranslatef(0.01f, 0.01f, 0.0f);
  43. }
  44.  
  45. public static void finishRendering() {
  46. GL11.glDisable(3042);
  47. GL11.glMatrixMode(5888);
  48. GL11.glPopMatrix();
  49. GL11.glPopAttrib();
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement