Java Code Examples for org.lwjgl.opengl.GL11#glFogi()

The following examples show how to use org.lwjgl.opengl.GL11#glFogi() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FogInfo.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final void enableFog(float camera_z) {
	GL11.glFog(GL11.GL_FOG_COLOR, fog_color);
	GL11.glFogf(GL11.GL_FOG_MODE, fog_mode);
	GL11.glFogf(GL11.GL_FOG_START, computeFogOffset(camera_z) + fog_start);
	GL11.glFogf(GL11.GL_FOG_END, computeFogOffset(camera_z) + fog_end);
	GL11.glFogi(GL11.GL_FOG_MODE, fog_mode);
	GL11.glFogf(GL11.GL_FOG_DENSITY, computeFogDensityFactor(camera_z)*fog_density);
	GL11.glEnable(GL11.GL_FOG);
}
 
Example 2
Source File: ArtifactClientEventHandler.java    From Artifacts with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onFogRender(FogDensity event) {
	//Handle player "cloaking" with Obscurity component.
	Minecraft mc = Minecraft.getMinecraft();
	if((cloaked && !mc.thePlayer.isPotionActive(Potion.invisibility)) || mc.thePlayer.isPotionActive(Potion.blindness)) {
		cloaked = false;
	}
	
	//Make the fog max depend on the render distance.
	float fogMax = mc.gameSettings.renderDistanceChunks * 16;
	if(fogCurrent > fogMax) {
		fogCurrent = fogMax;
	}

       //Check if the effect should or shouldn't be applied (it shouldn't if the player already has a strong fog effect).
	if(!mc.thePlayer.isPotionActive(Potion.blindness) && !mc.thePlayer.isInsideOfMaterial(Material.water) && !mc.thePlayer.isInsideOfMaterial(Material.lava)) {
	   //Note to self - this didn't work that well: && !BlockQuickSand.headInQuicksand(mc.theWorld, MathHelper.floor_double(mc.thePlayer.posX), MathHelper.floor_double(mc.thePlayer.posY + mc.thePlayer.getEyeHeight()), MathHelper.floor_double(mc.thePlayer.posZ), mc.thePlayer)
		
		//If the player is cloaked, render the fog coming in. It stops when it reaches fogMin.
		if(cloaked) {
			event.setCanceled(true);
			if(fogCurrent > fogMin + 0.01) {
				fogCurrent -= (fogCurrent-fogMin)/fogMax * 0.3f;
			}
		}
		//Otherwise render the fog going out, then stop rendering when it reaches fogMax.
		else {
			if(fogCurrent < fogMax) {
				event.setCanceled(true);
				
				fogCurrent += 0.1f;
			}
		} 
	}
	else {
		//"Insta-move" the fog if it isn't rendering.
		if(cloaked) {
			fogCurrent = fogMin;
		}
		else {
			fogCurrent = fogMax;
		}
	}
	
	//Render the fog.
	if(event.isCanceled()) {
		GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_LINEAR);

		GL11.glFogf(GL11.GL_FOG_START, fogCurrent * 0.25F);
		GL11.glFogf(GL11.GL_FOG_END, fogCurrent);

		if (GLContext.getCapabilities().GL_NV_fog_distance)
		{
			GL11.glFogi(34138, 34139);
		}
	}
}