#How do I use DrawContext
50 messages · Page 1 of 1 (latest)
you'll need to be a lot more specific about what you're trying to do and how
I'm just trying to draw somsething to the screen
I said specific
Check out the methods in DrawContext
There's text, color fills, textures
Each one is a separate topic
i tried DrawContext.fill(...) but no work
as in
im mainyl confused w
DrawContext(MinecraftClient.getInstance(), VertexConsumerProvider.immediate(Buffer))
``` @sour tinsel
where are you using this code?
ClientModInitializer
are you using a rendering event?
what
you cannot just create an instance of DrawContext
im just trying to draw a box to the screen, im sorry like IM REALLY new
oh
that's not how rendering works
i suggest you read the docs https://docs.fabricmc.net/develop/rendering/basic-concepts
i thought it would be easy
i have
its confusing
so? it clearly shows you how to use a rendering event
it's all explained in the docs
.
that was meant for hud rendering
if you need anything beyond that, look at the minecraft code
HudRenderCallback.EVENT.register((drawContext, tickDeltaManager) -> {
// Get the transformation matrix from the matrix stack, alongside the tessellator instance and a new buffer builder.
Matrix4f transformationMatrix = drawContext.getMatrices().peek().getPositionMatrix();
Tessellator tessellator = Tessellator.getInstance();
// Begin a triangle strip buffer using the POSITION_COLOR vertex format.
BufferBuilder buffer = tessellator.begin(VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_COLOR);
// Write our vertices, Z doesn't really matter since it's on the HUD.
buffer.vertex(transformationMatrix, 20, 20, 5).color(0xFF414141);
buffer.vertex(transformationMatrix, 5, 40, 5).color(0xFF000000);
buffer.vertex(transformationMatrix, 35, 40, 5).color(0xFF000000);
buffer.vertex(transformationMatrix, 20, 60, 5).color(0xFF414141);
// Make sure the correct shader for your chosen vertex format is set!
// You can find all the shaders in the ShaderProgramKeys class.
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
// Draw the buffer onto the screen.
BufferRenderer.drawWithGlobalProgram(buffer.end());
});
This is the code from the documentation and it's not working.
what minecraft version? the docs are based on a working reference so "not working" is highly unlikely
yes
oh
change the version of the docs
remember, docs are just common examples. you're not going to get spoonfed versions
ok
i've already provided enough info to figure out most of this on your own