Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import net.minecraft.client.Minecraft;
- import org.lwjgl.opengl.GL11;
- import org.lwjgl.opengl.GL12;
- import org.lwjgl.opengl.GL14;
- import org.lwjgl.opengl.GL30;
- import org.lwjgl.util.glu.GLU;
- import org.lwjgl.opengl.GLContext;
- import org.lwjgl.opengl.EXTFramebufferObject;
- public class mod_MipMap extends BaseMod {
- private static boolean done = false;
- private static boolean norefresh = false;
- org.lwjgl.opengl.ContextCapabilities capabilities;
- int mode = -1;
- int textureName;
- public mod_MipMap() {
- ModLoader.SetInGameHook(this, true, false);
- }
- public void OnTickInGame(Minecraft var1) {
- if (var1.q != null || var1.e == null) // current ingame screen open || world not loaded
- return;
- if (norefresh)
- return;
- if (!done) {
- done = true;
- try {
- textureName = var1.o.a("/terrain.png");
- } catch (Exception e) {
- System.out.println("Couldn't initialize mipmapping:");
- e.printStackTrace();
- norefresh = true;
- return;
- }
- GL11.glBindTexture(3553, textureName);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
- int textureWidth = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH);
- int tileWidth = textureWidth/16;
- int mipLevels = (int)Math.round(Math.log((double)tileWidth)/Math.log(2D));
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, mipLevels);
- GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.5F);
- capabilities = GLContext.getCapabilities();
- if (capabilities.OpenGL30) {
- System.out.println("Using OpenGL 3.0 for mipmap generation.");
- mode = 1;
- } else if (capabilities.GL_EXT_framebuffer_object) {
- System.out.println("Using GL_EXT_framebuffer_object extension for mipmap generation.");
- mode = 2;
- } else if (capabilities.OpenGL14) {
- System.out.println("Using GL_GENERATE_MIPMAP for mipmap generation. This might slow down with large textures.");
- mode = 3;
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
- norefresh = true;
- return;
- } else {
- System.out.println("Sorry, I could not find a suitable mechanism for automatic mipmap generation. Not enabling mipmapping.");
- norefresh = true;
- return;
- }
- }
- GL11.glBindTexture(3553, textureName);
- switch (mode) {
- case 1:
- GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
- break;
- case 2:
- EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D);
- break;
- }
- }
- public String Version() {
- return "1.2";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement