Example usage for com.badlogic.gdx.graphics GL20 GL_TEXTURE_CUBE_MAP

List of usage examples for com.badlogic.gdx.graphics GL20 GL_TEXTURE_CUBE_MAP

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics GL20 GL_TEXTURE_CUBE_MAP.

Prototype

int GL_TEXTURE_CUBE_MAP

To view the source code for com.badlogic.gdx.graphics GL20 GL_TEXTURE_CUBE_MAP.

Click Source Link

Usage

From source file:com.bitfire.postprocessing.filters.CubemapEquirectangularFilter.java

License:Apache License

public void setSides(FrameBuffer xpositive, FrameBuffer xnegative, FrameBuffer ypositive, FrameBuffer ynegative,
        FrameBuffer zpositive, FrameBuffer znegative) {
    cubemapSides = new TextureData[6];
    cubemapSides[0] = xpositive.getColorBufferTexture().getTextureData();
    cubemapSides[1] = xnegative.getColorBufferTexture().getTextureData();
    cubemapSides[2] = ypositive.getColorBufferTexture().getTextureData();
    cubemapSides[3] = ynegative.getColorBufferTexture().getTextureData();
    cubemapSides[4] = zpositive.getColorBufferTexture().getTextureData();
    cubemapSides[5] = znegative.getColorBufferTexture().getTextureData();

    FrameBuffer[] fbos = new FrameBuffer[6];
    fbos[0] = xpositive;/* www.  j a v  a 2  s .c o m*/
    fbos[1] = xnegative;
    fbos[2] = ypositive;
    fbos[3] = ynegative;
    fbos[4] = zpositive;
    fbos[5] = znegative;

    if (cmId < 0)
        cmId = Gdx.gl.glGenTexture();

    // Make active
    Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0 + u_texture1);
    Gdx.gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, cmId);

    // Call glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i) for all sides
    for (int i = 0; i < cubemapSides.length; i++) {
        if (cubemapSides[i].getType() == TextureData.TextureDataType.Custom) {
            cubemapSides[i].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
        }
    }

    for (int i = 0; i < cubemapSides.length; i++) {
        fbos[i].begin();
        Gdx.gl.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0,
                GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cmId, 0);
        fbos[i].end();
    }

    Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_MAG_FILTER, GL20.GL_LINEAR);
    Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_LINEAR);
    Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_WRAP_S, GL20.GL_CLAMP_TO_EDGE);
    Gdx.gl.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_WRAP_T, GL20.GL_CLAMP_TO_EDGE);
    Gdx.gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, 0);

    setParam(Param.Cubemap, u_texture1);

}

From source file:com.bitfire.postprocessing.filters.CubemapEquirectangularFilter.java

License:Apache License

@Override
protected void onBeforeRender() {
    // Bind cubemap
    Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0 + u_texture1);
    Gdx.gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, cmId);

    inputTexture.bind(u_texture0);// w  ww  . j a v  a  2s  .  c  om
}

From source file:com.lyeeedar.Roguelike3D.Graphics.Models.SkyBox.java

License:Open Source License

public SkyBox(String texture) {

    this.texture[0] = new Pixmap(Gdx.files.internal("data/textures/" + texture + "_px.png"));
    this.texture[1] = new Pixmap(Gdx.files.internal("data/textures/" + texture + "_nx.png"));
    this.texture[2] = new Pixmap(Gdx.files.internal("data/textures/" + texture + "_py.png"));
    this.texture[3] = new Pixmap(Gdx.files.internal("data/textures/" + texture + "_ny.png"));
    this.texture[4] = new Pixmap(Gdx.files.internal("data/textures/" + texture + "_pz.png"));
    this.texture[5] = new Pixmap(Gdx.files.internal("data/textures/" + texture + "_nz.png"));

    IntBuffer buffer = BufferUtils.newIntBuffer(1);
    buffer.position(0);// w  ww  .ja  v  a 2s  . c  om
    buffer.limit(buffer.capacity());
    Gdx.gl20.glGenTextures(1, buffer);
    textureId = buffer.get(0);

    Gdx.gl20.glActiveTexture(SKYBOX_TEXTURE_ACTIVE_UNIT);
    Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, textureId);

    for (int i = 0; i < 6; i++) {
        glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, this.texture[i]);
    }

    float[] vertices = { -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f,
            -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, };

    for (int i = 0; i < vertices.length; i++) {
        vertices[i] *= 10;
    }

    short[] indices = { 0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1 };

    mesh = new Mesh(true, 24, 14, new VertexAttribute(Usage.Position, 3, "a_position"));

    mesh.setVertices(vertices);
    mesh.setIndices(indices);

    final String vertexShader = Gdx.files.internal("data/shaders/model/skybox.vertex.glsl").readString();
    final String fragmentShader = Gdx.files.internal("data/shaders/model/skybox.fragment.glsl").readString();
    ShaderProgram.pedantic = true;
    shader = new ShaderProgram(vertexShader, fragmentShader);

    Gdx.gl20.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_NEAREST);
    Gdx.gl20.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_MAG_FILTER, GL20.GL_NEAREST);

    Gdx.gl20.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_WRAP_S, GL20.GL_CLAMP_TO_EDGE);
    Gdx.gl20.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_WRAP_T, GL20.GL_CLAMP_TO_EDGE);

}

From source file:com.lyeeedar.Roguelike3D.Graphics.Models.SkyBox.java

License:Open Source License

public void render(Camera cam) {
    Gdx.gl.glDisable(GL20.GL_DEPTH_TEST);
    Gdx.gl.glDepthMask(false);//w w  w.j  a va 2s.co  m
    Gdx.gl.glDisable(GL20.GL_CULL_FACE);

    Gdx.gl20.glActiveTexture(SKYBOX_TEXTURE_ACTIVE_UNIT);
    Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, textureId);

    shader.begin();

    shader.setUniformMatrix("u_pv", cam.combined);
    shader.setUniformf("u_pos", cam.position);
    shader.setUniformi("u_texture", 0);
    mesh.render(shader, GL20.GL_TRIANGLE_STRIP);

    shader.end();

    Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
    Gdx.gl.glDepthMask(true);
    Gdx.gl.glEnable(GL20.GL_CULL_FACE);
}

From source file:com.microbasic.sm.tools.FrameBufferCubeMap.java

License:Apache License

private void build() {
    final GL20 gl = Gdx.gl20;

    // iOS uses a different framebuffer handle! (not necessarily 0)
    if (!defaultFramebufferHandleInitialized) {
        defaultFramebufferHandleInitialized = true;
        if (Gdx.app.getType() == ApplicationType.iOS) {
            final IntBuffer intbuf = ByteBuffer.allocateDirect(16 * Integer.SIZE / 8)
                    .order(ByteOrder.nativeOrder()).asIntBuffer();
            gl.glGetIntegerv(GL20.GL_FRAMEBUFFER_BINDING, intbuf);
            defaultFramebufferHandle = intbuf.get(0);
        } else {//  w  w  w.  j a  v  a  2 s.c  o  m
            defaultFramebufferHandle = 0;
        }
    }

    setupTexture();

    final IntBuffer handle = BufferUtils.newIntBuffer(1);
    gl.glGenFramebuffers(1, handle);
    framebufferHandle = handle.get(0);

    if (hasDepth) {
        handle.clear();
        gl.glGenRenderbuffers(1, handle);
        depthbufferHandle = handle.get(0);
    }

    if (hasStencil) {
        handle.clear();
        gl.glGenRenderbuffers(1, handle);
        stencilbufferHandle = handle.get(0);
    }

    gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, colorTexture.getTextureObjectHandle());

    if (hasDepth) {
        gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, depthbufferHandle);
        gl.glRenderbufferStorage(GL20.GL_RENDERBUFFER, GL20.GL_DEPTH_COMPONENT16, colorTexture.getWidth(),
                colorTexture.getHeight());
    }

    if (hasStencil) {
        gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, stencilbufferHandle);
        gl.glRenderbufferStorage(GL20.GL_RENDERBUFFER, GL20.GL_STENCIL_INDEX8, colorTexture.getWidth(),
                colorTexture.getHeight());
    }

    gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, framebufferHandle);
    gl.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, GL20.GL_TEXTURE_CUBE_MAP,
            colorTexture.getTextureObjectHandle(), 0);
    if (hasDepth) {
        gl.glFramebufferRenderbuffer(GL20.GL_FRAMEBUFFER, GL20.GL_DEPTH_ATTACHMENT, GL20.GL_RENDERBUFFER,
                depthbufferHandle);
    }

    if (hasStencil) {
        gl.glFramebufferRenderbuffer(GL20.GL_FRAMEBUFFER, GL20.GL_STENCIL_ATTACHMENT, GL20.GL_RENDERBUFFER,
                stencilbufferHandle);
    }

    final int result = gl.glCheckFramebufferStatus(GL20.GL_FRAMEBUFFER);

    gl.glBindRenderbuffer(GL20.GL_RENDERBUFFER, 0);
    gl.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, 0);
    gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, defaultFramebufferHandle);

    /*for (int i = 0; i < 6; i++)
    {
       gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL20.GL_ALPHA, width, height, 0, GL20.GL_ALPHA, GL20.GL_UNSIGNED_BYTE, null);
    }*/

    if (result != GL20.GL_FRAMEBUFFER_COMPLETE) {
        colorTexture.dispose();
        if (hasDepth) {
            handle.clear();
            handle.put(depthbufferHandle);
            handle.flip();
            gl.glDeleteRenderbuffers(1, handle);
        }

        if (hasStencil) {
            handle.clear();
            handle.put(stencilbufferHandle);
            handle.flip();
            gl.glDeleteRenderbuffers(1, handle);
        }

        handle.clear();
        handle.put(framebufferHandle);
        handle.flip();
        gl.glDeleteFramebuffers(1, handle);

        if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
            throw new IllegalStateException("frame buffer couldn't be constructed: incomplete attachment");
        }
        if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS) {
            throw new IllegalStateException("frame buffer couldn't be constructed: incomplete dimensions");
        }
        if (result == GL20.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
            throw new IllegalStateException("frame buffer couldn't be constructed: missing attachment");
        }
        if (result == GL20.GL_FRAMEBUFFER_UNSUPPORTED) {
            throw new IllegalStateException(
                    "frame buffer couldn't be constructed: unsupported combination of formats");
        }
        throw new IllegalStateException("frame buffer couldn't be constructed: unknown error " + result);
    }
}

From source file:com.perfectplay.org.SkyBox.java

License:Open Source License

public SkyBox(AssetManager manager, String[] faces) {

    this.manager = manager;
    this.textures = faces;

    g_cubeTexture = createGLHandle();//from   w ww  . ja va  2 s  .  co m
    Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, g_cubeTexture);

    program = new ShaderProgram(Gdx.files.internal(vertexShader).readString(),
            Gdx.files.internal(fragmentShader).readString());
    if (!program.isCompiled())
        throw new GdxRuntimeException("Couldn't compile skybox shader: " + program.getLog());

    cube = genSkyBox();

    reloadCubemap();
}

From source file:com.perfectplay.org.SkyBox.java

License:Open Source License

public void reloadCubemap() {
    g_cubeTexture = createGLHandle();//w  w w  .j a v a  2 s .  com
    Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, g_cubeTexture);

    Pixmap temp = manager.get(textures[0], Pixmap.class);
    Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, temp.getGLInternalFormat(), temp.getWidth(),
            temp.getHeight(), 0, temp.getGLFormat(), temp.getGLType(), temp.getPixels());
    temp = manager.get(textures[1], Pixmap.class);
    Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, temp.getGLInternalFormat(), temp.getWidth(),
            temp.getHeight(), 0, temp.getGLFormat(), temp.getGLType(), temp.getPixels());
    temp = manager.get(textures[2], Pixmap.class);
    Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, temp.getGLInternalFormat(), temp.getWidth(),
            temp.getHeight(), 0, temp.getGLFormat(), temp.getGLType(), temp.getPixels());
    temp = manager.get(textures[3], Pixmap.class);
    Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, temp.getGLInternalFormat(), temp.getWidth(),
            temp.getHeight(), 0, temp.getGLFormat(), temp.getGLType(), temp.getPixels());
    temp = manager.get(textures[4], Pixmap.class);
    Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, temp.getGLInternalFormat(), temp.getWidth(),
            temp.getHeight(), 0, temp.getGLFormat(), temp.getGLType(), temp.getPixels());
    temp = manager.get(textures[5], Pixmap.class);
    Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, temp.getGLInternalFormat(), temp.getWidth(),
            temp.getHeight(), 0, temp.getGLFormat(), temp.getGLType(), temp.getPixels());

    Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, g_cubeTexture);

    Gdx.gl20.glTexParameterf(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_MAG_FILTER, GL20.GL_LINEAR);
    Gdx.gl20.glTexParameterf(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_NEAREST);
    Gdx.gl20.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_WRAP_S, GL20.GL_CLAMP_TO_EDGE);
    Gdx.gl20.glTexParameteri(GL20.GL_TEXTURE_CUBE_MAP, GL20.GL_TEXTURE_WRAP_T, GL20.GL_CLAMP_TO_EDGE);
}

From source file:com.perfectplay.org.SkyBox.java

License:Open Source License

public void render(PerspectiveCamera camera) {
    invView.set(camera.view);/*from   w  w w  . j av a 2  s .  c  om*/

    // Remove translation
    invView.val[Matrix4.M03] = 0;
    invView.val[Matrix4.M13] = 0;
    invView.val[Matrix4.M23] = 0;

    invView.inv().tra();

    mvp.set(camera.projection);
    mvp.mul(invView);

    Gdx.gl.glEnable(GL20.GL_CULL_FACE);
    Gdx.gl.glCullFace(GL20.GL_FRONT);
    Gdx.gl.glFrontFace(GL20.GL_CCW);

    Gdx.gl20.glDisable(GL20.GL_BLEND);
    Gdx.gl20.glDisable(GL20.GL_DEPTH_TEST);
    Gdx.gl20.glDepthMask(false);

    Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
    Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, g_cubeTexture);

    program.begin();

    program.setUniformMatrix("u_mvpMatrix", mvp);
    program.setUniformi("s_cubemap", 0);

    cube.render(program, GL20.GL_TRIANGLE_STRIP);

    program.end();

    Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
    Gdx.gl.glDepthMask(true);
}