As you said, I added .Pre after RenderGameOverlayEvent. (but I don't get ElementType what you're going to say is.)
And I found why Minecraft crashed. It's because that I separated functions at other classes.
But the problem now is that function draws line at HUD, not 3D space.
Any solution?
(btw, GL11 also works well instead of GlStateManager (And for other peoples too), so I changed GlStateManager to GL11.)
import java.awt.Color;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class gameOverlayEvents {
@SubscribeEvent
public void renderGame(RenderGameOverlayEvent.Pre event) {
drawBoundingBox(new Vec3d(5,5,5), new Vec3d(5,10,5), new Color(255,0,0,100), false, 1);
}
public static void drawBoundingBox(Vec3d pos1, Vec3d pos2, Color c, boolean smooth, float width) {
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glTranslated(0, 0, 0);
int r = c.getRed(), g = c.getGreen(), b = c.getBlue(), a = c.getAlpha();
GL11.glColor4d(r, g, b, a);
GL11.glLineWidth(width);
GL11.glDepthMask(false);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
bufferBuilder.pos(pos1.x, pos1.y, pos1.z).color(r, g, b, a).endVertex();
bufferBuilder.pos(pos2.x, pos2.y, pos2.z).color(r, g, b, a).endVertex();
tessellator.draw();
GL11.glDepthMask(true);
GL11.glPopAttrib();
}
} // I copied this code at "http://www.minecraftforge.net/forum/topic/60740-1121-solved-help-to-draw-line/"