Example usage for org.lwjgl.opengl GL11 glTexParameteri

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

Introduction

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

Prototype

public static void glTexParameteri(@NativeType("GLenum") int target, @NativeType("GLenum") int pname,
        @NativeType("GLint") int param) 

Source Link

Document

Sets the integer value of a texture parameter, which controls how the texel array is treated when specified or changed, and when applied to a fragment.

Usage

From source file:com.xrbpowered.gl.res.buffers.OffscreenBuffers.java

License:Open Source License

protected void create(int w, int h, boolean depthBuffer, boolean hdr) {
    colorTexId = GL11.glGenTextures();/*from   w ww.  j  a v  a2s  .  c o  m*/
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorTexId);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, hdr ? GL30.GL_RGB16F : GL11.GL_RGB, w, h, 0, GL11.GL_RGB,
            GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorTexId,
            0);

    depthTexId = 0;
    if (depthBuffer) {
        depthTexId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthTexId);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT16, w, h, 0, GL11.GL_DEPTH_COMPONENT,
                GL11.GL_FLOAT, (ByteBuffer) null);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
        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);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
        GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL11.GL_TEXTURE_2D,
                depthTexId, 0);
    }
    checkStatus();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}

From source file:com.xrbpowered.gl.res.textures.CubeTexture.java

License:Open Source License

public CubeTexture(String pathFormat) {
    try {// w w w  .j av  a  2s . co  m
        texId = GL11.glGenTextures();
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texId);

        IntBuffer buf = null;

        for (int i = 0; i < 6; i++) {
            //            BufferedImage img = load(new FileInputStream(String.format("assets/"+pathFormat, FACE_NAMES[i])));
            BufferedImage img = AssetManager.defaultAssets.loadImage(String.format(pathFormat, FACE_NAMES[i]));
            buf = getPixels(img, buf);
            put(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, img.getWidth(), img.getHeight(), buf);
        }

        GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL12.GL_TEXTURE_WRAP_R, GL12.GL_CLAMP_TO_EDGE);
        GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, 0);

        Client.checkError();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:com.xrbpowered.gl.res.textures.Texture.java

License:Open Source License

public static void setProperties(int textureType, boolean wrap, boolean filter, int anisotropy) {
    GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_WRAP_S, wrap ? GL11.GL_REPEAT : GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_WRAP_T, wrap ? GL11.GL_REPEAT : GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_MAG_FILTER, filter ? GL11.GL_LINEAR : GL11.GL_NEAREST);
    GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_MIN_FILTER,
            filter ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_NEAREST);
    if (filter) {
        GL30.glGenerateMipmap(textureType);
        if (anisotropy > 1) {
            GL11.glTexParameterf(textureType, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
                    anisotropy);//from  ww  w. j  a  v  a  2s  .  c o  m
        }
    }
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public int createTexture(int width, int height) {

    int texId = GL11.glGenTextures();
    if (texId == 0) {
        return 0;
    }/*  w  w  w . j  a  v  a 2  s.  co  m*/

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // make the texture
    clearGLErrors();
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, 0);

    // if something bad happened, delete the texture
    if (hasGLError()) {
        GL11.glDeleteTextures(texId);
        return 0;
    }

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);

    return texId;
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public void texParamsMinMax(int pname, boolean useMipmap) {

    int min = pname;
    int max = pname;

    if (useMipmap) {
        if (min == GLContext.GL_LINEAR) {
            min = GLContext.GL_LINEAR_MIPMAP_LINEAR;
        } else {/*from w  w  w  . j  a  v  a 2s  . co  m*/
            min = GLContext.GL_NEAREST_MIPMAP_NEAREST;
        }
    }

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, translatePrismToGL(max));
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, translatePrismToGL(min));
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public boolean texImage2D(int target, int level, int internalFormat, int width, int height, int border,
        int format, int type, Buffer pixels, boolean useMipmap) {

    // NOTE: null pixels are allowed

    if (pixels != null && !(pixels instanceof ByteBuffer)) {
        throw new Error(
                "buffer should be a " + ByteBuffer.class.getName() + ", not a " + pixels.getClass().getName());
    }/*from   w  ww .  j  a v  a2 s .com*/
    ByteBuffer buf = (ByteBuffer) pixels;

    if (useMipmap) {
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
    }

    // if buf is not direct, copy it to a direct buffer
    if (buf != null && !buf.isDirect()) {
        imageBuf = updateBuffer(imageBuf, buf);
        buf = imageBuf;
    }

    clearGLErrors();

    GL11.glTexImage2D(translatePrismToGL(target), level, translatePrismToGL(internalFormat), width, height,
            border, translatePrismToGL(format), translatePrismToGL(type), buf);

    int glerror = getGLError();
    boolean hasError = glerror != GL11.GL_NO_ERROR;
    if (hasError) {
        System.err.println(String
                .format("WARNING: couldn't upload texture. glTexImage2D failed with code: 0x%x", glerror));
    }
    return !hasError;
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public void updateFilterState(int texID, boolean linearFilter) {
    if (linearFilter) {
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    } else {//from w  w w .  ja v  a2s.co  m
        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:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public void updateWrapState(int texID, WrapMode wrapMode) {
    int wm;/* w  ww  .java2s. c  o  m*/
    switch (wrapMode) {
    case REPEAT_SIMULATED: // mode should not matter for this case
    case REPEAT:
        wm = WRAPMODE_REPEAT;
        break;
    case CLAMP_TO_ZERO_SIMULATED:
    case CLAMP_TO_EDGE_SIMULATED: // needed for top/left edge cases
    case CLAMP_TO_EDGE:
        wm = WRAPMODE_CLAMP_TO_EDGE;
        break;
    case CLAMP_TO_ZERO:
        wm = WRAPMODE_CLAMP_TO_BORDER;
        break;
    case CLAMP_NOT_NEEDED:
        return;
    default:
        throw new Error("Unrecognized wrap mode: " + wrapMode);
    }
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, translatePrismToGL(wm));
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, translatePrismToGL(wm));
}

From source file:dataAccess.lwjgl.VAO_Loader.java

public static int loadTexture(File file) {
    int textureID;
    if (textureMap.containsKey(file.getAbsolutePath())) {
        textureID = textureMap.get(file.getAbsolutePath());
    } else {//from ww w.j a va  2 s . com
        Texture texture = null;
        try {
            texture = TextureLoader.getTexture("PNG", new FileInputStream(file));

        } catch (IOException ex) {
            Logger.getLogger(VAO_Loader.class.getName()).log(Level.SEVERE, null, ex);
        }
        textureID = texture.getTextureID();
        textureMap.put(file.getAbsolutePath(), textureID);
    }
    GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0f);
    if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) {
        if (Settings.ANISOTROPIC_FILTERING) {
            float amount = Math.min(4f,
                    GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT));
            GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
                    amount);
        }
    } else {
        System.out.println("no anisotropic filtering possible!");
    }
    return textureID;
}

From source file:dataAccess.lwjgl.VAO_Loader.java

public static int loadCubeMap(String... textureFiles) {
    int texID = GL11.glGenTextures();
    GL13.glActiveTexture(texID);//from   w  ww .  ja v a2  s.c o  m
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID);

    for (int i = 0; i < textureFiles.length; i++) {
        TextureData data = dataAccess.fileLoaders.TextureLoader
                .decodeTextureFile("res/textures/skybox/" + textureFiles[i] + ".png");
        GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_RGBA, data.getWidth(),
                data.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data.getBuffer());
    }
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    textureMap.put("cubeMap", texID);
    return texID;
}