Utility - 0x3C50/Renderer GitHub Wiki

AlphaOverride

AlphaOverride provides a way to temporarily change the alpha of elements on the screen or in the world. This can be used to make, for example, fade in / fade out animations library-wide.

Usage

Adding a new alpha multiplier: AlphaOverride.pushAlphaMul(0-1);. This will add a new alpha multiplier to the stack. Everything rendered beyond this point will have it's alpha multiplied by the value given to pushAlphaMul.

Removing the previously added multiplier: AlphaOverride.popAlphaMul();. This will remove the previously added alpha multiplier. Everything rendered beyond this point will no longer consider the previously added alpha multiplier

BufferUtils

Certain utilities for working with BufferBuilders

draw(bufferBuilder)

Draws the given BufferBuilder with the global program (alias for BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()))

createVbo(builtBuffer)

Creates a new VBO for the given BuiltBuffer. Can be used to cache certain buffers, to draw them faster next time.

uploadToVbo(builtBuffer, vertexBuffer)

Uploads the given builtBuffer to the given vertexBuffer, provided it is not closed.

Colors

Utilities for working with color integers / other formats. This class has an extensive javadoc, and listing all methods here would be redundant.

Rectangle

It's just a rectangle on the screen. Nothing much to say about it.

RendererUtils

Utilities for working with the Renderer2d / Renderer3d classes.

Registering BufferedImages as Identifiers

registerBufferedImageTexture(identifier, bufferedImage) registers the provided bufferedImage under the identifier identifier, which can then be used to draw it in the game.

Projecting world coordinates into screen coordinates

worldSpaceToScreenSpace(vec3d) can project the given world coordinate (vec3d) into screen space. Can be combined with screenSpaceCoordinateIsVisible(vec3d), to determine if something is on screen or not.

Example

// Hud render event
Vec3d targetPos = new Vec3d(100, 64, 100); // world space
Vec3d screenSpace = RendererUtils.worldSpaceToScreenSpace(targetPos);
if (RendererUtils.screenSpaceCoordinateIsVisible(screenSpace)) {
    // do something with screenSpace.x and .y
}

Projecting screen coordinates into world coordinates

Similarly, you can also reverse the previous step. Using screenSpaceToWorldSpace(x, y, farPlane), you can convert certain screen coordinates (x, y) into world coordinates. Combining this with a raycast from farPlane = 0 to farPlane = 1, you can determine the precise position of a point on the screen in the world.

Example

// World render event
Vec3d near = RendererUtils.screenSpaceToWorldSpace(100, 100, 0);
Vec3d far = RendererUtils.screenSpaceToWorldSpace(100, 100, 1);
// Ray-cast from near to far to get block or entity at (100, 100) screen space