Jump to content

tf2_mandeokyi

Members
  • Posts

    7
  • Joined

  • Last visited

tf2_mandeokyi's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. As the title says. (I've thought about mixing drawTexturedQuadFit and drawTexturedModalRect or something though, but it's actually quite not working well)
  2. Then how do I draw? [Edit] ( I got a code that can draw a line. Thankfully it doesn't crash the game, but it doesn't draw a line... Before: Tessellator t = Tessellator.getInstance(); BufferBuilder bb = t.getBuffer(); bb.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR); bb.pos(pos1.x, pos1.y, pos1.z).color(r, g, b, a).endVertex(); bb.pos(pos2.x, pos2.y, pos2.z).color(r, g, b, a).endVertex(); After: GlStateManager.glBegin(GL11.GL_LINES); GlStateManager.glVertex3f((float)pos1.x, (float)pos1.y, (float)pos1.z); GlStateManager.glVertex3f((float)pos2.x, (float)pos2.y, (float)pos2.z); GlStateManager.glEnd(); )
  3. Ok... I changed (again) GL11 to GlStateManager. But Minecraft crashes when I use GlStateManager (when opening a map). What is the problem with this code? package com.tf2_mandeokyi.TF2Mod.events; import java.awt.Color; import org.lwjgl.opengl.GL11; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.math.Vec3d; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class gameOverlayEvents { @SubscribeEvent public void renderGame(RenderWorldLastEvent 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) { GlStateManager.pushAttrib(); GlStateManager.disableCull(); GlStateManager.disableLighting(); GlStateManager.disableTexture2D(); GlStateManager.enableBlend(); GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); int r = c.getRed(), g = c.getGreen(), b = c.getBlue(), a = c.getAlpha(); GlStateManager.color(r, g, b, a); GlStateManager.glLineWidth(width); GlStateManager.depthMask(false); Tessellator t = Tessellator.getInstance(); BufferBuilder bb = t.getBuffer(); bb.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR); bb.pos(pos1.x, pos1.y, pos1.z).color(r, g, b, a).endVertex(); bb.pos(pos2.x, pos2.y, pos2.z).color(r, g, b, a).endVertex(); GlStateManager.depthMask(true); GlStateManager.popAttrib(); } } log:
  4. Ok, I'll use GLStateManager. But because I don't know how to use it, can you show me some examples? because I can't find any of it about GlStateManager, but the only GL11.
  5. 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/"
  6. Ok, so as you said, I changed GL11 to GlStateManager (There was GlStateManager, instead of GLStateManager), and placed that function at RenderGameOverlayEvent (Not at PlayerInteractEvent because I don't know how to make a loop at the inside of it). But Minecraft still crashes when I open the map. Did I miss something? import java.awt.Color; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.math.Vec3d; public class draw3dObjects { public static void drawLine(Vec3d pos1, Vec3d pos2, Color c, boolean smooth, float width) { GlStateManager.pushMatrix(); int r = c.getRed(), g = c.getGreen(), b = c.getBlue(), a = c.getAlpha(); GlStateManager.color(r, g, b, a); GlStateManager.glLineWidth(width); GlStateManager.depthMask(smooth); Tessellator t = Tessellator.getInstance(); BufferBuilder bBuilder = t.getBuffer(); //bBuilder.begin(GlStateManager.GL_LINES, DefaultVertexFormats.POSITION_COLOR); // Is this function useful? bBuilder.pos(pos1.x, pos1.y, pos1.z).color(r, g, b, a).endVertex(); bBuilder.pos(pos2.x, pos2.y, pos2.z).color(r, g, b, a).endVertex(); t.draw(); GlStateManager.depthMask(true); GlStateManager.popMatrix(); } } import java.awt.Color; import /* Some files... */.draw3dObjects; 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 event) { draw3dObjects.drawLine(new Vec3d(5,10,5), new Vec3d(10,10,10), new Color(255,0,0,100), false, 4); } }
  7. I made a function that can draw a line between pos1 and pos2 when the mouse is clicked, but sometimes Minecraft crashes. or instead of crashing, it doesn't draw a line when I click the mouse. 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; public class draw3dObjects { public static void drawLine(Vec3d pos1, Vec3d pos2, Color c, boolean smooth, float width) { // This causes crash (or maybe?) 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.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()); GL11.glLineWidth(width); GL11.glDepthMask(false); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR); int r = c.getRed(), g = c.getGreen(), b = c.getBlue(), a = c.getAlpha(); 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(); } } import java.awt.Color; import /* Some files... */.draw3dObjects; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.Vec3d; import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickEmpty; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class mouseClickEvents { @SubscribeEvent public void onPlayerClickedLeftButtonAtAir(LeftClickEmpty event) { if(event.getEntity() instanceof EntityPlayer) { EntityPlayer player = event.getEntityPlayer(); draw3dObjects.drawLine(player.getPositionVector(), new Vec3d(1,1,1), new Color(255,0,0,100), true, 3); } } } Can I put them in a function? What's the problem if I can?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.