Advertisement
303

meepmap

303
Mar 27th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None | 0 0
  1. import net.minecraft.client.Minecraft;
  2. import org.lwjgl.opengl.GL11;
  3. import org.lwjgl.opengl.GL12;
  4. import org.lwjgl.opengl.GL14;
  5. import org.lwjgl.opengl.GL30;
  6. import org.lwjgl.util.glu.GLU;
  7. import org.lwjgl.opengl.GLContext;
  8. import org.lwjgl.opengl.EXTFramebufferObject;
  9.  
  10. public class mod_MipMap extends BaseMod {
  11.     private static boolean done = false;
  12.     private static boolean norefresh = false;
  13.     org.lwjgl.opengl.ContextCapabilities capabilities;
  14.     int mode = -1;
  15.     int textureName;
  16.  
  17.     public mod_MipMap() {
  18.         ModLoader.SetInGameHook(this, true, false);
  19.     }
  20.  
  21.     public void OnTickInGame(Minecraft var1) {
  22.         if (var1.q != null || var1.e == null) // current ingame screen open || world not loaded
  23.             return;
  24.  
  25.         if (norefresh)
  26.             return;
  27.  
  28.         if (!done) {
  29.             done = true;
  30.  
  31.             try {
  32.                 textureName = var1.o.a("/terrain.png");
  33.             } catch (Exception e) {
  34.                 System.out.println("Couldn't initialize mipmapping:");
  35.                 e.printStackTrace();
  36.                 norefresh = true;
  37.                 return;
  38.             }
  39.  
  40.             GL11.glBindTexture(3553, textureName);
  41.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
  42.             int textureWidth = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH);
  43.             int tileWidth = textureWidth/16;
  44.             int mipLevels = (int)Math.round(Math.log((double)tileWidth)/Math.log(2D));
  45.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, mipLevels);
  46.             GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.5F);
  47.             capabilities = GLContext.getCapabilities();
  48.  
  49.             if (capabilities.OpenGL30) {
  50.                 System.out.println("Using OpenGL 3.0 for mipmap generation.");
  51.                 mode = 1;
  52.             } else if (capabilities.GL_EXT_framebuffer_object) {
  53.                 System.out.println("Using GL_EXT_framebuffer_object extension for mipmap generation.");
  54.                 mode = 2;
  55.             } else if (capabilities.OpenGL14) {
  56.                 System.out.println("Using GL_GENERATE_MIPMAP for mipmap generation. This might slow down with large textures.");
  57.                 mode = 3;
  58.                 GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
  59.                 norefresh = true;
  60.                 return;
  61.             } else {
  62.                 System.out.println("Sorry, I could not find a suitable mechanism for automatic mipmap generation. Not enabling mipmapping.");
  63.                 norefresh = true;
  64.                 return;
  65.             }
  66.         }
  67.  
  68.         GL11.glBindTexture(3553, textureName);
  69.  
  70.         switch (mode) {
  71.         case 1:
  72.             GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
  73.             break;
  74.         case 2:
  75.             EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D);
  76.             break;
  77.         }
  78.     }
  79.  
  80.     public String Version() {
  81.         return "1.2";
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement