Jump to content

Wire frame overlay for a block


navybofus

Recommended Posts

I'm trying to "highlight" (add a wire frame) to some nearby chests when the player looks at a certain block, but I can't seem to get the tessellator to draw the wire frame. I followed the tutorial here on tessellation, but it's mainly for drawing faces of a custom block. I just want to draw a "phantom" wire frame with the faces shaded a color with a low alpha. Currently I just have the code for one face to get started but I stopped there because I was just getting a glitchy black face that was invisible from most angles and glitchy from others. I guess I'm using the wrong methods to draw lines. Sorry, but I just can't find a lot of good info about this.

 

Tessellator t = Tessellator.instance;
	GL11.glPushMatrix();
	GL11.glColor4d(1.0D, 0.0D, 0.0D, 1.0D);
	GL11.glTranslated(x, y+1, z);
	GL11.glLineWidth(3.0F);
	//t.startDrawingQuads(); // EDIT: Was using this. Now using next line.
	t.startDrawing(GL11.GL_LINE_STRIP); // This is showing the wireframe, but not all the time.

	t.addVertex(0, 0, 0);
	t.addVertex(0, 1, 0);
	t.addVertex(1, 1, 0);
	t.addVertex(1, 0, 0);
	t.draw();
	GL11.glPopMatrix();

 

Any help or a point toward a similar tutorial would be greatly appreciated.

Link to comment
Share on other sites

Hi

 

Here is some code I have used to render a wire frame; there is a lot of extra irrelevant stuff in there but it might give you some clues about what is going wrong.  Perhaps disable GL_TEXTURE_2D?

BTW what do you mean a "glitchy black face"?  if you are trying to draw lines (a wire frame), you shouldn't see any faces?

 

-TGG

 

  public void render(RenderPhase renderPhase, EntityPlayer player, int animationTickCount, float partialTick)
  {
    boolean shouldIRender = infoProvider.refreshRenderInfo(renderInfo);
    if (!shouldIRender) return;

    try {
      GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
      GL11.glDepthMask(false);

      GL11.glEnable(GL11.GL_BLEND);
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
      GL11.glColor4f(Colour.BLACK_40.R, Colour.BLACK_40.G, Colour.BLACK_40.B, Colour.BLACK_40.A);
      GL11.glLineWidth(2.0F);
      GL11.glDisable(GL11.GL_TEXTURE_2D);
      double expandDistance = 0.002F;

      Vec3 playerOrigin = player.getPosition(partialTick);

      AxisAlignedBB boundingBox = AxisAlignedBB.getAABBPool().getAABB(0, 0, 0, 0, 0, 0);
      for (ChunkCoordinates block : renderInfo.currentlySelectedBlocks) {
        boundingBox.setBounds(block.posX, block.posY, block.posZ, block.posX + 1, block.posY + 1, block.posZ + 1);
        boundingBox = boundingBox.expand(expandDistance, expandDistance, expandDistance).getOffsetBoundingBox(-playerOrigin.xCoord, -playerOrigin.yCoord, -playerOrigin.zCoord);
        switch (SELECTION_BOX_STYLE) {
          case 0: {
            SelectionBoxRenderer.drawCube(boundingBox);
            break;
          }
          case 1: {
            SelectionBoxRenderer.drawFilledCube(boundingBox);
            break;
          }
        }
      }
    } finally {
      GL11.glDepthMask(true);
      GL11.glPopAttrib();
    }
  }

 

and

 

  public static void drawCube(AxisAlignedBB cube) {
    double xa = cube.minX;
    double xb = cube.maxX;
    double ya = cube.minY;
    double yb = cube.maxY;
    double za = cube.minZ;
    double zb = cube.maxZ;

//    OpenGLdebugging.dumpAllIsEnabled();

    Tessellator tessellator = Tessellator.instance;
    tessellator.startDrawing(GL11.GL_LINE_STRIP);
    tessellator.addVertex(xa, ya, za);
    tessellator.addVertex(xa, yb, za);
    tessellator.addVertex(xb, yb, za);
    tessellator.addVertex(xb, ya, za);
    tessellator.addVertex(xa, ya, za);

    tessellator.addVertex(xa, ya, zb);
    tessellator.addVertex(xa, yb, zb);
    tessellator.addVertex(xb, yb, zb);
    tessellator.addVertex(xb, ya, zb);
    tessellator.addVertex(xa, ya, zb);
    tessellator.draw();

    tessellator.startDrawing(GL11.GL_LINES);
    tessellator.addVertex(xa, ya, za);
    tessellator.addVertex(xa, ya, zb);

    tessellator.addVertex(xa, yb, za);
    tessellator.addVertex(xa, yb, zb);

    tessellator.addVertex(xb, ya, za);
    tessellator.addVertex(xb, ya, zb);

    tessellator.addVertex(xb, yb, za);
    tessellator.addVertex(xb, yb, zb);
    tessellator.draw();
  }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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