Jump to content

[1.19] Draw simple line


Zergatul

Recommended Posts

In 1.18 I used this code, but it no longer works. Could you give me some hints or example from other mods source code? I know I can look into Minecraft source, but they use VertexFormat.Mode.LINES and vertex format with normal.

var tesselator = Tesselator.getInstance();
var buffer = tesselator.getBuilder();
buffer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
buffer.vertex(x1, y1, z1).color(1f, 1f, 1f, 1f).endVertex();
buffer.vertex(x2, y2, z2).color(1f, 1f, 1f, 1f).endVertex();
buffer.end();
vertexBuffer.upload(buffer);

RenderSystem.depthMask(false);
RenderSystem.disableCull();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.disableTexture();
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glEnable(GL11.GL_DEPTH_TEST);

PoseStack poseStack = event.getPoseStack();
poseStack.pushPose();
poseStack.translate(-view.x, -view.y, -view.z);
var shader = GameRenderer.getPositionColorShader();
vertexBuffer.drawWithShader(poseStack.last().pose(), event.getProjectionMatrix().copy(), shader);
poseStack.popPose();

RenderSystem.depthMask(true);
RenderSystem.disableBlend();
RenderSystem.enableCull();
RenderSystem.enableTexture();

 

Link to comment
Share on other sites

Working code for 1.19:

 

Vec3 view = mc.gameRenderer.getMainCamera().getPosition();

RenderSystem.depthMask(false);
RenderSystem.disableCull();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.disableTexture();
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glDisable(GL11.GL_DEPTH_TEST);

var tesselator = Tesselator.getInstance();
var buffer = tesselator.getBuilder();
buffer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
buffer.vertex(0, 0, 0).color(1f, 1f, 1f, 1f).endVertex();
buffer.vertex(100, 200, 100).color(1f, 1f, 1f, 1f).endVertex();
vertexBuffer.bind();
vertexBuffer.upload(buffer.end());

PoseStack matrix = event.getPoseStack();
matrix.pushPose();
matrix.translate(-view.x, -view.y, -view.z);
var shader = GameRenderer.getPositionColorShader();
vertexBuffer.drawWithShader(matrix.last().pose(), event.getProjectionMatrix().copy(), shader);
matrix.popPose();

VertexBuffer.unbind();

 

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.