Example usage for org.lwjgl.opengl GL11 GL_CLAMP

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

Introduction

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

Prototype

int GL_CLAMP

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

Click Source Link

Document

TextureWrapMode

Usage

From source file:illarion.graphics.lwjgl.TextureAtlasLWJGL.java

License:Open Source License

/**
 * Activate the texture and prepare it for usage by OpenGL.
 * //from   www  .  ja  v a  2 s.  c  o m
 * @param resizeable true in case the texture shall be loaded with advanced
 *            rescaling methods, that are more calculation intensive but
 *            look better then the normal ones
 * @param allowCompression true if the texture is compressed at default
 *            settings, false if not. Best disallow compression for static
 *            images such as tiles, since the effects of the compression
 *            will be quite visible there
 */
@Override
@SuppressWarnings("nls")
public void activateTexture(final boolean resizeable, final boolean allowCompression) {

    if (!hasTextureData()) {
        throw new IllegalStateException("No texturedata loaded");
    }

    final int quality = Graphics.getInstance().getQuality();

    if (getTextureID() != 0) {
        removeTexture();
    }

    // generate new texture ID
    final int texID = getNewTextureID();
    setTextureID(texID);

    // bind texture ID
    DriverSettingsLWJGL.getInstance().enableTexture(texID);

    // prepare texture data
    if (resizeable) { // Textures will be resized -> smoothing would be good
        if (quality <= Graphics.QUALITY_LOW) {
            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);
        } else if ((quality <= Graphics.QUALITY_NORMAL) || isNoMipMaps()) {
            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 {
            if (GLContext.getCapabilities().OpenGL14) {
                GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
            } else {
                setNoMipMaps(true);
            }
            if (!isNoMipMaps()) {
                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_MAG_FILTER, GL11.GL_LINEAR);
            } else {
                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 {
        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.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);

    if (GLContext.getCapabilities().OpenGL13) {
        GL11.glHint(GL13.GL_TEXTURE_COMPRESSION_HINT, GL11.GL_NICEST);
    }

    // setup texture compression
    final boolean activateCompression = GLContext.getCapabilities().OpenGL13
            && ((allowCompression && (quality < Graphics.QUALITY_MAX)) || (quality <= Graphics.QUALITY_LOW));
    if (isTextureRGBA()) {
        internalFormat = GL11.GL_RGBA;
        sourceFormat = GL11.GL_RGBA;
        if (activateCompression) {
            internalFormat = GL13.GL_COMPRESSED_RGBA;
        }
    } else if (isTextureRGB()) {
        internalFormat = GL11.GL_RGB;
        sourceFormat = GL11.GL_RGB;
        if (activateCompression) {
            internalFormat = GL13.GL_COMPRESSED_RGB;
        }
    } else if (isTextureGrey()) {
        internalFormat = GL11.GL_LUMINANCE;
        sourceFormat = GL11.GL_LUMINANCE;
        if (activateCompression) {
            internalFormat = GL13.GL_COMPRESSED_LUMINANCE;
        }
    } else if (isTextureGreyAlpha()) {
        internalFormat = GL11.GL_LUMINANCE_ALPHA;
        sourceFormat = GL11.GL_LUMINANCE_ALPHA;
        if (activateCompression) {
            internalFormat = GL13.GL_COMPRESSED_LUMINANCE_ALPHA;
        }
    }

    final ByteBuffer texData = getTextureData();

    final int texWidth = getTextureWidth();
    final int texHeight = getTextureHeight();

    // produce a texture from the byte buffer
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, texWidth, texHeight, 0, sourceFormat,
            GL11.GL_UNSIGNED_BYTE, texData);

    if (quality < Graphics.QUALITY_MAX) {
        texIDBuffer.rewind();
        GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL13.GL_TEXTURE_COMPRESSED, texIDBuffer);

        texData.rewind();
        if (texIDBuffer.get(0) == GL11.GL_FALSE) {
            int newInternalFormat = internalFormat;
            if (internalFormat == GL13.GL_COMPRESSED_LUMINANCE_ALPHA) {
                newInternalFormat = GL13.GL_COMPRESSED_RGBA;
            } else if (internalFormat == GL13.GL_COMPRESSED_LUMINANCE) {
                newInternalFormat = GL13.GL_COMPRESSED_RGB;
            }
            final int orgSize = texData.remaining();
            if (newInternalFormat != internalFormat) {
                GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, newInternalFormat, texWidth, texHeight, 0,
                        sourceFormat, GL11.GL_UNSIGNED_BYTE, texData);
                GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL13.GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
                        texIDBuffer);
                final int newSize = texIDBuffer.get(0);
                if (newSize > orgSize) {
                    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, texWidth, texHeight, 0,
                            sourceFormat, GL11.GL_UNSIGNED_BYTE, texData);
                }
            }
        }
    }

    texIDBuffer.rewind();
    GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_INTERNAL_FORMAT, texIDBuffer);
    internalFormat = texIDBuffer.get();

    discardImageData();
}

From source file:im.bci.jnuit.lwjgl.LwjglHelper.java

License:Open Source License

public static void setupGLTextureParams() {
    if (GLContext.getCapabilities().OpenGL12) {
        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);
    } else {/*  w ww.  j  av a 2  s  .  c o  m*/
        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);
    }
    setupGLTextureQualityParams();
    GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
}

From source file:im.bci.jnuit.lwjgl.LwjglNuitFont.java

License:Open Source License

public static int loadImage(BufferedImage bufferedImage) {
    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;/*from w  ww.  j av  a  2s . c o m*/
    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_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);

    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);
}

From source file:itdelatrisu.opsu.render.CurveRenderState.java

License:Open Source License

/**
 * Backup the current state of the relevant OpenGL state and change it to
 * what's needed to draw the curve.//ww w. j a v  a2  s  .  c o m
 */
private RenderState startRender() {
    RenderState state = new RenderState();
    state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH);
    state.blendEnabled = GL11.glGetBoolean(GL11.GL_BLEND);
    state.depthEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_TEST);
    state.depthWriteEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK);
    state.texEnabled = GL11.glGetBoolean(GL11.GL_TEXTURE_2D);
    state.texUnit = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE);
    state.oldProgram = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM);
    state.oldArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
    GL11.glEnable(GL11.GL_BLEND);
    GL14.glBlendEquation(GL14.GL_FUNC_ADD);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthMask(true);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_TEXTURE_1D);
    GL11.glBindTexture(GL11.GL_TEXTURE_1D, staticState.gradientTexture);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);

    GL20.glUseProgram(0);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();

    return state;
}

From source file:loon.core.graphics.opengl.LWjglGL10.java

License:Apache License

public final void glTexParameterf(int target, int pname, float param) {
    if (GLEx.verMinor < 2 && param == GL12.GL_CLAMP_TO_EDGE) {
        param = GL11.GL_CLAMP;
    }/*from  www  .  ja va 2  s.  c  o m*/
    GL11.glTexParameterf(target, pname, param);
}

From source file:map.GameMap.java

License:Open Source License

private void renderMinimap() {
    int size = MINIMAP_SIZE;
    Texture tex = new Texture("ground");
    miniMap = new Material(name + "_minimap");
    int[] viewport = GLUtils.getViewport();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();//from   w w  w.j  a v  a  2 s .c  o  m
    GL11.glOrtho(0, size, size, 0, -10, 10);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glViewport(0, 0, size, size);

    GL11.glClearColor(0.0f, 0, 0, 1.0f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glScalef(size / tiles.length, size / tiles.length, size / tiles.length);

    GLUtils.glLightPos(1.0f, 1.0f, 1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    draw(null);
    GL11.glEnable(GL11.GL_CULL_FACE);

    IntBuffer addr = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glGenTextures(addr);
    tex.setID(addr.get(0));
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getID());

    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_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 0, 0, size, size, 0);

    miniMap.setTexture(0, tex);
    GL11.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
}

From source file:nintendofan9797.core.textureengine.codechicken.render.TextureUtils.java

public static Texture createTextureObject(String textureFile) {
    BufferedImage img = loadBufferedImage(textureFile);
    if (img == null)
        CoreLoadingPlugin.log.warning("Texture is null.");
    return new Texture(textureFile, 2, img.getWidth(), img.getHeight(), GL11.GL_CLAMP, GL11.GL_RGBA,
            GL11.GL_NEAREST, GL11.GL_NEAREST, img);
}

From source file:nintendofan9797.core.textureengine.codechicken.render.TextureUtils.java

public static Texture createTextureObject(String name, int w, int h) {
    return new Texture(name, 2, w, h, GL11.GL_CLAMP, GL11.GL_RGBA, GL11.GL_NEAREST, GL11.GL_NEAREST, null);
}

From source file:org.fenggui.binding.render.lwjgl.LWJGLOpenGL.java

License:Open Source License

public void setupStateVariables(boolean depthTestEnabled) {
    GL11.glEnable(GL11.GL_BLEND);//from  w  ww .j ava  2 s .c om
    //      GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    if (depthTestEnabled)
        GL11.glDisable(GL11.GL_DEPTH_TEST);

    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_FOG);
    GL11.glDisable(GL11.GL_DITHER);

    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    //GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
    GL11.glDisable(GL11.GL_LINE_STIPPLE);

    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.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_DECAL);

    //GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
    GL11.glDisable(GL11.GL_CULL_FACE);
    //      GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_NORMALIZE);
    GL11.glFrontFace(GL11.GL_CW);
    GL11.glCullFace(GL11.GL_BACK);
    // disabling textures after setting state values. They would
    // be ignored otherwise (i think)
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_TEXTURE_1D);
}

From source file:org.fenggui.render.lwjgl.LWJGLOpenGL.java

License:Open Source License

public void setupStateVariables(boolean depthTestEnabled) {
    GL11.glEnable(GL11.GL_BLEND);// w w  w. j  av a2  s  . co  m
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    if (depthTestEnabled)
        GL11.glDisable(GL11.GL_DEPTH_TEST);

    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_FOG);
    GL11.glDisable(GL11.GL_DITHER);

    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    //GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
    GL11.glEnable(GL11.GL_NORMALIZE);
    GL11.glDisable(GL11.GL_LINE_STIPPLE);

    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.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_DECAL);

    //GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_NORMALIZE);
    GL11.glFrontFace(GL11.GL_CW);
    GL11.glCullFace(GL11.GL_BACK);
    // disabling textures after setting state values. They would
    // be ignored otherwise (i think)
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_TEXTURE_1D);

}