net.awairo.mcmod.spawnchecker.client.marker.RenderingSupport.java Source code

Java tutorial

Introduction

Here is the source code for net.awairo.mcmod.spawnchecker.client.marker.RenderingSupport.java

Source

/*
 * SpawnChecker.
 * 
 * (c) 2014 alalwww
 * https://github.com/alalwww
 * 
 * This mod is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL.
 * Please check the contents of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt
 * 
 * ?? MOD ??Minecraft Mod Public License (MMPL) 1.0 ???????????
 * ??????????? http://www.mod-buildcraft.com/MMPL-1.0.txt
 */

package net.awairo.mcmod.spawnchecker.client.marker;

import java.awt.Color;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;

import net.awairo.mcmod.common.v1.util.Colors;

/**
 * RenderingSupport.
 * 
 * @author alalwww
 */
public final class RenderingSupport {
    /** @return ? */
    public static RenderManager manager() {
        return RenderManager.instance;
    }

    /** @return ??? */
    public static Tessellator tessellator() {
        return Tessellator.instance;
    }

    /**
     * ????GL.
     */
    public static void beginRendering() {
        GL11.glDisable(GL11.GL_TEXTURE_2D);

        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glCullFace(GL11.GL_BACK);
        GL11.glDepthMask(false);

        GL11.glMatrixMode(GL11.GL_MODELVIEW);

        GL11.glEnable(GL11.GL_BLEND);
        OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
        GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
    }

    /**
     * ???GL.
     */
    public static void endRendering() {
        GL11.glDisable(GL11.GL_BLEND);

        GL11.glDepthMask(true);

        GL11.glDisable(GL11.GL_CULL_FACE);

        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }

    /**
     * ??????.
     */
    public static void startDrawingQuads() {
        tessellator().startDrawingQuads();
    }

    /**
     * ??????.
     */
    public static void startDrawingLines() {
        tessellator().startDrawing(GL11.GL_LINES);
    }

    /**
     * ???.
     * 
     * @param xOffset 
     * @param yOffset 
     * @param zOffset 
     */
    public static void setTranslation(double xOffset, double yOffset, double zOffset) {
        tessellator().setTranslation(xOffset, yOffset, zOffset);
    }

    /**
     * .
     * 
     * @param x x
     * @param y y
     * @param z z
     */
    public static void addVertex(double x, double y, double z) {
        tessellator().addVertex(x, y, z);
    }

    /**
     * ??.
     * 
     * @param x x
     * @param y y
     * @param z z
     * @param u u
     * @param v v
     */
    public static void addVertexWithUV(double x, double y, double z, double u, double v) {
        tessellator().addVertexWithUV(x, y, z, u, v);
    }

    /**
     * ?????.
     * 
     * @return ?
     */
    public static int draw() {
        return tessellator().draw();
    }

    /**
     * ?????.
     * 
     * @param color 
     * @param brightness ?
     */
    // TODO: ?????????????????GL11.glColor4ub???????
    // brightness???????????????????????
    public static void setColorAndBrightness(Color color, int brightness) {
        tessellator().setBrightness(brightness);
        tessellator().setColorRGBA(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
    }

    /**
     * ?????.
     * 
     * @param color 
     * @param brightness ?
     */
    public static void setGLColorAndBrightness(Color color, int brightness) {
        // ??????????????
        // ????????????????????
        // tessellator ??????????????????

        setGLColor(Colors.applyBrightnessTo(color, brightness));
    }

    /**
     * ???.
     * 
     * @param c 
     */
    public static void setGLColor(Color c) {
        setGLColor(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
    }

    /**
     * ???.
     * 
     * @param argb 
     */
    public static void setGLColor(int argb) {
        int a = (argb >> 24) & 0xff;
        int r = (argb >> 16) & 0xff;
        int g = (argb >> 8) & 0xff;
        int b = (argb >> 0) & 0xff;
        setGLColor(r, g, b, a);
    }

    /**
     * ???.
     * 
     * @param r 
     * @param g 
     * @param b ?
     * @param a ?
     */
    public static void setGLColor(int r, int g, int b, int a) {
        GL11.glColor4ub((byte) r, (byte) g, (byte) b, (byte) a);
    }

    /**
     * Constructor.
     */
    private RenderingSupport() {
        throw new InternalError();
    }
}