Example usage for org.lwjgl.opengl GL11 GL_NEAREST

List of usage examples for org.lwjgl.opengl GL11 GL_NEAREST

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 GL_NEAREST.

Prototype

int GL_NEAREST

To view the source code for org.lwjgl.opengl GL11 GL_NEAREST.

Click Source Link

Document

TextureMagFilter

Usage

From source file:org.spoutcraft.client.io.CustomTextureManager.java

License:Open Source License

public static Texture getTextureFromPath(String path) {
    if (textures.containsKey(path)) {
        return textures.get(path);
    }//from w w  w  .  ja  v  a2 s  .com
    Texture texture = null;
    try {
        FileInputStream stream = new FileInputStream(path);
        if (stream.available() > 0) {
            texture = TextureLoader.getTexture(path.toLowerCase().endsWith(".png") ? "PNG" : "JPG", stream,
                    true, GL11.GL_NEAREST);
        }
        stream.close();
    } catch (IOException e) {
    }

    if (texture != null) {
        textures.put(path, texture);
    }
    return texture;
}

From source file:org.spoutcraft.client.io.CustomTextureManager.java

License:Open Source License

public static Texture getTextureFromJar(String path) {
    if (textures.containsKey(path)) {
        return textures.get(path);
    }/*from   w  ww  .ja  va2  s  . c  o  m*/

    Texture texture = null;
    // Check inside jar
    try {
        InputStream stream = Minecraft.class.getResourceAsStream(path);
        texture = TextureLoader.getTexture(path.toLowerCase().endsWith(".png") ? "PNG" : "JPG", stream, true,
                GL11.GL_NEAREST);
        stream.close();
    } catch (Exception e) {
    }
    // Check MCP/Eclipse Path
    if (texture == null) {
        String pathToJar;
        File jar = new File(
                CustomTextureManager.class.getProtectionDomain().getCodeSource().getLocation().getFile());
        try {
            pathToJar = jar.getCanonicalPath();
        } catch (IOException e1) {
            pathToJar = jar.getAbsolutePath();
        }
        try {
            pathToJar = URLDecoder.decode(pathToJar, "UTF-8");
        } catch (java.io.UnsupportedEncodingException ignore) {
        }

        File relative = new File(pathToJar + "/../../src/main/resources" + path.substring(4));

        try {
            pathToJar = relative.getCanonicalPath();
        } catch (IOException e) {
            pathToJar = relative.getAbsolutePath();
        }

        texture = getTextureFromPath(pathToJar);
    }

    if (texture != null) {
        textures.put(path, texture);
    }

    return texture;
}

From source file:org.terasology.logic.manager.DefaultRenderingProcess.java

License:Apache License

public FBO createFBO(String title, int width, int height, FBOType type, boolean depth, boolean normals) {
    // Make sure to delete the existing FBO before creating a new one
    deleteFBO(title);//from w w w. j a  v  a 2  s.c  om

    // Create a new FBO object
    FBO fbo = new FBO();
    fbo.width = width;
    fbo.height = height;

    // Create the color target texture
    fbo.textureId = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.textureId);

    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

    if (type != FBOType.NO_COLOR) {
        if (type == FBOType.HDR) {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, ARBTextureFloat.GL_RGBA16F_ARB, width, height, 0,
                    GL11.GL_RGBA, ARBHalfFloatPixel.GL_HALF_FLOAT_ARB, (java.nio.ByteBuffer) null);
        } else {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                    GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null);
        }
    }

    if (depth) {
        // Generate the depth texture
        fbo.depthTextureId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.depthTextureId);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT24, width, height, 0,
                GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (java.nio.ByteBuffer) null);

        // Create depth render buffer object
        fbo.depthRboId = EXTFramebufferObject.glGenRenderbuffersEXT();
        EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, fbo.depthRboId);
        EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                GL14.GL_DEPTH_COMPONENT24, width, height);
        EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, 0);
    }

    if (normals) {
        // Generate the normals texture
        fbo.normalsTextureId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.normalsTextureId);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null);
    }

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

    // Create the FBO
    fbo.fboId = EXTFramebufferObject.glGenFramebuffersEXT();
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.fboId);

    if (type != FBOType.NO_COLOR) {
        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fbo.textureId, 0);
    }

    if (depth) {
        // Generate the depth render buffer and depth map texture
        EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                fbo.depthRboId);
        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D, fbo.depthTextureId, 0);
    }

    if (normals) {
        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_COLOR_ATTACHMENT1_EXT, GL11.GL_TEXTURE_2D, fbo.normalsTextureId, 0);
    }

    IntBuffer bufferIds = BufferUtils.createIntBuffer(3);
    if (type != FBOType.NO_COLOR) {
        bufferIds.put(EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT);
    }
    if (normals) {
        bufferIds.put(EXTFramebufferObject.GL_COLOR_ATTACHMENT1_EXT);
    }
    bufferIds.flip();
    GL20.glDrawBuffers(bufferIds);

    int checkFB = EXTFramebufferObject.glCheckFramebufferStatusEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT);
    switch (checkFB) {
    case EXTFramebufferObject.GL_FRAMEBUFFER_COMPLETE_EXT:
        break;
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT exception");
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
        logger.error("FrameBuffer: " + title
                + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT exception");
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT exception");
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT exception");
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT exception");
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT exception");

        /*
         * On some graphics cards, FBOType.NO_COLOR can cause a GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT.
         * Attempt to continue without this FBO.
         */
        if (type == FBOType.NO_COLOR) {
            logger.error("FrameBuffer: " + title
                    + ", ...but the FBOType was NO_COLOR, ignoring this error and continuing without this FBO.");

            taint("Got a GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT because of FBOType.NO_COLOR.");
            return null;
        }
    default:
        throw new RuntimeException("Unexpected reply from glCheckFramebufferStatusEXT: " + checkFB);
    }

    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);

    _FBOs.put(title, fbo);
    return fbo;
}

From source file:org.terasology.rendering.opengl.DefaultRenderingProcess.java

License:Apache License

public FBO createFBO(String title, int width, int height, FBOType type, boolean depthBuffer,
        boolean normalBuffer, boolean lightBuffer, boolean stencilBuffer) {
    // Make sure to delete the existing FBO before creating a new one
    deleteFBO(title);/*from   www . j  a v  a 2s .c o  m*/

    // Create a new FBO object
    FBO fbo = new FBO();
    fbo.width = width;
    fbo.height = height;

    // Create the FBO
    fbo.fboId = glGenFramebuffersEXT();
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.fboId);

    if (type != FBOType.NO_COLOR) {
        fbo.textureId = glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.textureId);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        if (type == FBOType.HDR) {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                    ARBHalfFloatPixel.GL_HALF_FLOAT_ARB, (ByteBuffer) null);
        } else {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                    GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
        }

        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D,
                fbo.textureId, 0);
    }

    if (normalBuffer) {
        fbo.normalsTextureId = glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.normalsTextureId);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null);

        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL11.GL_TEXTURE_2D,
                fbo.normalsTextureId, 0);
    }

    if (lightBuffer) {
        fbo.lightBufferTextureId = glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.lightBufferTextureId);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        if (type == FBOType.HDR) {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, ARBTextureFloat.GL_RGBA16F_ARB, width, height, 0,
                    GL11.GL_RGBA, ARBHalfFloatPixel.GL_HALF_FLOAT_ARB, (ByteBuffer) null);
        } else {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                    GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null);
        }

        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL11.GL_TEXTURE_2D,
                fbo.lightBufferTextureId, 0);
    }

    if (depthBuffer) {
        fbo.depthStencilTextureId = glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.depthStencilTextureId);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        if (!stencilBuffer) {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT24, width, height, 0,
                    GL11.GL_DEPTH_COMPONENT, GL11.GL_UNSIGNED_INT, (ByteBuffer) null);
        } else {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, width,
                    height, 0, EXTPackedDepthStencil.GL_DEPTH_STENCIL_EXT,
                    EXTPackedDepthStencil.GL_UNSIGNED_INT_24_8_EXT, (ByteBuffer) null);
        }

        fbo.depthStencilRboId = glGenRenderbuffersEXT();
        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo.depthStencilRboId);

        if (!stencilBuffer) {
            glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, width, height);
        } else {
            glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, width,
                    height);
        }

        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,
                fbo.depthStencilRboId);
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D,
                fbo.depthStencilTextureId, 0);

        if (stencilBuffer) {
            glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D,
                    fbo.depthStencilTextureId, 0);
        }
    }

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

    IntBuffer bufferIds = BufferUtils.createIntBuffer(3);
    if (type != FBOType.NO_COLOR) {
        bufferIds.put(GL_COLOR_ATTACHMENT0_EXT);
    }
    if (normalBuffer) {
        bufferIds.put(GL_COLOR_ATTACHMENT1_EXT);
    }
    if (lightBuffer) {
        bufferIds.put(GL_COLOR_ATTACHMENT2_EXT);
    }
    bufferIds.flip();

    if (bufferIds.limit() == 0) {
        GL11.glReadBuffer(GL11.GL_NONE);
        GL20.glDrawBuffers(GL11.GL_NONE);
    } else {
        GL20.glDrawBuffers(bufferIds);
    }

    int checkFB = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    switch (checkFB) {
    case GL_FRAMEBUFFER_COMPLETE_EXT:
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT exception");
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
        logger.error("FrameBuffer: " + title
                + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT exception");
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT exception");
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT exception");
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT exception");
        break;
    case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
        logger.error("FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_UNSUPPORTED_EXT exception");
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT exception");

        /*
         * On some graphics cards, FBOType.NO_COLOR can cause a GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT.
         * Attempt to continue without this FBO.
         */
        if (type == FBOType.NO_COLOR) {
            logger.error("FrameBuffer: " + title
                    + ", ...but the FBOType was NO_COLOR, ignoring this error and continuing without this FBO.");

            return null;
        }

        break;
    default:
        logger.error("Unexpected reply from glCheckFramebufferStatusEXT: " + checkFB);
        break;
    }

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

    fboLookup.put(title, fbo);
    return fbo;
}

From source file:org.terasology.rendering.opengl.FBO.java

License:Apache License

private static void createDepthBuffer(FBO fbo, Dimensions dimensions, boolean useStencilBuffer) {
    fbo.depthStencilTextureId = glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.depthStencilTextureId);

    setTextureParameters(GL11.GL_NEAREST);

    if (!useStencilBuffer) {
        allocateTexture(dimensions, GL14.GL_DEPTH_COMPONENT24, GL11.GL_DEPTH_COMPONENT, GL11.GL_UNSIGNED_INT);
    } else {/*from  w  w  w. j a  v a2  s.  c om*/
        allocateTexture(dimensions, EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT,
                EXTPackedDepthStencil.GL_DEPTH_STENCIL_EXT, EXTPackedDepthStencil.GL_UNSIGNED_INT_24_8_EXT);
    }

    fbo.depthStencilRboId = glGenRenderbuffersEXT();
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo.depthStencilRboId);

    if (!useStencilBuffer) {
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, fbo.dimensions.width,
                fbo.dimensions.height);
    } else {
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT,
                fbo.dimensions.width, fbo.dimensions.height);
    }

    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,
            fbo.depthStencilRboId);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D,
            fbo.depthStencilTextureId, 0);

    if (useStencilBuffer) {
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D,
                fbo.depthStencilTextureId, 0);
    }
}

From source file:org.terasology.rendering.renderingProcesses.DefaultRenderingProcess.java

License:Apache License

public FBO createFBO(String title, int width, int height, FBOType type, boolean depthBuffer,
        boolean normalBuffer, boolean lightBuffer, boolean stencilBuffer) {
    // Make sure to delete the existing FBO before creating a new one
    deleteFBO(title);//  w  w w.  j  a  v  a 2s  .  c om

    // Create a new FBO object
    FBO fbo = new FBO();
    fbo.width = width;
    fbo.height = height;

    // Create the FBO
    fbo.fboId = EXTFramebufferObject.glGenFramebuffersEXT();
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.fboId);

    if (type != FBOType.NO_COLOR) {
        fbo.textureId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.textureId);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        if (type == FBOType.HDR) {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, ARBTextureFloat.GL_RGBA16F_ARB, width, height, 0,
                    GL11.GL_RGBA, ARBHalfFloatPixel.GL_HALF_FLOAT_ARB, (java.nio.ByteBuffer) null);
        } else {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                    GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null);
        }

        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fbo.textureId, 0);
    }

    if (normalBuffer) {
        fbo.normalsTextureId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.normalsTextureId);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null);

        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_COLOR_ATTACHMENT1_EXT, GL11.GL_TEXTURE_2D, fbo.normalsTextureId, 0);
    }

    if (lightBuffer) {
        fbo.lightBufferTextureId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.lightBufferTextureId);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        if (type == FBOType.HDR) {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, ARBTextureFloat.GL_RGBA16F_ARB, width, height, 0,
                    GL11.GL_RGBA, ARBHalfFloatPixel.GL_HALF_FLOAT_ARB, (java.nio.ByteBuffer) null);
        } else {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                    GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null);
        }

        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_COLOR_ATTACHMENT2_EXT, GL11.GL_TEXTURE_2D, fbo.lightBufferTextureId, 0);
    }

    if (depthBuffer) {
        fbo.depthStencilTextureId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.depthStencilTextureId);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        if (!stencilBuffer) {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT24, width, height, 0,
                    GL11.GL_DEPTH_COMPONENT, GL11.GL_UNSIGNED_INT, (java.nio.ByteBuffer) null);
        } else {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, width,
                    height, 0, EXTPackedDepthStencil.GL_DEPTH_STENCIL_EXT,
                    EXTPackedDepthStencil.GL_UNSIGNED_INT_24_8_EXT, (java.nio.ByteBuffer) null);
        }

        fbo.depthStencilRboId = EXTFramebufferObject.glGenRenderbuffersEXT();
        EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                fbo.depthStencilRboId);

        if (!stencilBuffer) {
            EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                    GL14.GL_DEPTH_COMPONENT24, width, height);
        } else {
            EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                    EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, width, height);
        }

        EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, 0);

        EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                fbo.depthStencilRboId);
        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D, fbo.depthStencilTextureId, 0);

        if (stencilBuffer) {
            EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                    EXTFramebufferObject.GL_STENCIL_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D,
                    fbo.depthStencilTextureId, 0);
        }
    }

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

    IntBuffer bufferIds = BufferUtils.createIntBuffer(3);
    if (type != FBOType.NO_COLOR) {
        bufferIds.put(EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT);
    }
    if (normalBuffer) {
        bufferIds.put(EXTFramebufferObject.GL_COLOR_ATTACHMENT1_EXT);
    }
    if (lightBuffer) {
        bufferIds.put(EXTFramebufferObject.GL_COLOR_ATTACHMENT2_EXT);
    }
    bufferIds.flip();

    if (bufferIds.limit() == 0) {
        GL11.glReadBuffer(GL11.GL_NONE);
        GL20.glDrawBuffers(GL11.GL_NONE);
    } else {
        GL20.glDrawBuffers(bufferIds);
    }

    int checkFB = EXTFramebufferObject.glCheckFramebufferStatusEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT);
    switch (checkFB) {
    case EXTFramebufferObject.GL_FRAMEBUFFER_COMPLETE_EXT:
        break;
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT exception");
        break;
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
        logger.error("FrameBuffer: " + title
                + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT exception");
        break;
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT exception");
        break;
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT exception");
        break;
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT exception");
        break;
    case EXTFramebufferObject.GL_FRAMEBUFFER_UNSUPPORTED_EXT:
        logger.error("FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_UNSUPPORTED_EXT exception");
        break;
    case EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
        logger.error(
                "FrameBuffer: " + title + ", has caused a GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT exception");

        /*
         * On some graphics cards, FBOType.NO_COLOR can cause a GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT.
         * Attempt to continue without this FBO.
         */
        if (type == FBOType.NO_COLOR) {
            logger.error("FrameBuffer: " + title
                    + ", ...but the FBOType was NO_COLOR, ignoring this error and continuing without this FBO.");

            return null;
        }

        break;
    default:
        logger.error("Unexpected reply from glCheckFramebufferStatusEXT: " + checkFB);
        break;
    }

    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);

    FBOs.put(title, fbo);
    return fbo;
}

From source file:org.twisc.core.JTextureManager.java

License:Open Source License

private static void loadImage(File image) {
    String shortName = image.getAbsolutePath()
            .replace(new File("res/textures").getAbsolutePath() + System.getProperty("file.separator"), "");
    String format = shortName.substring(shortName.lastIndexOf(".") + 1, shortName.length()).toUpperCase();
    try {//from  w  w  w  . j a  v a 2 s . c o  m
        textures[number] = TextureLoader.getTexture(format, new FileInputStream(image));
        textures[number].setTextureFilter(GL11.GL_NEAREST);
        names[number] = shortName.replace(System.getProperty("file.separator"), "/");
    } catch (IOException ex) {

    }
    number++;
}

From source file:org.voxels.platform.LWJGLOpenGLAdapter.java

License:Open Source License

@Override
public int GL_NEAREST() {
    return GL11.GL_NEAREST;
}

From source file:pw.knx.feather.font.FontCache.java

License:Apache License

/**
 * Allocate a new OpenGL texture for caching pre-rendered glyph images. The new texture is initialized to fully transparent
 * white so the individual glyphs images within can have a transparent border between them. The new texture remains bound
 * after returning from the function.//www  .j a v a  2  s  . c o  m
 */
private void allocateTexture() {
    /* Initialize the background to all white but fully transparent. */
    glyphGraphics.clearRect(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    /* Allocate new OpenGL texure */
    texture = GL11.glGenTextures();

    /* Load imageBuffer with pixel data ready for transfer to OpenGL texture */
    updateBuffer(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    /*
       * Initialize texture with the now cleared BufferedImage. Using a texture with GL_ALPHA8 internal format may result in
       * faster rendering since the GPU has to only fetch 1 byte per texel instead of 4 with a regular RGBA texture.
       */
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_ALPHA8, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, imageBuffer);

    /* Explicitly disable mipmap support because updateTexture() will only update the base level 0 */
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
}

From source file:quake.map.Map.java

public Map(ArrayList<Node> nodes, ArrayList<String> texture_paths) {
    this.nodes = new Node[nodes.size()];
    this.textures = new Texture[texture_paths.size()];
    nodes.toArray(this.nodes);
    for (int i = 0; i < texture_paths.size(); i++)
        try {//from  www  .j  a  va 2s  .c  om
            textures[i] = (TextureLoader.getTexture("PNG",
                    ResourceLoader.getResourceAsStream("res/" + texture_paths.get(i)), GL11.GL_NEAREST));
        } catch (IOException ex) {
            Logger.getLogger(Map.class.getName()).log(Level.SEVERE, null, ex);
        }
}