Example usage for org.lwjgl.opengl GL13 glActiveTexture

List of usage examples for org.lwjgl.opengl GL13 glActiveTexture

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL13 glActiveTexture.

Prototype

public static void glActiveTexture(@NativeType("GLenum") int texture) 

Source Link

Document

Selects which texture unit subsequent texture state calls will affect.

Usage

From source file:com.opengrave.og.resources.TextureAtlasEditable.java

License:Open Source License

@Override
public void unbind() {
    GL13.glActiveTexture(lastTexNum);
    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0);
}

From source file:com.opengrave.og.resources.TextureDead.java

License:Open Source License

public static TextureDead create(String location) {
    InputStream in = null;//from   w  w  w  . j  a va 2  s. c  o m
    File f = new File(Resources.cache, location);
    try {
        in = new FileInputStream(f.getAbsolutePath());
    } catch (FileNotFoundException e1) {
        System.out.println("Cannot open file " + f.getAbsolutePath());
        return null;
    }
    PNGDecoder decoder;
    TextureDead textureObject = new TextureDead();
    int texture = -1;
    try {
        decoder = new PNGDecoder(in);
        textureObject.width = decoder.getWidth();
        textureObject.height = decoder.getHeight();
        System.out.println("Width : " + decoder.getWidth() + " Height : " + decoder.getHeight());
        ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
        buf.flip();
        texture = GL11.glGenTextures();
        textureObject.id = texture;
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
        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);
        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.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0,
                GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
        // GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
    } catch (IOException e) {
        new DebugExceptionHandler(e, location);
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
        }
    }
    return textureObject;

}

From source file:com.opengrave.og.resources.TextureEditable.java

License:Open Source License

@Override
public void bind(int t) {
    GL13.glActiveTexture(t);
    synchronized (changeList) {
        if (changeList.size() < 10) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);

            for (TextureEditableDeferedChanges change : changeList) {
                applyChangeToMainBuffer(change);
                ByteBuffer buf = BufferUtils.createByteBuffer(4);
                buf.put((byte) (255 * change.getColour().z)).put((byte) (255 * change.getColour().y))
                        .put((byte) (255 * change.getColour().x)).put((byte) (255 * change.getColour().w));
                buf.flip();/*from  w  w  w.j a  va2  s.com*/
                GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, change.getX(), change.getY(), 1, 1, GL12.GL_BGRA,
                        GL11.GL_UNSIGNED_BYTE, buf);
            }
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
        } else {
            // Replace the whole image. There's bound to be better ways
            // around this...
            for (TextureEditableDeferedChanges change : changeList) {
                applyChangeToMainBuffer(change);
            }
            mainBuf.position(0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
            Util.checkErr();
            GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, size, size, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE,
                    mainBuf);
            Util.checkErr();
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
            Util.checkErr();

        }
        changeList.clear();
    }
    Util.checkErr();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
    lastTexNum = t;
}

From source file:com.opengrave.og.resources.TextureEditable.java

License:Open Source License

@Override
public void unbind() {
    GL13.glActiveTexture(lastTexNum);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}

From source file:com.redthirddivision.quad.rendering.materials.Texture.java

License:Apache License

public void bind(int samplerSlot) {
    try {//ww  w  .  j a va2s  .  c  o  m
        assert (samplerSlot >= 0 && samplerSlot <= 31);
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + samplerSlot);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, manager.getID());
    } catch (Exception e) {
        System.err.println("Could not bind texture: " + file);
        System.exit(1);
    }
}

From source file:com.redthirddivision.quad.rendering.renderers.EntityRenderer.java

License:Apache License

protected void prepare(Model model) {
    GL30.glBindVertexArray(model.getVaoID());
    GL20.glEnableVertexAttribArray(0);/*from   w w w .j a v  a 2 s  .  c om*/
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    Material material = model.getMaterial();
    shader.loadNumRows(material.getNumRows());
    if (material.hasTransparency())
        Util.disableCulling();
    shader.loadFakeLighting(material.isUseingFakeLighting());
    shader.loadShine(material.getShineDamper(), material.getReflectivity());

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getMaterial().getTextureID());
}

From source file:com.redthirddivision.quad.rendering.renderers.GuiRenderer.java

License:Apache License

@Override
public void render(ArrayList<GuiTexture> elements) {
    shader.start();//  w w w.  j  av a 2 s . c om

    GL30.glBindVertexArray(quad.getVaoID());
    GL20.glEnableVertexAttribArray(0);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    for (GuiTexture gui : elements) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, gui.getTexture());
        Matrix4f matrix = MathHelper.createTransformationMatrix(gui.getPosition(), gui.getScale(),
                new Vector2f(0, 0));
        shader.loadTransformation(matrix);
        GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount());
    }

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);

    shader.stop();
}

From source file:com.redthirddivision.quad.rendering.renderers.TerrainRenderer.java

License:Apache License

private void bindTextures(Terrain terrain) {
    TerrainTexturePack texturePack = terrain.getTexturePack();
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getBackgroundTexture().getTextureID());

    GL13.glActiveTexture(GL13.GL_TEXTURE1);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getrTexture().getTextureID());

    GL13.glActiveTexture(GL13.GL_TEXTURE2);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getgTexture().getTextureID());

    GL13.glActiveTexture(GL13.GL_TEXTURE3);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getbTexture().getTextureID());

    GL13.glActiveTexture(GL13.GL_TEXTURE4);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, terrain.getBlendMap().getTextureID());
}

From source file:com.samrj.devil.gl.Texture.java

License:Open Source License

/**
 * Temporarily activates the given texture unit, binds this texture to it,
 * then activates whichever unit was active before this method was called.
 * //from  ww w  . j  a v a2s .  c o  m
 * @param texture The OpenGL texture unit enum to bind to.
 * @return This texture.
 */
public final T bind(int texture) {
    if (deleted)
        throw new IllegalStateException("Cannot bind deleted texture.");
    if (texture < GL13.GL_TEXTURE0)
        throw new IllegalArgumentException();
    int old = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE);
    GL13.glActiveTexture(texture);
    bind();
    GL13.glActiveTexture(old);
    return getThis();
}

From source file:com.voxelplugineering.voxelsniper.render.RenderMain.java

License:Open Source License

public void tick() {
    if (!setup) {
        return;//from   w w  w .jav a  2 s  .c  o m
    }
    Camera camera = Standalone.system().getMainCamera();

    // reset view matrix
    viewMatrix.setIdentity();

    // Translate camera
    Vector3f rot = camera.getCameraRot();
    Matrix4f.rotate(rot.x, new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate(rot.y, new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate(rot.z, new Vector3f(0, 0, 1), viewMatrix, viewMatrix);
    Matrix4f.translate(camera.getCameraPos(), viewMatrix, viewMatrix);

    GL20.glUseProgram(pId);

    // push matrices
    viewMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(viewMatrixLocation, false, matrix44Buffer);
    modelMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(modelMatrixLocation, false, matrix44Buffer);
    projectionMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(projectionMatrixLocation, false, matrix44Buffer);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

    // bind textures
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.textures.get("block"));

    // render all buffer sections
    buffer.renderSections();

    GL20.glUseProgram(0);

    OpenGLUtilities.checkGLError("render main");

    Display.update();
}