Jump to content

[1.5.2] Transparency in GUI [SOLVED]


OsipXD

Recommended Posts

Hello,

 

I'm trying to draw a translucent rectangle with Gui.drawRect(); But I did not get :-(

What am I doing wrong?

[spoiler=Code]

@ForgeSubscribe(priority = EventPriority.NORMAL)
public void renderDebugMonitor(RenderGameOverlayEvent event)
{
    ScaledResolution res = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight);

    posX = res.getScaledWidth() - spaceRigth;

    // Draw background
    // posX, posY, descSpace, spaceRight and fontRender is global staic varibles
    int x1 = posX - descSpace - 5;
    int y1 = posY + 8 * (this.fontRender.FONT_HEIGHT + 2) + 5;
    int x2 = posX + 5;
    int y2 = posY - 5;
    Color color = new Color(85, 75, 59, 140); // Alfa is 140, but a rectangle is not translucent

    drawRect(x1, y1, x2, y2, color.getRGB());
}

 

[spoiler=Screenshot]sqjh.png

 

 

Sorry for my bad English, it's not my first language.

Link to comment
Share on other sites

Thanks for the advice, but method darwRect() contains this.

[spoiler=Gui.drawRect()]

/**
* Draws a solid color rectangle with the specified coordinates and color. Args: x1, y1, x2, y2, color
*/
public static void drawRect(int par0, int par1, int par2, int par3, int par4)
{
    int j1;

    if (par0 < par2)
    {
        j1 = par0;
        par0 = par2;
        par2 = j1;
    }

    if (par1 < par3)
    {
        j1 = par1;
        par1 = par3;
        par3 = j1;
    }

    float f = (float)(par4 >> 24 & 255) / 255.0F;
    float f1 = (float)(par4 >> 16 & 255) / 255.0F;
    float f2 = (float)(par4 >> 8 & 255) / 255.0F;
    float f3 = (float)(par4 & 255) / 255.0F;
    Tessellator tessellator = Tessellator.instance;
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(f1, f2, f3, f);
    tessellator.startDrawingQuads();
    tessellator.addVertex((double)par0, (double)par3, 0.0D);
    tessellator.addVertex((double)par2, (double)par3, 0.0D);
    tessellator.addVertex((double)par2, (double)par1, 0.0D);
    tessellator.addVertex((double)par0, (double)par1, 0.0D);
    tessellator.draw();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_BLEND);
}

 

Link to comment
Share on other sites

Oh... it's a pity :sad:... Thanks for trying to help

 

P.S. I tried to write the method drawRect without tessellator. When I add the last line GL11.glLoadIdentity(); rectangle becomes transparent, but a new problem arises. All included as a standard GUI becomes invisible. Without this line, rectangle, still not transparent.

[spoiler=Code]

/**
* Draws a solid color rectangle with the specified coordinates and color. Args: x1, y1, x2, y2, color
*/
public static void drawRect(int par0, int par1, int par2, int par3, int par4)
{
    int j1;

    if (par0 < par2)
    {
        j1 = par0;
        par0 = par2;
        par2 = j1;
    }

    if (par1 < par3)
    {
        j1 = par1;
        par1 = par3;
        par3 = j1;
    }

    float f = (float)(par4 >> 24 & 255) / 255.0F;
    float f1 = (float)(par4 >> 16 & 255) / 255.0F;
    float f2 = (float)(par4 >> 8 & 255) / 255.0F;
    float f3 = (float)(par4 & 255) / 255.0F;

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(f1, f2, f3, f);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2f((float) par0, (float) par3);
    GL11.glVertex2f((float) par2, (float) par3);
    GL11.glVertex2f((float) par2, (float) par1);
    GL11.glVertex2f((float) par0, (float) par1);
    GL11.glEnd();
    GL11.glDisable(GL11.GL_BLEND);
    // ** THE MAGIC BEGINS **
    GL11.glLoadIdentity();
    // ** MAGIC ENDS ***
}

 

[spoiler=Screenshot]H86MG1l.png

 

I almost do not know how to use LWJGL. Help please.

Link to comment
Share on other sites

Hi

 

That suggests to me that the reason your transparent rectangle is not transparent is because another part of the GUI is drawing over the top of your transparent rectangle.  GL11.glLoadIdentity might be making it render somewhere offscreen.

 

Instead of    GL11.glLoadIdentity(), you could try a GL11.glTranslatef or GL11.glScalef to see whether you get both your alpha rectangle and something else on the screen too.  Might be a useful clue.

 

-TGG

 

 

Link to comment
Share on other sites

This is code I've used, mostly borrowed from Draco and slightly modified, with drawTexturedModalRect (not the method you're using, I realize) that works for getting transparency:

GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(false);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_ALPHA_TEST);
drawTexturedModalRect(xPos, yPos, 0, 0, 56, 9);

Be sure you re-enable or disable whatever you disabled/enabled when you're finished. I don't know much about openGL, so there is probably a better / more efficient way of doing it, and it again it isn't the method you're looking for but maybe you can use drawTexturedModalRect instead. Good luck!

Link to comment
Share on other sites

@TheGreyGhost Thanks a lot. I wrote GL11.glTranslatef(0.0f, 0.0f,-1.0f), and that helped. But I'm not quite sure what it is the right decision. Is not it bad form?

 

@coolAlias Thanks for the advice. I've tried it, but it did not help.

 

P.S. I like it :3

[spoiler=Screenshot]6km6.png

 

Link to comment
Share on other sites

Hi

 

keen, that's a useful clue.

 

The effect of GL11.glTranslate(0.0f, 0.0f, -1.0f) shows that there is almost certainly another part of the code which is drawing an opaque rectangle over the top of your alpha rectangle.

 

So ideally it would be best to go find that and turn it off, rather than "fix" it with the translate.

 

Perhaps you could trace through step by step with a debugger to see if another rect is drawn over the top of yours.  Or alternatively you could look through the I don't have forge on this pc, perhaps there is an obvious method like "drawBackground" or something.

 

Also - perhaps you need to "cancel" the event before returning from it, to stop the vanilla code from drawing the normal gui screen?

 

-TGG

 

 

 

Link to comment
Share on other sites

The problem is you are using the event wrong.

RenderGameOverlayEvent is a parent event, with a *-load of children.

You need to specify at which step of the event you do the rendering (Pre, or Post ?), and which child event (ElementType) to use. Without that, you are doing the rendering multiple times in the same rendering cycle.

Which basically mean you are rendering your own gui on top of itself.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
    • Create a new instance and start with Embeddium/Oculus and Valkyrien Skies Try different builds of Embeddium/Valkyrien Skies until you find a working combination - then add the rest of your mods one by one or in groups
    • There are some mods missing Missing or unsupported mandatory dependencies: Mod ID: 'octolib', Requested by: 'ramcompat', Expected range: '[0.1,)', Actual version: '[MISSING]' Mod ID: 'forge', Requested by: 'tfc', Expected range: '[47.1.3,47.1.6),[47.1.81,47.2.0),[47.2.6,)', Actual version: '47.2.0' Mod ID: 'relics', Requested by: 'ramcompat', Expected range: '[0.6.5,)', Actual version: '[MISSING]' Add octolib and relics and update tfc to build 47.2.6
    • Make a test with adding LMFT https://www.curseforge.com/minecraft/mc-mods/lmft
  • Topics

×
×
  • Create New...

Important Information

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