我希望渲染一个类似这样的Hud,但是我目前只会渲染文字,不会渲染图片。
有没有相关的教程链接?已经看了好几篇国内/外的教程,但是普遍只教普通的有格子的Gui,但是很少有关于hud的渲染教程。
- public class RenderGuiHandler {
- @SubscribeEvent
- public void onRenderGui(RenderGameOverlayEvent.Post event) {
- if (event.getType() != RenderGameOverlayEvent.ElementType.EXPERIENCE) return;
- new GuiNotif(Minecraft.getMinecraft());
- }
- }
- public class GuiNotif extends Gui
- {
- String text = "Hello world!";
- public GuiNotif(Minecraft mc)
- {
- ScaledResolution scaled = new ScaledResolution(mc);
- int width = scaled.getScaledWidth();
- int height = scaled.getScaledHeight();
- drawCenteredString(mc.fontRenderer, text,
- width*1 / 4,
- (height*9 / 10) - 4,
- Integer.parseInt("FFAA00", 16));
- }
- }
使用mc.renderEngine先绑定贴图,然后使用Gui.drawModalRectWithCustomSizedTexture绘制贴图
复制代码
- mc.renderEngine.bindTexture(new ResourceLocation(ClientMod.MODID, "xxxxx.png"));
- Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 0, width,height,width, height);
本帖最后由 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源代码。
https://github.com/ModularMods/M ... ient/hud/GunUI.java
你找个mod抄不就完了
这种东西吧
你要是不想深究
你就直接在RenderGameOverlayEvent调用GUI类的drawModalRectWithCustomSizedTexture之类的直接画就完事了
你要是想搞懂。
你还是必须学习opengl并自己阅读mc的渲染代码,搞懂他的工作过程。
http://buhuibaidu.me/?s=LearnOpengl
最后 开发forgemod不同于开发bukkit插件,这玩意几乎没有文档,国内外教程都很少(国内就更少了)
所以你只能靠自己阅读mc源代码。