Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.61 KB | None | 0 0
  1. package com.gameready.readycraft.mod;
  2.  
  3. import java.awt.Color;
  4. import java.awt.image.BufferedImage;
  5. import java.io.File;
  6. import java.io.FileInputStream;
  7. import java.io.IOException;
  8. import java.nio.ByteBuffer;
  9.  
  10. import org.lwjgl.BufferUtils;
  11. import org.lwjgl.opengl.Display;
  12.  
  13. import static org.lwjgl.opengl.GL11.GL_CLAMP;
  14. import static org.lwjgl.opengl.GL11.GL_NEAREST;
  15. import static org.lwjgl.opengl.GL11.GL_RGBA;
  16. import static org.lwjgl.opengl.GL11.GL_RGBA8;
  17. import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
  18. import static org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER;
  19. import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
  20. import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S;
  21. import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T;
  22. import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
  23. import static org.lwjgl.opengl.GL11.glBindTexture;
  24. import static org.lwjgl.opengl.GL11.glGenTextures;
  25. import static org.lwjgl.opengl.GL11.glTexImage2D;
  26. import static org.lwjgl.opengl.GL11.glTexParameteri;
  27.  
  28. import com.gameready.readycraft.mod.proxy.CommonProxy;
  29.  
  30. import cpw.mods.fml.common.Mod;
  31. import cpw.mods.fml.common.Mod.EventHandler;
  32. import cpw.mods.fml.common.SidedProxy;
  33. import cpw.mods.fml.common.event.FMLInitializationEvent;
  34. import cpw.mods.fml.common.event.FMLPostInitializationEvent;
  35. import cpw.mods.fml.common.event.FMLPreInitializationEvent;
  36.  
  37. @Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
  38.  
  39. public class ReadyCraftMod
  40. {
  41.     @SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.SERVER_PROXY)
  42.     public static CommonProxy proxy;
  43.    
  44.     @EventHandler
  45.     public void preInit(FMLPreInitializationEvent e)
  46.     {
  47.         String[] ICON_PATHS = {"/assets/readycraft/icons/16.png", "/assets/readycraft/icons/32.png"};
  48.  
  49.         Display.setTitle("HavanaMC");
  50.         //Display.setIcon();
  51.     }
  52.    
  53.     @EventHandler
  54.     public void Init(FMLInitializationEvent e)
  55.     {
  56.         proxy.registerRenders();
  57.     }
  58.    
  59.     @EventHandler
  60.     public void postInit(FMLPostInitializationEvent e)
  61.     {
  62.        
  63.     }
  64.    
  65.     public ByteBuffer generateByteBuffer(int[] pixels, int u, int v, int width, int height)
  66.     {
  67.         ByteBuffer buffer = BufferUtils.createByteBuffer((width * height) * 4);
  68.  
  69.         for (int y = u; y < height; y++)
  70.         {
  71.             for (int x = v; x < width; x++)
  72.             {
  73.                 int i = pixels[x + y * width];
  74.                 Color c = new Color(i);
  75.                 buffer.put((byte) c.getRed());
  76.                 buffer.put((byte) c.getGreen());
  77.                 buffer.put((byte) c.getBlue());
  78.                 buffer.put((byte) c.getAlpha());
  79.             }
  80.         }
  81.  
  82.         buffer.flip();
  83.  
  84.         final int id = glGenTextures();
  85.         glBindTexture(GL_TEXTURE_2D, id);
  86.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  87.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  88.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  89.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  90.         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  91.         return buffer;
  92.     }
  93.  
  94.     public ByteBuffer load(BufferedImage img, int u, int v, int width, int height)
  95.     {
  96.         return generateByteBuffer(img.getRGB(u, v, width, height, new int[width * height], 0, width), 0, 0, width, height);
  97.     }
  98.  
  99.     public ByteBuffer load(BufferedImage img)
  100.     {
  101.         int width = img.getWidth();
  102.         int height = img.getHeight();
  103.        
  104.         return generateByteBuffer(img.getRGB(0, 0, width, height, new int[width * height], 0, width), 0, 0, width, height);
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement