Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey Guys!

I wanted to create a renderer for a tile entity to show a title for the Block.

The Problem is that the plain face is just rendered black and the water can be seen through it.

Why?

 

(PS: The normal block isn't opaque, but I don't think that's the error)

@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float var8) {
	String title = ((TileEntityReadableBookshelf)te).bookTitle;
	Main.logPlainText(" " + title);

	FontRenderer fontrenderer = this.func_147498_b();
        GL11.glPushMatrix();
        GL11.glTranslatef((float)x + 0.5F, (float)y + 0.75F, (float)z + 0.5F);
        GL11.glRotatef(180, 0, 0, 1);
        GL11.glRotatef(Minecraft.getMinecraft().thePlayer.rotationYawHead, 0, 1, 0);
        GL11.glTranslatef(0.0F, 0.0F, -0.75F);
        GL11.glNormal3f(0.0F, 0.0F, 1.0F);
        GL11.glScalef(0.03F, 0.03F, 0.03F);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDepthMask(false);
        GL11.glEnable(GL11.GL_BLEND);
        OpenGlHelper.glBlendFunc(770, 771, 1, 0);
        Tessellator tessellator = Tessellator.instance;
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        tessellator.startDrawingQuads();
        int i = fontrenderer.getStringWidth(title) / 2;
        tessellator.setColorOpaque(255, 0, 0);      //Seems to have no effect!
        tessellator.addVertex(-i - 1, -1.0D, 0.0D);
        tessellator.addVertex(-i - 1, 8.0D, 0.0D);
        tessellator.addVertex(i + 1, 8.0D, 0.0D);
        tessellator.addVertex(i + 1, -1.0D, 0.0D);
        tessellator.draw();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glDepthMask(true);
        tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);  //Also no effect!
        fontrenderer.drawString(title, -fontrenderer.getStringWidth(title) / 2, 0, 16777215);
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glPopMatrix();
}

Hi

 

If you want the face to be opaque, you should turn off BLEND before rendering.

i.e.

GL11.glDisable(GL11.GL_BLEND);

You probably also don't want to disable the depth mask before rendering the face, otherwise entities that are behind the face might render over the top of it if they're drawn afterwards.

GL11.glDepthMask(true);

 

-TGG

 

 

 

  • Author

I just copied the code from the rendering of Entity names.

 

@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float var8) {
	String title = ((TileEntityReadableBookshelf)te).bookTitle;

	FontRenderer fontrenderer = this.func_147498_b();
        GL11.glPushMatrix();
        GL11.glTranslatef((float)x + 0.5F, (float)y + 0.75F, (float)z + 0.5F);
        GL11.glRotatef(180, 0, 0, 1);
        GL11.glRotatef(Minecraft.getMinecraft().thePlayer.rotationYawHead, 0, 1, 0);
        GL11.glTranslatef(0.0F, 0.0F, -0.75F);
        GL11.glNormal3f(0.0F, 0.0F, 1.0F);
        GL11.glScalef(0.03F, 0.03F, 0.03F);

        GL11.glEnable(GL11.GL_ALPHA_TEST);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDepthMask(false);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glEnable(GL11.GL_BLEND);
        OpenGlHelper.glBlendFunc(770, 771, 1, 0);
        Tessellator tessellator = Tessellator.instance;
        byte b0 = 0;

        GL11.glDisable(GL11.GL_TEXTURE_2D);
        tessellator.startDrawingQuads();
        int j = fontrenderer.getStringWidth(title) / 2;
        tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.25F);
        tessellator.addVertex(-j - 1, -1 + b0, 0.0D);
        tessellator.addVertex(-j - 1, 8 + b0, 0.0D);
        tessellator.addVertex(j + 1, 8 + b0, 0.0D);
        tessellator.addVertex(j + 1, -1 + b0, 0.0D);
        tessellator.draw();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        fontrenderer.drawString(title, -fontrenderer.getStringWidth(title) / 2, b0, 553648127);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDepthMask(true);
        fontrenderer.drawString(title, -fontrenderer.getStringWidth(title) / 2, b0, -1);
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glPopMatrix();
}

 

 

This is the effect:

q41tpoV.png

Before the line

GL11.glEnable(GL11.GL_ALPHA_TEST);

 

put this piece of code inside:

int bright = 0xF0;
int brightX = bright % 65536;
int brightY = bright / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, brightX, brightY);

It should brighten your render stuff up. The bright integer can range from 0x00 (complete darkness) to 0xF0 (complete brightness).

 

If it doesn't work, put it before

tessellator.startDrawingQuads();

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

  • Author

Before the line

GL11.glEnable(GL11.GL_ALPHA_TEST);

 

put this piece of code inside:

int bright = 0xF0;
int brightX = bright % 65536;
int brightY = bright / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, brightX, brightY);

It should brighten your render stuff up. The bright integer can range from 0x00 (complete darkness) to 0xF0 (complete brightness).

 

If it doesn't work, put it before

tessellator.startDrawingQuads();

 

Works fine ! Thanks!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.