| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import java.nio.FloatBuffer;
|
| 4 | import net.minecraft.util.Vec3;
|
| 5 | import org.lwjgl.opengl.GL11;
|
| 6 |
|
| 7 | public class RenderHelper
|
| 8 | {
|
| 9 | /** Float buffer used to set OpenGL material colors */
|
| 10 | private static FloatBuffer colorBuffer = GLAllocation.createDirectFloatBuffer(16);
|
| 11 | private static final Vec3 LIGHT0_POS = (new Vec3(0.20000000298023224D, 1.0D, -0.699999988079071D)).normalize();
|
| 12 | private static final Vec3 LIGHT1_POS = (new Vec3(-0.20000000298023224D, 1.0D, 0.699999988079071D)).normalize();
|
| 13 |
|
| 14 | /**
|
| 15 | * Disables the OpenGL lighting properties enabled by enableStandardItemLighting
|
| 16 | */
|
| 17 | public static void disableStandardItemLighting()
|
| 18 | {
|
| 19 | GlStateManager.disableLighting();
|
| 20 | GlStateManager.disableLight(0);
|
| 21 | GlStateManager.disableLight(1);
|
| 22 | GlStateManager.disableColorMaterial();
|
| 23 | }
|
| 24 |
|
| 25 | /**
|
| 26 | * Sets the OpenGL lighting properties to the values used when rendering blocks as items
|
| 27 | */
|
| 28 | public static void enableStandardItemLighting()
|
| 29 | {
|
| 30 | GlStateManager.enableLighting();
|
| 31 | GlStateManager.enableLight(0);
|
| 32 | GlStateManager.enableLight(1);
|
| 33 | GlStateManager.enableColorMaterial();
|
| 34 | GlStateManager.colorMaterial(1032, 5634);
|
| 35 | float f = 0.4F;
|
| 36 | float f1 = 0.6F;
|
| 37 | float f2 = 0.0F;
|
| 38 | GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, (FloatBuffer)setColorBuffer(LIGHT0_POS.xCoord, LIGHT0_POS.yCoord, LIGHT0_POS.zCoord, 0.0D));
|
| 39 | GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, (FloatBuffer)setColorBuffer(f1, f1, f1, 1.0F));
|
| 40 | GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, (FloatBuffer)setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
|
| 41 | GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, (FloatBuffer)setColorBuffer(f2, f2, f2, 1.0F));
|
| 42 | GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, (FloatBuffer)setColorBuffer(LIGHT1_POS.xCoord, LIGHT1_POS.yCoord, LIGHT1_POS.zCoord, 0.0D));
|
| 43 | GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer)setColorBuffer(f1, f1, f1, 1.0F));
|
| 44 | GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
|
| 45 | GL11.glLight(GL11.GL_LIGHT1, GL11.GL_SPECULAR, (FloatBuffer)setColorBuffer(f2, f2, f2, 1.0F));
|
| 46 | GlStateManager.shadeModel(7424);
|
| 47 | GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, (FloatBuffer)setColorBuffer(f, f, f, 1.0F));
|
| 48 | }
|
| 49 |
|
| 50 | /**
|
| 51 | * Update and return colorBuffer with the RGBA values passed as arguments
|
| 52 | */
|
| 53 | private static FloatBuffer setColorBuffer(double p_74517_0_, double p_74517_2_, double p_74517_4_, double p_74517_6_)
|
| 54 | {
|
| 55 | return setColorBuffer((float)p_74517_0_, (float)p_74517_2_, (float)p_74517_4_, (float)p_74517_6_);
|
| 56 | }
|
| 57 |
|
| 58 | /**
|
| 59 | * Update and return colorBuffer with the RGBA values passed as arguments
|
| 60 | */
|
| 61 | private static FloatBuffer setColorBuffer(float p_74521_0_, float p_74521_1_, float p_74521_2_, float p_74521_3_)
|
| 62 | {
|
| 63 | colorBuffer.clear();
|
| 64 | colorBuffer.put(p_74521_0_).put(p_74521_1_).put(p_74521_2_).put(p_74521_3_);
|
| 65 | colorBuffer.flip();
|
| 66 | return colorBuffer;
|
| 67 | }
|
| 68 |
|
| 69 | /**
|
| 70 | * Sets OpenGL lighting for rendering blocks as items inside GUI screens (such as containers).
|
| 71 | */
|
| 72 | public static void enableGUIStandardItemLighting()
|
| 73 | {
|
| 74 | GlStateManager.pushMatrix();
|
| 75 | GlStateManager.rotate(-30.0F, 0.0F, 1.0F, 0.0F);
|
| 76 | GlStateManager.rotate(165.0F, 1.0F, 0.0F, 0.0F);
|
| 77 | enableStandardItemLighting();
|
| 78 | GlStateManager.popMatrix();
|
| 79 | }
|
| 80 | }
|
| 81 |
|