Final target: draw a line in sky
Env
Config in build.properties
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.3
loader_version=0.13.3
fabric_version=0.51.1+1.18.2
Development environment:
- Ubuntu 22.04
- IDEA 2021.3.2(CE)
- OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
Code
SkyRenderer code
@Environment(EnvType.CLIENT)
public class OverworldSkyRenderer implements DimensionRenderingRegistry.SkyRenderer {
@Override
public void render(WorldRenderContext context) {
RenderSystem.disableTexture();
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(515);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.depthMask(false);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
bufferBuilder.begin(VertexFormat.DrawMode.LINES, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex(0f,0f,0f).color(255,255,255,255).next();
bufferBuilder.vertex(3f,3f,3f).color(255,255,255,255).next();
tessellator.draw();
RenderSystem.enableCull();
RenderSystem.depthMask(true);
RenderSystem.disableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableTexture();
}
}
And Mod initialization code
public class MainMod implements ModInitializer {
@Override
public void onInitialize() {
// Register sky renderer
DimensionRenderingRegistry.registerSkyRenderer(
RegistryKey.of(Registry.WORLD_KEY, new Identifier("overworld")),
new OverworldSkyRenderer()
);
DimensionRenderingRegistry.registerDimensionEffects(
new Identifier("overworld"),
new DimensionEffects.End()
);
}
}
Result and Assumption
But it did not work, at least I did not find any line in my view(F5 has been used).
I consulted some code of fabric-carpet
There are some difference, but I think these are not the key point
Package import
In carpet, it includes
com.mojang.blaze3d.vertex, but I cannot find this package in my IDEA. And when I cloned carpet and built it,import com.mojang.blaze3d.vertex.*;was removed, andendVertex()was changed tonext().begin()functionIn carpet, it uses
DEBUG_LINESand I usedLINES, I think they should have no difference in rendering. And I triedDEBUG_LINESlater, still no line.
Here are some of my assumptions:
- In carpet, these functions seem to be used as APIs for script, is there any more operations when rendering lines?
- I just said I did not see these lines, maybe they are invisible or behind me? Before this, I rendered some image in sky and that worked, and if vertexes are rendered in wrong order, image can be invisible.
- SkyRenderer cannot render lines? (Least likely >_<)
If anyone can help me?
My solution is using
VertexFormat.Mode.DEBUG_LINESHere I found an issue related to this question, although it is Forge, not Fabric.
In this issue, it found that
LINES,LINE_STRIPcannot be rendered for that they do not pass correct mode argument when invokingglDrawElements, so it cannot be rendered correctly. AndDEBUG_LINESandDEBUG_LINE_STRIPhave correct mode.Before I found this issue, I tried some code in
ChunkBoarderDebugRenderer, which usesVertexFormat.Mode.DEBUG_LINE_STRIP, and it did work!So what I did was changing:
to
And the vertex of second point(Camera looks at Z-negative, which means you can only see the point with negative z. I am noob for opengl T_T)
So here is my changed code
And the screenshot
However,
TRIANGLEcannot work, although it has correct mode value. I am trying to figure it out.