Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gameready.readycraft.mod;
- import java.awt.Color;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.nio.ByteBuffer;
- import org.lwjgl.BufferUtils;
- import org.lwjgl.opengl.Display;
- import static org.lwjgl.opengl.GL11.GL_CLAMP;
- import static org.lwjgl.opengl.GL11.GL_NEAREST;
- import static org.lwjgl.opengl.GL11.GL_RGBA;
- import static org.lwjgl.opengl.GL11.GL_RGBA8;
- import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
- import static org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER;
- import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
- import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S;
- import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T;
- import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
- import static org.lwjgl.opengl.GL11.glBindTexture;
- import static org.lwjgl.opengl.GL11.glGenTextures;
- import static org.lwjgl.opengl.GL11.glTexImage2D;
- import static org.lwjgl.opengl.GL11.glTexParameteri;
- import com.gameready.readycraft.mod.proxy.CommonProxy;
- import cpw.mods.fml.common.Mod;
- import cpw.mods.fml.common.Mod.EventHandler;
- import cpw.mods.fml.common.SidedProxy;
- import cpw.mods.fml.common.event.FMLInitializationEvent;
- import cpw.mods.fml.common.event.FMLPostInitializationEvent;
- import cpw.mods.fml.common.event.FMLPreInitializationEvent;
- @Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
- public class ReadyCraftMod
- {
- @SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.SERVER_PROXY)
- public static CommonProxy proxy;
- @EventHandler
- public void preInit(FMLPreInitializationEvent e)
- {
- String[] ICON_PATHS = {"/assets/readycraft/icons/16.png", "/assets/readycraft/icons/32.png"};
- Display.setTitle("HavanaMC");
- //Display.setIcon();
- }
- @EventHandler
- public void Init(FMLInitializationEvent e)
- {
- proxy.registerRenders();
- }
- @EventHandler
- public void postInit(FMLPostInitializationEvent e)
- {
- }
- public ByteBuffer generateByteBuffer(int[] pixels, int u, int v, int width, int height)
- {
- ByteBuffer buffer = BufferUtils.createByteBuffer((width * height) * 4);
- for (int y = u; y < height; y++)
- {
- for (int x = v; x < width; x++)
- {
- int i = pixels[x + y * width];
- Color c = new Color(i);
- buffer.put((byte) c.getRed());
- buffer.put((byte) c.getGreen());
- buffer.put((byte) c.getBlue());
- buffer.put((byte) c.getAlpha());
- }
- }
- buffer.flip();
- final int id = glGenTextures();
- glBindTexture(GL_TEXTURE_2D, id);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
- return buffer;
- }
- public ByteBuffer load(BufferedImage img, int u, int v, int width, int height)
- {
- return generateByteBuffer(img.getRGB(u, v, width, height, new int[width * height], 0, width), 0, 0, width, height);
- }
- public ByteBuffer load(BufferedImage img)
- {
- int width = img.getWidth();
- int height = img.getHeight();
- return generateByteBuffer(img.getRGB(0, 0, width, height, new int[width * height], 0, width), 0, 0, width, height);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement