Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8] Drawing enchantment glint over a regular quad


Recommended Posts

I've been able to draw the enchantment effect over a quad in 1.7.10, using the following method:

/** Bits which are modified while rendering item glints, so must be pushed/popped.
     * @see #drawTexturedGlintRect(int, int, int, int, int, int) */
    public static final int GL_GLINT_BITS =
            GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_TRANSFORM_BIT |
            GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT;

    /** Render an 'item glint' over the specified quad with the currently bound texture for clipping.
     * @param x X coordinate of the top-left
     * @param y Y coordinate of the top-left
     * @param u Texture X coordinate, in pixels
     * @param v Texture Y coordinate, in pixels
     * @param width The width of the quad to draw, in pixels
     * @param height The height of the quad to draw, in pixels
     * @see ItemRenderer#renderItem(net.minecraft.entity.EntityLivingBase, ItemStack, int, net.minecraftforge.client.IItemRenderer.ItemRenderType) */
    public void drawTexturedGlintRect(int x, int y, int u, int v, int width, int height) {
        mc.mcProfiler.startSection("glint");
        // Push bits we modify to restore later on
        glPushAttrib(GL_GLINT_BITS);

        glDepthFunc(GL_EQUAL);
        glDisable(GL_LIGHTING);
        glEnable(GL_BLEND);
        // Mapped OpenGL constants from [768, 1, 1, 0]
        OpenGlHelper.glBlendFunc(GL_SRC_COLOR, GL_ONE, GL_ONE, GL_ZERO);

        glColor4f(0.38F, 0.19F, 0.608F, 1.0F); // #61309B, light purple tint
        mc.getTextureManager().bindTexture(RES_ITEM_GLINT);

        glMatrixMode(GL_TEXTURE);

        long time = Minecraft.getSystemTime();

        // Rect #1
        glPushMatrix();
        glScalef(0.125F, 0.125F, 0.125F);
        glTranslatef((float) (time % 3000L) / 3000.0F * 8.0F, 0.0F, 0.0F);
        glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
        this.drawTexturedModalRect(x, y, u, v, width, height);
        glPopMatrix();

        // Rect #2
        glPushMatrix();
        glScalef(0.125F, 0.125F, 0.125F);
        glTranslatef((float) (time % 4873L) / 4873.0F * -8.0F, 0.0F, 0.0F);
        glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
        this.drawTexturedModalRect(x, y, u, v, width, height);
        glPopMatrix();

        glPopAttrib();
        mc.mcProfiler.endSection();
    }

 

This works perfectly, if I run it after drawTexturedModalRect. It was ripped and slightly modified from vanilla's method for rendering over items, but since item rendering has changed a lot between 1.7.10 and 1.8 it no longer works. The new method of rendering items seems to be so complicated that I can't find any new method of doing this.

 

In 1.8, this code sort of works correctly, for the first quad I draw it over. Any further quads cause the texture to remain blank for most of the time, then very quickly the entire enchantment texture moves across the quad and disappears again for a second or two. Any ideas on how this same effect can be achieved in 1.8?

Link to post
Share on other sites

In 1.8, this code sort of works correctly, for the first quad I draw it over. Any further quads cause the texture to remain blank for most of the time, then very quickly the entire enchantment texture moves across the quad and disappears again for a second or two. Any ideas on how this same effect can be achieved in 1.8?

Not directly a solution, but the error on the additional quads sounds like an undersized UV area. I've messed around previously with the Glint for a shield esque overlay and when its UV coords aren't displaced enough you get gaps akin to what you've described because it 'zooms' in on the textures.

I think its my java of the variables.

Link to post
Share on other sites

In 1.8, this code sort of works correctly, for the first quad I draw it over. Any further quads cause the texture to remain blank for most of the time, then very quickly the entire enchantment texture moves across the quad and disappears again for a second or two. Any ideas on how this same effect can be achieved in 1.8?

Not directly a solution, but the error on the additional quads sounds like an undersized UV area. I've messed around previously with the Glint for a shield esque overlay and when its UV coords aren't displaced enough you get gaps akin to what you've described because it 'zooms' in on the textures.

Why would the UVs have changed at all between me rendering these two quads (the only thing inbetween is a regular quad, drawTexturedModalRect). I wouldn't thought it was some OpenGL state that's now changed in 1.8... Hmm. I wish I could say I had any ideas.

Link to post
Share on other sites

I couldn't tell you with certainty, but if you're seeing the artifacts of the texture then it's likely a uv scaling/ timing issue... do you mind showing where/how you're invoking this?

GitHub. This is for 1.7.10, but none of the code has changed apart from things like replacing .addVertexWithUV from Tessellator to WorldRenderer.

Link to post
Share on other sites

width=800 height=450Screenshot%202016-01-28%2008.37.52.png?d [/img]

Got this from snagging RenderItem.renderEffect(IBakedModel) and replacing model rendering with

Minecraft.getMinecraft().ingameGUI.drawTexturedModalRect(0,0,0,0,scaledWidth, scaledHeight);

and it worked fine as far as speed and such goes.... So comparing against this and looking at your code I *think* I see the culprit:

 

this.drawTexturedGlintRect(left + this.left, this.top, (int) uv.x, (int) uv.y, 5, 9);

your UV is set to a specific slot... try forcing it to use the full Glint texture instead of a portion of it.

I think its my java of the variables.

Link to post
Share on other sites

FIXED! The solution wasn't exactly what you said, but your findings did cause me to look into a few things. First, I rendered the whole texture so I could see better, then I looked into RenderItem#renderEffect(). I found that some of my calculations were weirdly flipped (*8 instead of /8, for example). I think this was actually part of a previous attempt to fix the problem, someone suggested using the reciprocal. Either way, that caused the animation to work properly again (did have to mess around with the bound texture, though...)

 

Thank you RANKSHANK!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • sorry i will talk in english. there is the debug.log of server and the client debug.log debug.log
    • Aww thanks i guess... Makes sense now.
    • I showed you that code...    it was this, and your 'complained' about the deferred register name, then went on about Objectholder (which to be fair was only there because the ONLY other example of doing this wasn't exactly knowledgeable as to what was happening or why. I'm trying to figure out why the following works, and the example wasn't exactly updated, so i had to use IDE feedback to get it to work properly, and I used setRegistryName as a way to prevent it from using my own name space....    -- To be clear i'm not sure what i did that caused it to work..  but it does Just to be clear  This is sitting where the package says it's sitting.   -mine are sitting in com.dephoegon.reclaim....   package net.minecraft; import com.dephoegon.reclaim.aid.block.sand; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.material.MaterialColor; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraftforge.common.ToolType; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.ObjectHolder; @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public class blockoverrides { public static final Block SAND = new sand(14406560, AbstractBlock.Properties.create(Material.SAND, MaterialColor.SAND) .harvestTool(ToolType.SHOVEL).harvestLevel(0) .hardnessAndResistance(0.5F).sound(SoundType.SAND) , "", "", "", true).setRegistryName("minecraft", "sand"); @SubscribeEvent public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) { blockRegistryEvent.getRegistry().registerAll ( SAND ); } public static final Item SAND_ITEM = new BlockItem(SAND, new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)).setRegistryName("minecraft","sand"); @SubscribeEvent public static void registerItems(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll ( SAND_ITEM ); } }  
    • From what I can .. gather, and I'm sure this is my confusion going on..        It has public Objects that are effectively the block registry calls. Wait?  Would it be possible to actually override a public object, and have it use it? ---      I'm not sure I understand,   though the only bit I can honestly gather from that is a string name key, & the block object calling a new instance of a block (sand, log, etc) with properties defined in those block classes, which are often calling abstractblocks for properties, and extending special classes (like fallingblock) which tend to fall onto blocks, then abstract blocks themselves.   perhaps I'm missing the forest for the trees (or missing the trees for the forest), but  I'm not getting how you meant that.
    • Oh hold on, I forgot about the refresh gradle option. I refreshed the project and it downloaded new jars. That's weird, the last time I opened the workspace and started the game, it was working fine. Sorry for wasting your time. 😓
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.