Search in sources :

Example 26 with Texture2D

use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories-core by Hugobros3.

the class SignRenderer method setupRender.

private void setupRender(RenderingInterface renderingContext) {
    renderingContext.setObjectMatrix(null);
    Texture2D diffuse = renderingContext.textures().getTexture("./models/sign.png");
    diffuse.setLinearFiltering(false);
    renderingContext.bindAlbedoTexture(diffuse);
    renderingContext.bindNormalTexture(renderingContext.textures().getTexture("./textures/normalnormal.png"));
    renderingContext.bindMaterialTexture(renderingContext.textures().getTexture("./textures/defaultmaterial.png"));
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D)

Example 27 with Texture2D

use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories-core by Hugobros3.

the class SignRenderer method renderVoxels.

@Override
public void renderVoxels(RenderingInterface renderingContext, IterableIterator<ChunkCell> renderableEntitiesIterator) {
    setupRender(renderingContext);
    renderingContext.setObjectMatrix(null);
    for (// .getElementsInFrustrumOnly())
    ChunkCell context : // .getElementsInFrustrumOnly())
    renderableEntitiesIterator) {
        if (renderingContext.getCamera().getCameraPosition().distance(context.getLocation()) > 32)
            continue;
        Texture2D diffuse = renderingContext.textures().getTexture("./models/sign.png");
        diffuse.setLinearFiltering(false);
        renderingContext.bindAlbedoTexture(diffuse);
        renderingContext.bindNormalTexture(renderingContext.textures().getTexture("./textures/normalnormal.png"));
        renderingContext.currentShader().setUniform2f("worldLightIn", context.getBlocklight(), context.getSunlight());
        boolean isPost = context.getVoxel().getName().endsWith("_post");
        int facing = context.getMetaData();
        Matrix4f mutrix = new Matrix4f();
        mutrix.translate(new Vector3f(0.5f, 0.0f, 0.5f));
        Location loc = context.getLocation();
        mutrix.translate((float) loc.x, (float) loc.y, (float) loc.z);
        mutrix.rotate((float) Math.PI * 2.0f * (-facing) / 16f, new Vector3f(0, 1, 0));
        if (!isPost)
            mutrix.translate(new Vector3f(0.0f, 0.0f, -0.5f));
        renderingContext.setObjectMatrix(mutrix);
        if (!isPost)
            renderingContext.meshes().getRenderableMeshByName("./models/sign_post.obj").render(renderingContext);
        else
            renderingContext.meshes().getRenderableMeshByName("./models/sign.obj").render(renderingContext);
        VoxelComponentSignText signTextComponent = (VoxelComponentSignText) context.components().get("signData");
        if (signTextComponent == null)
            continue;
        // bake sign mesh
        if (signTextComponent.cachedText == null || !signTextComponent.cachedText.equals(signTextComponent.getSignText())) {
            // entitySign.renderData = new TextMeshObject(entitySign.signText.getSignText());
            signTextComponent.cachedText = signTextComponent.getSignText();
            signTextComponent.renderData = renderingContext.getFontRenderer().newTextMeshObject(renderingContext.getFontRenderer().defaultFont(), signTextComponent.cachedText);
        }
        // signTextComponent.setSignText("fuck");
        // System.out.println("cachedText:"+signTextComponent.getSignText());
        // Display it
        mutrix.translate(new Vector3f(0.0f, 1.15f, 0.055f));
        renderingContext.setObjectMatrix(mutrix);
        signTextComponent.renderData.render(renderingContext);
    }
}
Also used : VoxelComponentSignText(io.xol.chunkstories.core.voxel.components.VoxelComponentSignText) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) ChunkCell(io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell) Location(io.xol.chunkstories.api.Location)

Aggregations

Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)27 Shader (io.xol.chunkstories.api.rendering.shader.Shader)9 Vector4f (org.joml.Vector4f)6 Matrix4f (org.joml.Matrix4f)5 Vector3f (org.joml.Vector3f)5 Location (io.xol.chunkstories.api.Location)3 GameWindow (io.xol.chunkstories.api.rendering.GameWindow)3 Voxel (io.xol.chunkstories.api.voxel.Voxel)3 ByteBuffer (java.nio.ByteBuffer)3 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)2 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)2 Player (io.xol.chunkstories.api.player.Player)2 Font (io.xol.chunkstories.api.rendering.text.FontRenderer.Font)2 CellData (io.xol.chunkstories.api.world.cell.CellData)2 DummyCell (io.xol.chunkstories.api.world.cell.DummyCell)2 MemFreeByteBuffer (io.xol.chunkstories.client.util.MemFreeByteBuffer)2 HeightmapImplementation (io.xol.chunkstories.world.summary.HeightmapImplementation)2 Vector2d (org.joml.Vector2d)2 Vector3dc (org.joml.Vector3dc)2 Entity (io.xol.chunkstories.api.entity.Entity)1