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:com.dinasgames.engine.graphics.Texture.java

public Texture setSmooth(boolean smooth) {

    if (smooth != mSmooth) {

        mSmooth = smooth;// ww  w .j ava2s . c o m

        if (mTexture > 0) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, mTexture);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,
                    (mSmooth ? GL11.GL_LINEAR : GL11.GL_NEAREST));
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
                    (mSmooth ? GL11.GL_LINEAR : GL11.GL_NEAREST));
        }

    }

    return this;

}

From source file:com.dyonovan.tcnodetracker.lib.truetyper.TrueTypeFont.java

License:Open Source License

public static int loadImage(BufferedImage bufferedImage) {
    try {/*from   w ww.  j a va  2  s  .co  m*/
        short width = (short) bufferedImage.getWidth();
        short height = (short) bufferedImage.getHeight();
        //textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ? (byte)32 : (byte)24;
        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();

        int internalFormat = GL11.GL_RGBA8, format = GL11.GL_RGBA;
        IntBuffer textureId = BufferUtils.createIntBuffer(1);
        ;
        GL11.glGenTextures(textureId);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.get(0));

        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);

        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_NEAREST);

        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_NEAREST);

        GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);

        GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, internalFormat, width, height, format, GL11.GL_UNSIGNED_BYTE,
                byteBuffer);
        return textureId.get(0);

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

    return -1;
}

From source file:com.foudroyantfactotum.mod.fousarchive.midi.generation.MidiTexture.java

License:Open Source License

@Override
public void loadTexture(IResourceManager resourceManager) throws IOException {
    final int xSize = getSmallTextureSize();
    final int ySize = 88;
    byte[] res = null;

    try (final InputStream io = resourceManager.getResource(rl).getInputStream()) {
        res = getMidiTrack(io, xSize, ySize);
    } catch (InvalidMidiDataException e) {
        e.printStackTrace();// ww w .  ja v  a  2 s.  com
    }

    if (res != null) {
        this.deleteGlTexture();

        GlStateManager.bindTexture(this.getGlTextureId());

        final ByteBuffer bb = (ByteBuffer) BufferUtils.createByteBuffer(res.length).put(res).flip();

        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_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);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MIN_LOD, 0.0f);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, 0.0f);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0.0f);

        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, xSize, ySize, 0, GL11.GL_RGB, GL11.GL_BYTE, bb);
    }
}

From source file:com.github.begla.blockmania.world.horizon.Skysphere.java

License:Apache License

private void loadStarTextures() {
    int internalFormat = GL11.GL_RGBA8, format = GL12.GL_BGRA;

    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, _textureIds.get(0));

    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL12.GL_TEXTURE_WRAP_R, 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, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

    for (int i = 0; i < 6; i++) {

        byte[] data = TextureManager.getInstance().getTexture("stars" + (i + 1)).getTextureData();
        ByteBuffer byteBuffer = BufferUtils.createByteBuffer(data.length);
        byteBuffer.put(data);//from  w  w  w. j  ava2 s  . c om
        byteBuffer.flip();

        GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, 256, 256, 0, format,
                GL11.GL_UNSIGNED_BYTE, byteBuffer);
    }
}

From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

protected void setTextureUnit(Texture texture, int textureUnit) {
    // Create a new texture object in memory and bind it
    texId = GL11.glGenTextures();/*from w  w w.j  a v  a  2 s  . c  om*/
    GL13.glActiveTexture(textureUnit);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // All RGB bytes are aligned to each other and each component is 1 byte
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    // Upload the texture data and generate mip maps (for scaling)
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, texture.getWidth(), texture.getHeight(), 0,
            GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, texture.getTexBuffer());
    GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

    // Setup the ST coordinate system
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

    // Setup what to do when the texture has to be scaled
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
}

From source file:com.grillecube.client.opengl.GLTexture.java

/** set pixels data */
public final void setData(BufferedImage img) {
    if (img == null) {
        return;//from   w ww.  j a  v  a 2 s.c  o m
    }

    byte[] pixels = ImageUtils.getImagePixels(img);
    ByteBuffer buffer = BufferUtils.createByteBuffer(pixels.length);
    buffer.put(pixels);
    buffer.flip();

    this.data = img;

    this.bind(GL13.GL_TEXTURE0, GL11.GL_TEXTURE_2D);

    this.image2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, img.getWidth(), img.getHeight(), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buffer);

    this.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    this.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

    this.unbind(GL11.GL_TEXTURE_2D);

    this.width = img.getWidth();
    this.height = img.getHeight();
}

From source file:com.grillecube.engine.opengl.object.GLTexture.java

/** set pixels data */
public void setData(BufferedImage img) {
    if (img == null) {
        return;//from   w w  w .  j  a v  a2 s. c  o  m
    }

    byte[] pixels = ImageUtils.getImagePixels(img);
    ByteBuffer buffer = BufferUtils.createByteBuffer(pixels.length);
    buffer.put(pixels);
    buffer.flip();

    this.bind(GL13.GL_TEXTURE0, GL11.GL_TEXTURE_2D);

    this.image2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, img.getWidth(), img.getHeight(), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buffer);

    this.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    this.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

    this.unbind(GL11.GL_TEXTURE_2D);

    this._width = img.getWidth();
    this._height = img.getHeight();
}

From source file:com.grillecube.engine.renderer.world.WorldRenderer.java

private void createShadowFBO() {

    this._shadow_fbo = GLH.glhGenFBO();
    this._shadow_fbo.bind();
    this._shadow_fbo.createDrawBuffer(GL11.GL_NONE);

    this._shadow_map = GLH.glhGenTexture();
    this._shadow_map.bind(GL11.GL_TEXTURE_2D);

    this._shadow_map.image2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT16, SHADOW_FBO_WIDTH,
            SHADOW_FBO_HEIGHT, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null);
    this._shadow_map.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    this._shadow_map.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    this._shadow_map.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    this._shadow_map.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    this._shadow_fbo.createTextureAttachment(this._shadow_map, GL30.GL_DEPTH_ATTACHMENT);

    this._shadow_fbo.unbind();
}

From source file:com.kauridev.lunarfever.graphics.TextureLoader.java

License:Open Source License

public static Texture loadTexture(String file) {
    Texture texture = cache.get(file);//from   w w w.j a v  a  2 s.  c  o  m

    if (texture != null && texture.getTexture().valid()) {
        return texture;
    }

    BufferedImage image = loadImage(file);

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    int id = GL11.glGenTextures();

    // bind
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);

    // set filter
    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);

    // set wrap
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);

    // set unpack alignment
    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    // send data to gpu
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, loadBuffer(image));

    // Create texture
    texture = new Texture(id, image.getWidth(), image.getHeight());

    cache.put(file, texture);
    return texture;
}

From source file:com.microsoft.Malmo.MissionHandlers.VideoProducerImplementation.java

License:Open Source License

@Override
public void getFrame(MissionInit missionInit, ByteBuffer buffer) {
    if (!this.videoParams.isWantDepth()) {
        getRGBFrame(buffer); // Just return the simple RGB, 3bpp image.
        return;//from w ww.ja v  a 2s.  c om
    }

    // Otherwise, do the work of extracting the depth map:
    final int width = this.videoParams.getWidth();
    final int height = this.videoParams.getHeight();

    GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER,
            Minecraft.getMinecraft().getFramebuffer().framebufferObject);
    GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, this.fbo.framebufferObject);
    GL30.glBlitFramebuffer(0, 0, Minecraft.getMinecraft().getFramebuffer().framebufferWidth,
            Minecraft.getMinecraft().getFramebuffer().framebufferHeight, 0, 0, width, height,
            GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT, GL11.GL_NEAREST);

    this.fbo.bindFramebuffer(true);
    glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
    glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, this.depthBuffer);
    this.fbo.unbindFramebuffer();

    // Now convert the depth buffer into values from 0-255 and copy it over the alpha channel.
    // We either use the min and max values supplied in order to scale it, or we scale it according
    // to the dynamic content:
    float minval, maxval;

    // The scaling section is optional (since the depthmap is optional) - so if there is no depthScaling object,
    // go with the default of autoscale.
    if (this.videoParams.getDepthScaling() == null || this.videoParams.getDepthScaling().isAutoscale()) {
        minval = 1;
        maxval = 0;
        for (int i = 0; i < width * height; i++) {
            float f = this.depthBuffer.get(i);
            if (f < minval)
                minval = f;
            if (f > maxval)
                maxval = f;
        }
    } else {
        minval = this.videoParams.getDepthScaling().getMin().floatValue();
        maxval = this.videoParams.getDepthScaling().getMax().floatValue();
        if (minval > maxval) {
            // You can't trust users.
            float t = minval;
            minval = maxval;
            maxval = t;
        }
    }
    float range = maxval - minval;
    if (range < 0.000001)
        range = 0.000001f; // To avoid divide by zero errors in cases where there is no depth variance
    float scale = 255 / range;
    for (int i = 0; i < width * height; i++) {
        float f = this.depthBuffer.get(i);
        f = (f < minval ? minval : (f > maxval ? maxval : f));
        f -= minval;
        f *= scale;
        buffer.put(i * 4 + 3, (byte) f);
    }
    // Reset depth buffer ready for next read:
    this.depthBuffer.clear();
}