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.

Fog originates from vertex position instead of player position in RenderWorldLastEvent

Featured Replies

Posted

I'm rendering some things in RenderWorldLastEvent and would like to have fog applied to them. However when I enable fog, it originates from vertex position instead of player position.

NYqieH7.png

Here's my code:

Tessellator tess = Tessellator.getInstance();
BufferBuilder buffer = tess.getBuffer();

GlStateManager.pushMatrix();
RenderHelper.translateToZero();

GlStateManager.disableTexture2D();
GlStateManager.color(1, 0, 0);
GlStateManager.disableCull();
GlStateManager.enableFog();

buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);

buffer.pos(0, 100, 0).endVertex();
buffer.pos(-1.1, 100, 0).endVertex();
buffer.pos(-100, 100, 0).endVertex();
buffer.pos(-101.1, 100, 0).endVertex();

tess.draw();

GlStateManager.disableFog();
GlStateManager.enableCull();
GlStateManager.enableTexture2D();

GlStateManager.popMatrix();

And this is the translateToZero() method:

public static void translateToZero() {
	Entity entity = mc.getRenderViewEntity();
	float partialTicks = mc.getRenderPartialTicks();

	GlStateManager.translate(
		-(entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks),
		-(entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks),
		-(entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks)
	);
}

Do I need to draw my quads in a different way? I've never done anything with OpenGL fog.

Edited by Silly511

You might want to contact TheGreyGhost. He does a fair bit with GL.

 

Otherwise, you need to debug the old fashioned way. You are already right to be suspicious of the translate to zero method. So maybe print out the values and get a sense of what is happening. I expect it is something wrong with the math that will become obvious.

 

For example one thing may be that by the time the render happens the current position and the last tick position may be equal to each other (since at some point in the tick the last tick position must copy the current position and the current position will get updated later). That's my guess.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.