Search in sources :

Example 1 with Texture2DGL

use of io.xol.chunkstories.renderer.opengl.texture.Texture2DGL in project chunkstories by Hugobros3.

the class DecalsRendererImplementation method drawDecal.

public void drawDecal(Vector3dc position, Vector3dc orientation, Vector3dc size, String decalName) {
    Texture2DGL texture = TexturesHandler.getTexture("./textures/decals/" + decalName + ".png");
    drawDecal(position, orientation, size, texture);
}
Also used : Texture2DGL(io.xol.chunkstories.renderer.opengl.texture.Texture2DGL)

Example 2 with Texture2DGL

use of io.xol.chunkstories.renderer.opengl.texture.Texture2DGL in project chunkstories by Hugobros3.

the class SkyBoxBackground method render.

@Override
public void render(RenderingInterface renderer) {
    if (gameWindow.getLayer() == this)
        gameWindow.setLayer(new MainMenu(gameWindow, this));
    try // Ugly fps caps yay
    {
        Thread.sleep(33L);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // Render this shit boy
    renderer.getRenderTargetManager().setConfiguration(unblurredFBO);
    camera.setupUsingScreenSize(gameWindow.getWidth(), gameWindow.getHeight());
    Shader menuSkyBox = renderer.useShader("mainMenuSkyBox");
    camera.setupShader(menuSkyBox);
    renderer.bindCubemap("skybox", TexturesHandler.getCubemap(skyBox));
    camera.setRotationX(35 + (float) (Math.sin(camera.getRotationY() / 15)) * 5f);
    camera.setRotationY((System.currentTimeMillis() % 1000000) / 200.0f);
    renderer.drawFSQuad();
    renderer.getRenderTargetManager().setConfiguration(blurredHFBO);
    Shader blurH = renderer.useShader("blurH");
    blurH.setUniform2f("screenSize", gameWindow.getWidth(), gameWindow.getHeight());
    renderer.bindTexture2D("inputTexture", unblurred);
    renderer.drawFSQuad();
    for (int i = 0; i < 1; i++) {
        renderer.getRenderTargetManager().setConfiguration(blurredVFBO);
        Shader blurV = renderer.useShader("blurV");
        blurV.setUniform1f("lookupScale", 1);
        blurV.setUniform2f("screenSize", gameWindow.getWidth() / 2, gameWindow.getHeight() / 2);
        renderer.bindTexture2D("inputTexture", blurredH);
        renderer.drawFSQuad();
        renderer.getRenderTargetManager().setConfiguration(blurredHFBO);
        blurH = renderer.useShader("blurH");
        blurH.setUniform2f("screenSize", gameWindow.getWidth() / 2, gameWindow.getHeight() / 2);
        renderer.bindTexture2D("inputTexture", blurredV);
        renderer.drawFSQuad();
    }
    renderer.getRenderTargetManager().setConfiguration(blurredVFBO);
    Shader blurV = renderer.useShader("blurV");
    blurV.setUniform2f("screenSize", gameWindow.getWidth(), gameWindow.getHeight());
    renderer.bindTexture2D("inputTexture", blurredH);
    renderer.drawFSQuad();
    renderer.getRenderTargetManager().setConfiguration(null);
    Shader blit = renderer.useShader("background");
    blit.setUniform2f("screenSize", gameWindow.getWidth(), gameWindow.getHeight());
    Texture2DGL backgroundTexture = TexturesHandler.getTexture("./textures/gui/darker.png");
    backgroundTexture.setLinearFiltering(false);
    renderer.bindTexture2D("diffuseTexture", backgroundTexture);
    renderer.bindTexture2D("backgroundTexture", blurredV);
    renderer.drawFSQuad();
    Texture2DGL logoTexture = TexturesHandler.getTexture("./textures/gui/icon.png");
    float alphaIcon = (float) (0.25 + Math.sin((System.currentTimeMillis() % (1000 * 60 * 60) / 3000f)) * 0.25f);
    renderer.setBlendMode(BlendMode.MIX);
    float diagonal = (float) Math.sqrt(gameWindow.getWidth() * gameWindow.getWidth() + gameWindow.getHeight() * gameWindow.getHeight());
    float iconSize = (float) (diagonal / 3 + 50 * Math.sin((System.currentTimeMillis() % (1000 * 60 * 60) / 30000f)));
    renderer.getGuiRenderer().drawBoxWindowsSpace(gameWindow.getWidth() / 2 - iconSize / 2, gameWindow.getHeight() / 2 - iconSize / 2, gameWindow.getWidth() / 2 + iconSize / 2, gameWindow.getHeight() / 2 + iconSize / 2, 0, 1, 1, 0, logoTexture, true, true, new Vector4f(1.0f, 1.0f, 1.0f, alphaIcon));
}
Also used : Vector4f(org.joml.Vector4f) Texture2DGL(io.xol.chunkstories.renderer.opengl.texture.Texture2DGL) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 3 with Texture2DGL

use of io.xol.chunkstories.renderer.opengl.texture.Texture2DGL in project chunkstories by Hugobros3.

the class TrueTypeFont method loadImageIntoOpenGLTexture.

public static Texture2DGL loadImageIntoOpenGLTexture(int offset, BufferedImage bufferedImage) {
    try {
        short width = (short) bufferedImage.getWidth();
        short height = (short) bufferedImage.getHeight();
        int bpp = (byte) bufferedImage.getColorModel().getPixelSize();
        ByteBuffer byteBuffer;
        DataBuffer db = bufferedImage.getData().getDataBuffer();
        if (db instanceof DataBufferInt) {
            int[] intI = ((DataBufferInt) (bufferedImage.getData().getDataBuffer())).getData();
            byte[] newI = new byte[intI.length * 4];
            for (int i = 0; i < intI.length; i++) {
                byte[] b = intToByteArray(intI[i]);
                int newIndex = i * 4;
                newI[newIndex] = b[1];
                newI[newIndex + 1] = b[2];
                newI[newIndex + 2] = b[3];
                newI[newIndex + 3] = b[0];
            }
            byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI);
        } else {
            byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
        }
        byteBuffer.flip();
        Texture2DGL texture = new Texture2DRenderTargetGL(TextureFormat.RGBA_8BPP, width, height);
        texture.uploadTextureData(width, height, byteBuffer);
        texture.setLinearFiltering(false);
        texture.setTextureWrapping(false);
        return texture;
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
    return null;
}
Also used : Texture2DRenderTargetGL(io.xol.chunkstories.renderer.opengl.texture.Texture2DRenderTargetGL) DataBufferInt(java.awt.image.DataBufferInt) Texture2DGL(io.xol.chunkstories.renderer.opengl.texture.Texture2DGL) DataBufferByte(java.awt.image.DataBufferByte) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) FontFormatException(java.awt.FontFormatException) DataBuffer(java.awt.image.DataBuffer)

Example 4 with Texture2DGL

use of io.xol.chunkstories.renderer.opengl.texture.Texture2DGL in project chunkstories by Hugobros3.

the class TrueTypeFontRenderer method drawString.

private void drawString(Font font, float x, float y, String whatchars, float scaleX, float scaleY, int alignement, float clipX, Vector4fc color, TextMeshObject target) {
    TrueTypeFont trueTypeFont = (TrueTypeFont) font;
    boolean clip = clipX != -1;
    Glyph glyph;
    int charCurrent;
    int totalwidth = 0;
    int i = 0;
    float startY = 0;
    Vector4f colorModified = new Vector4f(color);
    String[] lines = whatchars.split("\n");
    if (lines.length == 0)
        return;
    int lineI = 0;
    int currentLineTotalLength = trueTypeFont.getWidth(lines[lineI]);
    if (alignement == ALIGN_CENTER) {
        // System.out.println(clipX + " " + currentLineTotalLength + " -> " + (clipX / scaleX - currentLineTotalLength) / 2);
        if (currentLineTotalLength < clipX / scaleX)
            totalwidth += (clipX / scaleX - currentLineTotalLength) / 2;
    }
    while (i < whatchars.length()) {
        charCurrent = whatchars.charAt(i);
        Texture2DGL pageTexture = trueTypeFont.glTextures[charCurrent / 256];
        // Generates any required unicode page
        if (pageTexture == null)
            pageTexture = trueTypeFont.createPage(charCurrent / 256);
        glyph = trueTypeFont.glyphs[charCurrent];
        if (glyph != null) {
            // Detects and parses #C0L0R codes
            if (charCurrent == '#' && whatchars.length() - i - 1 >= 6 && (whatchars.toCharArray()[i + 1] != '#') && HexTools.isHexOnly(whatchars.substring(i + 1, i + 7))) {
                if (!(i > 1 && whatchars.toCharArray()[i - 1] == '#')) {
                    String colorCode = whatchars.substring(i + 1, i + 7);
                    int[] rgb = ColorsTools.hexToRGB(colorCode);
                    colorModified = new Vector4f(rgb[0] / 255.0f * color.x(), rgb[1] / 255.0f * color.y(), rgb[2] / 255.0f * color.z(), color.w());
                    i += 7;
                    continue;
                }
            } else if (charCurrent == '\n') {
                startY -= trueTypeFont.getHeight();
                totalwidth = 0;
                if (lineI < lines.length - 1)
                    lineI++;
                currentLineTotalLength = trueTypeFont.getWidth(lines[lineI]);
                if (alignement == ALIGN_CENTER) {
                    if (currentLineTotalLength < clipX / scaleX)
                        totalwidth += (clipX / scaleX - currentLineTotalLength) / 2;
                }
            } else {
                if (clip && (totalwidth + (glyph.width)) > clipX / scaleX) {
                    startY -= trueTypeFont.getHeight();
                    totalwidth = 0;
                    continue;
                }
                if (target == null) {
                    // renderingContext.getGuiRenderer().setState(pageTexture, true, true, colorModified);
                    drawQuad(totalwidth * scaleX + x, startY * scaleY + y, (glyph.width) * scaleX, glyph.height * scaleY, ((float) glyph.x) / textureWidth, ((float) (glyph.y + glyph.height)) / textureHeight, ((float) (glyph.x + glyph.width)) / textureWidth, ((float) glyph.y) / textureHeight, pageTexture, colorModified);
                } else {
                    target.setState(pageTexture, colorModified);
                    target.drawQuad(totalwidth * scaleX + x, startY * scaleY + y, (glyph.width) * scaleX, glyph.height * scaleY, ((float) glyph.x) / textureWidth, ((float) (glyph.y + glyph.height)) / textureHeight, ((float) (glyph.x + glyph.width)) / textureWidth, ((float) glyph.y) / textureHeight);
                }
                if (glyph.width < 3)
                    totalwidth += 1;
                totalwidth += glyph.width;
            }
            i++;
        }
    }
    if (target != null)
        target.done();
}
Also used : Vector4f(org.joml.Vector4f) Texture2DGL(io.xol.chunkstories.renderer.opengl.texture.Texture2DGL)

Example 5 with Texture2DGL

use of io.xol.chunkstories.renderer.opengl.texture.Texture2DGL in project chunkstories by Hugobros3.

the class GuiRendererImplementation method renderTexturedRotatedRectRVBA.

public void renderTexturedRotatedRectRVBA(float xpos, float ypos, float w, float h, float rot, float tcsx, float tcsy, float tcex, float tcey, String textureName, float r, float v, float b, float a) {
    if (textureName.startsWith("internal://"))
        textureName = textureName.substring("internal://".length());
    else if (textureName.startsWith("gameDir://"))
        // GameDirectory.getGameFolderPath() + "/" + tex.substring("gameDir://".length());
        textureName = textureName.substring("gameDir://".length());
    else if (textureName.contains("../"))
        textureName = ("./" + textureName.replace("../", "") + ".png");
    else
        textureName = ("./textures/" + textureName + ".png");
    Texture2DGL texture = TexturesHandler.getTexture(textureName);
    texture.setLinearFiltering(false);
    // TexturesHandler.mipmapLevel(texture, -1);
    drawBoxWindowsSpace(xpos - w / 2, ypos + h / 2, xpos + w / 2, ypos - h / 2, tcsx, tcsy, tcex, tcey, texture, false, true, new Vector4f(r, v, b, a));
}
Also used : Vector4f(org.joml.Vector4f) Texture2DGL(io.xol.chunkstories.renderer.opengl.texture.Texture2DGL)

Aggregations

Texture2DGL (io.xol.chunkstories.renderer.opengl.texture.Texture2DGL)6 Vector4f (org.joml.Vector4f)4 Shader (io.xol.chunkstories.api.rendering.shader.Shader)1 Texture2DRenderTargetGL (io.xol.chunkstories.renderer.opengl.texture.Texture2DRenderTargetGL)1 FontFormatException (java.awt.FontFormatException)1 DataBuffer (java.awt.image.DataBuffer)1 DataBufferByte (java.awt.image.DataBufferByte)1 DataBufferInt (java.awt.image.DataBufferInt)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1