Posted December 27, 20213 yr I am trying to draw a simple icon on the screen. For starters, I thought I'd just try and draw part of an existing 256x256 texture so that I have the basic concepts working. I have the following code: public static void RenderGameOverlayEvent(RenderGameOverlayEvent.Post event) { Minecraft minecraft = Minecraft.getInstance(); TextureManager tm = minecraft.getTextureManager(); ResourceLocation rl = new ResourceLocation("minecraft", "textures/gui/recipe_book.png"); RenderSystem.setShader(GameRenderer::getPositionTexShader); tm.bindForSetup(rl); // tried with and without this RenderSystem.enableTexture(); // tried with and without this RenderSystem.bindTexture(tm.getTexture(rl).getId()); // tried with and without this RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0f); GuiUtils.drawTexturedModalRect(event.getMatrixStack(), 0, 0, 0, 0, 16, 16, 0); } And this is what gets rendered in-game (garbage): I have found that, even if I omit the calls for binding texture entirely, it makes no difference to the image. So I assume that I am not setting the texture correctly (my calls are effectively noops). I have searched the code, forum and google for examples of how to do this drawing correctly but as far as I can tell I'm doing the same as others for whom it is working. Can anyone see what I'm missing / doing wrong? Many thanks.
December 27, 20213 yr Author I did see that as an alternative approach, and I tried to understand how OverlayRegistry works but couldn't see any usage examples. I found classes that call register but could not find any places where the registered items were subsequently used. Could you point me at an example or docs on how to use OverlayRegistry? Also, is there a reason why my approach above doesn't work (apparently it works for other people) ?
January 1, 20223 yr Author tysm I have it working now. Doing it via OverlayRegistry as follows works: MyHudOverlay = OverlayRegistry.registerOverlayTop("MyHudOverlay", (gui, mStack, partialTicks, screenWidth, screenHeight) -> { Minecraft minecraft = Minecraft.getInstance(); if (minecraft.gameMode == null) return; if (minecraft.level == null) return; TextureManager tm = minecraft.getTextureManager(); ResourceLocation rl = new ResourceLocation("minecraft", "textures/gui/recipe_book.png"); gui.setupOverlayRenderState(true, false, rl); RenderSystem.setShader(GameRenderer::getPositionTexShader); tm.bindForSetup(rl); RenderSystem.enableTexture(); RenderSystem.bindTexture(tm.getTexture(rl).getId()); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0f); GuiUtils.drawTexturedModalRect(new PoseStack(), 0, 0, 0, 0, 16, 16, 0); }); I also found that the key thing my original code was missing was RenderSystem.setShaderTexture(0, res); (which is called inside setupOverlayRenderState) If I use that with my original code instead of using OverlayRegistry, I also get the desired result. Is there a reason/benefit to using OverlayRegistry for this task rather than RenderGameOverlayEvent ? Edited January 1, 20223 yr by Marshall7
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.