#How do I use DrawContext

50 messages · Page 1 of 1 (latest)

graceful sapphire
#

im sorry im a beginner please don't make fun of me if im stupid

sand epoch
#

you'll need to be a lot more specific about what you're trying to do and how

graceful sapphire
sand epoch
sour tinsel
#

There's text, color fills, textures

#

Each one is a separate topic

graceful sapphire
graceful sapphire
#

as in

#

im mainyl confused w

DrawContext(MinecraftClient.getInstance(), VertexConsumerProvider.immediate(Buffer))
```  @sour tinsel
real void
#

where are you using this code?

graceful sapphire
real void
#

are you using a rendering event?

graceful sapphire
real void
#

you cannot just create an instance of DrawContext

graceful sapphire
#

im just trying to draw a box to the screen, im sorry like IM REALLY new

graceful sapphire
real void
#

that's not how rendering works

graceful sapphire
#

i thought it would be easy

real void
#

so? it clearly shows you how to use a rendering event

graceful sapphire
#

WAIT

#

was it HudRenderCallback thingy

real void
#

yes

#

please read it again

graceful sapphire
#

ok

#

where do I put the HudRenderCallback thing?

#

sorry

real void
#

it's all explained in the docs

graceful sapphire
#

ok

#

What about ShaderProgramKeys?

graceful sapphire
real void
#

that was meant for hud rendering

#

if you need anything beyond that, look at the minecraft code

graceful sapphire
#
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.

real void
#

what minecraft version? the docs are based on a working reference so "not working" is highly unlikely

graceful sapphire
#

1.21

#

this is on 1.21.4

#

Did something change?

real void
#

yes

graceful sapphire
#

oh

real void
#

change the version of the docs

graceful sapphire
#

it only has 2 versions

#

and they are both incorrect so idk

#

no the rigt one

real void
#

remember, docs are just common examples. you're not going to get spoonfed versions

real void
#

i've already provided enough info to figure out most of this on your own