Jump to content

[1.16.5] Rendering text in GUI causes all future rendering to fail


DARKHAWX

Recommended Posts

So I've got myself a GUI similar to that of the Advancements screen or the Creative screen where I've got a main screen that renders the window, and tabs that render their own info.

Everything works fine and dandy, until I have one of the tabs render text. When that happens, all other text rendered by the screen, along with the tab icon are no longer rendered. There seemingly are no errors, and when I try debugging I can see that each code path is still called so I'm not sure what's going on.

So within my screen the main render function looks as follows

    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        int i = (this.width - GUI_WIDTH) / 2;
        int j = (this.height - GUI_HEIGHT) / 2;
        this.renderBackground(matrixStack);
        if (maxPages != 0) {
            ITextComponent page = new StringTextComponent(String.format("%d / %d", tabPage + 1, maxPages + 1));
            int width = this.font.width(page);
            RenderSystem.disableLighting();
            this.font.draw(matrixStack, page.getString(), i + (GUI_WIDTH / 2) - (width / 2), j - 44, -1);
        }
        this.drawWindowBackground(matrixStack, mouseX, mouseY, i, j);
        this.renderWindow(matrixStack, i, j);
        this.drawWindowTooltips(matrixStack, mouseX, mouseY, i, j);
    }

The errant line is within this.drawWindowBackground(matrixStack, mouseX, mouseY, i, j);. Here we render the tab window itself.

    private void drawWindowBackground(MatrixStack matrixStack, int mouseX, int mouseY, int offsetX, int offsetY) {
        if (this.selectedTab == null) {
            fill(matrixStack, offsetX + 9, offsetY + 18, offsetX + 9 + 234, offsetY + 18 + 113, -16777216);
            int i = offsetX + 9 + 117;
            drawCenteredString(matrixStack, this.font, EMPTY, i, offsetY + 18 + 56 - 9 / 2, -1);
            drawCenteredString(matrixStack, this.font, SAD_LABEL, i, offsetY + 18 + 113 - 9, -1);
        } else {
            RenderSystem.pushMatrix();
            RenderSystem.translatef((float)(offsetX + 9), (float)(offsetY + 18), 0.0F);
            this.selectedTab.drawTabBackground(matrixStack);
            RenderSystem.popMatrix();
            RenderSystem.depthFunc(515);
            RenderSystem.disableDepthTest();
        }
    }

From there the tab draws itself as follows:

    public void drawTabBackground(MatrixStack matrixStack) {
        if (!this.centered) {
            this.scrollX = 117 - (this.maxX + this.minX) / 2.0D;
            this.scrollY = 56 - (this.maxY + this.minY) / 2.0D;
            this.centered = true;
        }

        RenderSystem.pushMatrix();
        RenderSystem.enableDepthTest();
        RenderSystem.translatef(0.0F, 0.0F, 950.0F);
        RenderSystem.colorMask(false, false, false, false);
        fill(matrixStack, 4680, 2260, -4680, -2260, -16777216);
        RenderSystem.colorMask(true, true, true, true);
        RenderSystem.translatef(0.0F, 0.0F, -950.0F);
        RenderSystem.depthFunc(518);
        fill(matrixStack, MAX_WIDTH, MAX_HEIGHT, 0, 0, -16777216);
        RenderSystem.depthFunc(515);
        this.minecraft.getTextureManager().bind(background);
        int i = MathHelper.floor(this.scrollX);
        int j = MathHelper.floor(this.scrollY);
        int k = i % 16;
        int l = j % 16;

        for(int i1 = -1; i1 <= 15; ++i1) {
            for(int j1 = -1; j1 <= 8; ++j1) {
                blit(matrixStack, k + 16 * i1, l + 16 * j1, 0.0F, 0.0F, 16, 16, 16, 16);
            }
        }

        this.renderWindow(matrixStack);
        RenderSystem.depthFunc(518);
        RenderSystem.translatef(0.0F, 0.0F, -950.0F);
        RenderSystem.colorMask(false, false, false, false);
        fill(matrixStack, 4680, 2260, -4680, -2260, -16777216);
        RenderSystem.colorMask(true, true, true, true);
        RenderSystem.translatef(0.0F, 0.0F, 950.0F);
        RenderSystem.depthFunc(515);
        RenderSystem.popMatrix();
    }

And finally we get to the errant line: this.renderWindow(matrixStack);. This method is overridden by each tab and renders the content of the tab. For my tab it is simple, we render a piece of text at the center of the tab. This text renders fine, however it breaks the tab icon and window name.

    @Override
    protected void renderWindow(MatrixStack matrixStack) {
        ITextComponent divineFavourText = new TranslationTextComponent("screen.mesoamericamythology.divine_relationships.favour.divine_favour", this.getRelationship().getDivineFavour());
        // x, y, colour
        // This line breaks the rendering :(
        drawCenteredString(matrixStack, this.minecraft.font, divineFavourText, MAX_WIDTH / 2, MAX_HEIGHT / 2, Integer.parseInt("FFFFFF", 16));
    }

Below I have two screenshots. The one on the left is what the UI looks like when I don't draw the string in renderWindow. The right is what happens when I do.

yTbmbY9.png

I'm a little befuddled at the moment. Hoping someone has more pointers that would help me understand what is going on.

No signature for you!

Link to comment
Share on other sites

Here's the code which renders the GUI_LABEL and tab.drawIcon is called. It's called after drawWindowBackground (in code above) is called

    public void renderWindow(MatrixStack matrixStack, int offsetX, int offsetY) {
        RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
        RenderSystem.enableBlend();
        this.minecraft.getTextureManager().bind(WINDOW);
        this.blit(matrixStack, offsetX, offsetY, 0, 0, GUI_WIDTH, GUI_HEIGHT);
        if (this.tabs.size() >= 1) {
            this.minecraft.getTextureManager().bind(TABS);

            for (DivineRelationshipsTabGui tab : this.tabs) {
                if (tab.getPage() == tabPage) {
                    tab.renderTabSelectorBackground(matrixStack, offsetX, offsetY, tab == this.selectedTab);
                }
            }

            RenderSystem.enableRescaleNormal();
            RenderSystem.defaultBlendFunc();

            for (DivineRelationshipsTabGui tab : this.tabs) {
                if (tab.getPage() == tabPage)
                    tab.drawIcon(offsetX, offsetY, this.itemRenderer);
            }

            RenderSystem.disableBlend();
        }

        this.font.draw(matrixStack, GUI_LABEL, (float)(offsetX + 8), (float)(offsetY + 6), 4210752);
    }

drawIcon simply looks like the following. Where index is the tab number and stack is the item to render.

    public void drawIcon(int offsetX, int offsetY, int index, ItemRenderer renderItemIn, ItemStack stack) {
        int i = offsetX + this.getX(index);
        int j = offsetY + this.getY(index);
        switch(this) {
            case ABOVE:
                i += 6;
                j += 9;
                break;
            case BELOW:
                i += 6;
                j += 6;
                break;
        }

        renderItemIn.renderGuiItem(stack, i, j);
    }

I believe these are effectively clones of the Advancements screen code just with some code removed.

No signature for you!

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • ASIABET adalah pilihan terbaik bagi Anda yang mencari slot gacor hari ini dengan server Rusia dan jackpot menggiurkan. Berikut adalah beberapa alasan mengapa Anda harus memilih ASIABET: Slot Gacor Hari Ini Kami menyajikan koleksi slot gacor terbaik yang diperbarui setiap hari. Dengan fitur-fitur unggulan dan peluang kemenangan yang tinggi, Anda akan merasakan pengalaman bermain yang tak terlupakan setiap kali Anda memutar gulungan. Server Rusia yang Handal Kami menggunakan server Rusia yang handal dan stabil untuk memastikan kelancaran dan keadilan dalam setiap putaran permainan. Anda dapat bermain dengan nyaman tanpa khawatir tentang gangguan atau lag. Jackpot Menggiurkan Nikmati kesempatan untuk memenangkan jackpot menggiurkan yang dapat mengubah hidup Anda secara instan. Dengan hadiah-hadiah besar yang ditawarkan, setiap putaran permainan bisa menjadi peluang untuk meraih keberuntungan besar.
    • Sonic77 adalah pilihan tepat bagi Anda yang menginginkan pengalaman bermain slot yang unggul dengan akun pro Swiss terbaik. Berikut adalah beberapa alasan mengapa Anda harus memilih Sonic77: Slot Gacor Terbaik Kami menyajikan koleksi slot gacor terbaik dari provider terkemuka. Dengan fitur-fitur unggulan dan peluang kemenangan yang tinggi, Anda akan merasakan pengalaman bermain yang tak terlupakan. Akun Pro Swiss Berkualitas Kami menawarkan akun pro Swiss yang berkualitas dan terpercaya. Dengan akun ini, Anda dapat menikmati berbagai keuntungan eksklusif dan fasilitas premium yang tidak tersedia untuk akun reguler.
    • SV388 SITUS RESMI SABUNG AYAM 2024   Temukan situs resmi untuk sabung ayam terpercaya di tahun 2024 dengan SV388! Dengan layanan terbaik dan pengalaman bertaruh yang tak tertandingi, SV388 adalah tempat terbaik untuk pecinta sabung ayam. Daftar sekarang untuk mengakses arena sabung ayam yang menarik dan nikmati kesempatan besar untuk meraih kemenangan. Jelajahi sensasi taruhan yang tak terlupakan di tahun ini dengan SV388! [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]] [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]]   JURAGANSLOT88 SITUS JUDI SLOT ONLINE TERPERCAYA 2024 Jelajahi pengalaman judi slot online terpercaya di tahun 2024 dengan JuraganSlot88! Sebagai salah satu situs terkemuka, JuraganSlot88 menawarkan berbagai pilihan permainan slot yang menarik dengan layanan terbaik dan keamanan yang terjamin. Daftar sekarang untuk mengakses sensasi taruhan yang tak terlupakan dan raih kesempatan besar untuk meraih kemenangan di tahun ini dengan JuraganSlot88 [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]] [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]]
    • Slot Bank MEGA atau Daftar slot Bank MEGA bisa anda lakukan pada situs WINNING303 kapanpun dan dimanapun, Bermodalkan Hp saja anda bisa mengakses chat ke agen kami selama 24 jam full. keuntungan bergabung bersama kami di WINNING303 adalah anda akan mendapatkan bonus 100% khusus member baru yang bergabung dan deposit. Tidak perlu banyak, 5 ribu rupiah saja anda sudah bisa bermain bersama kami di WINNING303 . Tunggu apa lagi ? Segera Klik DAFTAR dan anda akan jadi Jutawan dalam semalam.
    • ladangtoto situs resmi ladangtoto situs terpercaya 2024   Temukan situs resmi dan terpercaya untuk tahun 2024 di LadangToto! Dengan layanan terbaik dan keamanan yang terjamin, LadangToto adalah pilihan utama untuk penggemar judi online. Daftar sekarang untuk mengakses berbagai jenis permainan taruhan, termasuk togel, kasino, dan banyak lagi. Jelajahi sensasi taruhan yang tak terlupakan dan raih kesempatan besar untuk meraih kemenangan di tahun ini dengan LadangToto!" [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]] [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]]
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.