diff --git a/SpecialSource-1.5-SNAPSHOT-shaded.jar b/SpecialSource-1.5-SNAPSHOT-shaded.jar deleted file mode 100644 index db85a28..0000000 Binary files a/SpecialSource-1.5-SNAPSHOT-shaded.jar and /dev/null differ diff --git a/SpecialSource-License.txt b/SpecialSource-License.txt deleted file mode 100644 index f887127..0000000 --- a/SpecialSource-License.txt +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2012, md_5. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this -list of conditions and the following disclaimer. - -Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - -The name of the author may not be used to endorse or promote products derived -from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. diff --git a/build.xml b/build.xml index b0ce14e..eb1c1b8 100644 --- a/build.xml +++ b/build.xml @@ -6,10 +6,10 @@ - + - - + + @@ -29,7 +29,7 @@ - + @@ -49,13 +49,27 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -104,7 +118,7 @@ - + - + + + + + + + + + + + @@ -159,6 +183,10 @@ + + + + diff --git a/src/itemrender/ItemRenderMod.java b/src/itemrender/ItemRenderMod.java index efac61a..d5d862d 100644 --- a/src/itemrender/ItemRenderMod.java +++ b/src/itemrender/ItemRenderMod.java @@ -19,21 +19,27 @@ public class ItemRenderMod { public static boolean gl32_enabled = false; - @Mod.PreInit + public static final int DEFAULT_TEXTURE_SIZE = 128; + public static final int GRID_TEXTURE_SIZE = 32; + + @Mod.EventHandler public void preInit(FMLPreInitializationEvent e) { gl32_enabled = GLContext.getCapabilities().OpenGL32; } - @Mod.Init + @Mod.EventHandler public void init(FMLInitializationEvent e) { if(gl32_enabled) { TickRegistry.registerTickHandler(new RenderTickHandler(), Side.CLIENT); - KeyBindingRegistry.registerKeyBinding(new KeybindRenderInventoryBlock()); + KeybindRenderInventoryBlock defaultRender = new KeybindRenderInventoryBlock(DEFAULT_TEXTURE_SIZE, ""); + RenderTickHandler.keybindToRender = defaultRender; + KeyBindingRegistry.registerKeyBinding(defaultRender); + KeyBindingRegistry.registerKeyBinding(new KeybindRenderInventoryBlock(GRID_TEXTURE_SIZE, "_grid")); KeyBindingRegistry.registerKeyBinding(new KeybindToggleRender()); } } - @Mod.PostInit + @Mod.EventHandler public void postInit(FMLPostInitializationEvent e) { } } diff --git a/src/itemrender/client/KeybindRenderInventoryBlock.java b/src/itemrender/client/KeybindRenderInventoryBlock.java index a9facd3..83830a3 100644 --- a/src/itemrender/client/KeybindRenderInventoryBlock.java +++ b/src/itemrender/client/KeybindRenderInventoryBlock.java @@ -34,17 +34,26 @@ public class KeybindRenderInventoryBlock extends KeyBindingRegistry.KeyHandler { new KeyBinding[]{new KeyBinding("Render Inventory Block", Keyboard.KEY_P)}; private static boolean[] repeatings = new boolean[]{false}; - private static final int RENDER_TEXTURE_SIZE = 128; + private int renderTextureSize = 128; - public static int framebufferID = -1; - public static int depthbufferID = -1; - public static int textureID = -1; + public int framebufferID = -1; + public int depthbufferID = -1; + public int textureID = -1; + + private String filenameSuffix = ""; private RenderItem itemRenderer = new RenderItem(); - public KeybindRenderInventoryBlock() { + public KeybindRenderInventoryBlock(int textureSize, String filename_suffix) { super(keyBindings, repeatings); + renderTextureSize = textureSize; + filenameSuffix = filename_suffix; + + createFramebuffer(); + } + + private void createFramebuffer() { framebufferID = GL30.glGenFramebuffers(); textureID = GL11.glGenTextures(); int currentTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); @@ -57,7 +66,7 @@ public KeybindRenderInventoryBlock() { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); - GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE, 0, GL12.GL_BGRA, + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, renderTextureSize, renderTextureSize, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null); // Restore old texture @@ -66,7 +75,7 @@ public KeybindRenderInventoryBlock() { // Create depth buffer depthbufferID = GL30.glGenRenderbuffers(); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthbufferID); - GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE); + GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, renderTextureSize, renderTextureSize); // Bind depth buffer to the framebuffer GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, depthbufferID); @@ -78,6 +87,18 @@ public KeybindRenderInventoryBlock() { GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); } + private void deleteFramebuffer() { + GL30.glDeleteFramebuffers(framebufferID); + GL11.glDeleteTextures(textureID); + GL30.glDeleteRenderbuffers(depthbufferID); + } + + public void resizeFramebuffer(int newSize) { + deleteFramebuffer(); + renderTextureSize = newSize; + createFramebuffer(); + } + @Override public void keyDown(EnumSet types, KeyBinding kb, boolean tickEnd, boolean isRepeat) { if(!tickEnd) return; @@ -91,7 +112,7 @@ public void keyDown(EnumSet types, KeyBinding kb, boolean tickEnd, boo // Remember viewport info. IntBuffer viewportInfo = GLAllocation.createDirectIntBuffer(16); GL11.glGetInteger(GL11.GL_VIEWPORT, viewportInfo); - GL11.glViewport(0, 0, RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE); + GL11.glViewport(0, 0, renderTextureSize, renderTextureSize); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); @@ -149,16 +170,16 @@ public void keyDown(EnumSet types, KeyBinding kb, boolean tickEnd, boo IntBuffer texture = BufferUtils.createIntBuffer(width * height); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, texture); - //GL11.glReadPixels(0, 0, RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, texture); + //GL11.glReadPixels(0, 0, renderTextureSize, renderTextureSize, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, texture); int[] texture_array = new int[width * height]; texture.get(texture_array); BufferedImage image = - new BufferedImage(RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE, BufferedImage.TYPE_INT_ARGB); - image.setRGB(0, 0, RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE, texture_array, 0, width); + new BufferedImage(renderTextureSize, renderTextureSize, BufferedImage.TYPE_INT_ARGB); + image.setRGB(0, 0, renderTextureSize, renderTextureSize, texture_array, 0, width); File file = new File(minecraft.mcDataDir, - String.format("rendered/item_%d_%d.png", current.getItem().itemID, current.getItemDamage())); + String.format("rendered/item_%d_%d%s.png", current.getItem().itemID, current.getItemDamage(), filenameSuffix)); file.mkdirs(); try { ImageIO.write(image, "png", file); diff --git a/src/itemrender/client/RenderTickHandler.java b/src/itemrender/client/RenderTickHandler.java index 454df6c..197b0a5 100644 --- a/src/itemrender/client/RenderTickHandler.java +++ b/src/itemrender/client/RenderTickHandler.java @@ -11,6 +11,7 @@ @SideOnly(Side.CLIENT) public class RenderTickHandler implements ITickHandler { public static boolean renderPreview = false; + public static KeybindRenderInventoryBlock keybindToRender; public RenderTickHandler() { } @@ -21,11 +22,11 @@ public void tickStart(EnumSet type, Object... tickData) { @Override public void tickEnd(EnumSet type, Object... tickData) { - if(renderPreview) { + if(keybindToRender != null && renderPreview) { int originalTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); // Bind framebuffer texture - GL11.glBindTexture(GL11.GL_TEXTURE_2D, KeybindRenderInventoryBlock.textureID); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, keybindToRender.textureID); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0, 0); GL11.glVertex2i(0, 0);