byxiaobai

我希望渲染一个类似这样的Hud,但是我目前只会渲染文字,不会渲染图片。

有没有相关的教程链接?已经看了好几篇国内/外的教程,但是普遍只教普通的有格子的Gui,但是很少有关于hud的渲染教程。

  1. public class RenderGuiHandler {
  2.     @SubscribeEvent
  3.     public void onRenderGui(RenderGameOverlayEvent.Post event) {
  4.         if (event.getType() != RenderGameOverlayEvent.ElementType.EXPERIENCE) return;
  5.         new GuiNotif(Minecraft.getMinecraft());

  6.     }
  7. }
复制代码

  1. public class GuiNotif extends Gui
  2. {
  3.     String text = "Hello world!";

  4.     public GuiNotif(Minecraft mc)
  5.     {
  6.         ScaledResolution scaled = new ScaledResolution(mc);
  7.         int width = scaled.getScaledWidth();
  8.         int height = scaled.getScaledHeight();
  9.         drawCenteredString(mc.fontRenderer, text,
  10.                 width*1 / 4,
  11.                 (height*9 / 10) - 4,
  12.                 Integer.parseInt("FFAA00", 16));
  13.     }

  14. }
复制代码



隔壁老吕
使用mc.renderEngine先绑定贴图,然后使用Gui.drawModalRectWithCustomSizedTexture绘制贴图
  1. mc.renderEngine.bindTexture(new ResourceLocation(ClientMod.MODID, "xxxxx.png"));
  2. Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 0, width,height,width, height);
复制代码

Hueihuea
本帖最后由 Hueihuea 于 2022-2-18 21:13 编辑

https://github.com/ModularMods/M ... ient/hud/GunUI.java
你找个mod抄不就完了
这种东西吧
你要是不想深究
你就直接在RenderGameOverlayEvent调用GUI类的drawModalRectWithCustomSizedTexture之类的直接画就完事了
你要是想搞懂。
你还是必须学习opengl并自己阅读mc的渲染代码,搞懂他的工作过程。
http://buhuibaidu.me/?s=LearnOpengl

最后 开发forgemod不同于开发bukkit插件,这玩意几乎没有文档,国内外教程都很少(国内就更少了)
所以你只能靠自己阅读mc源代码。