Java Code Examples for com.jogamp.opengl.GL3#glActiveTexture()

The following examples show how to use com.jogamp.opengl.GL3#glActiveTexture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Gl_320_glsl_discard.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearColor(1.0f, 0.5f, 0.0f, 1.0f);
    gl3.glClear(GL_COLOR_BUFFER_BIT);

    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));
    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);

    return true;
}
 
Example 2
Source File: Gl_320_fbo_multisample_integer.java    From jogl-samples with MIT License 6 votes vote down vote up
private void renderFBO(GL3 gl3, int framebuffer) {

        Mat4 projection = glm.ortho_(-1.1f, 1.1f, 1.1f, -1.1f, 1.1f, -1.1f);
        Mat4 view = new Mat4(1.0f);
        Mat4 model = new Mat4(1.0f).rotate(-0.3f, new Vec3(0.f, 0.f, 1.f));
        Mat4 mvp = projection.mul(view).mul(model);

        gl3.glUseProgram(programName[Program.RENDER]);
        gl3.glUniform1i(uniformDiffuse[Program.RENDER], 0);
        gl3.glUniformMatrix4fv(uniformMvp[Program.RENDER], 1, false, mvp.toFa_(), 0);

        gl3.glViewport(0, 0, windowSize.x / framebufferSize, windowSize.y / framebufferSize);
        gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
        gl3.glClearBufferuiv(GL_COLOR, 0, new int[]{0, 128, 255, 255}, 0);

        gl3.glActiveTexture(GL_TEXTURE0);
        gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
        gl3.glBindVertexArray(vertexArrayName.get(0));

        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);

        checkError(gl3, "renderFBO");
    }
 
Example 3
Source File: Gl_320_texture_integer.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initTexture(GL3 gl3) {

        try {
            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl3.glGenTextures(1, textureName);
            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

            for (int level = 0; level < texture.levels(); ++level) {
                // TODO fix format
                gl3.glTexImage2D(GL_TEXTURE_2D, level,
                        GL_RGBA8UI, // TODO -A?
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        0,
                        GL_RGB_INTEGER, GL_UNSIGNED_BYTE,
                        texture.data(level));
            }
            gl3.glGenerateMipmap(GL_TEXTURE_2D);

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_320_texture_integer.class.getName()).log(Level.SEVERE, null, ex);
        }
        return checkError(gl3, "initTexture");
    }
 
Example 4
Source File: Gl_320_glsl_builtin_blocks.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initTexture(GL3 gl3) {

        try {
            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
            assert (!texture.empty());

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl3.glGenTextures(1, textureName);

            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
            jgli.Gl.Format format = jgli.Gl.translate(texture.format());
            for (int level = 0; level < texture.levels(); ++level) {
                gl3.glTexImage2D(GL_TEXTURE_2D, level,
                        format.internal.value,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        0,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            gl3.glGenerateMipmap(GL_TEXTURE_2D);

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_320_glsl_builtin_blocks.class.getName()).log(Level.SEVERE, null, ex);
        }
        return checkError(gl3, "initTexture");
    }
 
Example 5
Source File: Gl_320_glsl_input_struct.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    {
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl3.glMapBufferRange(
                GL_UNIFORM_BUFFER, 0, Mat4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

        Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);

        pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_());

        // Make sure the uniform buffer is uploaded
        gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);
    gl3.glUniformBlockBinding(programName, uniformTransform, Semantic.Uniform.TRANSFORM0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

    return true;
}
 
Example 6
Source File: Gl_330_texture_swizzle.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 1000.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, .5f).put(2, 0).put(3, 1));

    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl3.glUniform1i(uniformDiffuse, 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));

    gl3.glBindVertexArray(vertexArrayName.get(0));

    for (int index = 0; index < Viewport.MAX; ++index) {
        gl3.glViewport(viewport[index].x, viewport[index].y, viewport[index].z, viewport[index].w);

        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, swizzleR[index]);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, swizzleG[index]);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, swizzleB[index]);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, swizzleA[index]);

        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }

    return true;
}
 
Example 7
Source File: Gl_320_texture_2d.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;
    {
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl3.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

        Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);

        pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_());

        gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl3.glDrawBuffer(GL_BACK);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glDisable(GL_FRAMEBUFFER_SRGB);
    clearColor.put(new float[]{1.0f, 0.5f, 0.0f, 1.0f}).rewind();
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

    gl3.glUseProgram(programName);

    gl3.glDisable(GL_FRAMEBUFFER_SRGB);
    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

    return true;
}
 
Example 8
Source File: Gl_320_fbo_blit.java    From jogl-samples with MIT License 5 votes vote down vote up
private void renderFBO(GL3 gl3) {

        Mat4 perspective = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);
        Mat4 mvp = perspective.mul(viewMat4()).mul(model);

        gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

        gl3.glActiveTexture(GL_TEXTURE0);
        gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
        gl3.glBindVertexArray(vertexArrayName.get(0));

        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }
 
Example 9
Source File: Gl_330_sampler_object.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 1000.0f);
    Mat4 model = new Mat4(1.0f).scale(new Vec3(3.0f));
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, .5f).put(2, 1).put(3, 1));

    // Bind the program for use
    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl3.glUniform1i(uniformDiffuse[Diffuse.A], Diffuse.A);
    gl3.glUniform1i(uniformDiffuse[Diffuse.B], Diffuse.B);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl3.glBindSampler(0, samplerName.get(Sampler.B));

    gl3.glActiveTexture(GL_TEXTURE1);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl3.glBindSampler(1, samplerName.get(Sampler.A));

    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);

    return true;
}
 
Example 10
Source File: Gl_320_test_scissor.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initTexture(GL3 gl3) {

        try {
            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));

            gl3.glGenTextures(1, textureName);

            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

            jgli.Gl.Format format = jgli.Gl.translate(texture.format());
            for (int level = 0; level < texture.levels(); ++level) {
                gl3.glTexImage2D(GL_TEXTURE_2D, level,
                        format.internal.value,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        0,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

        } catch (IOException ex) {
            Logger.getLogger(Gl_320_test_scissor.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }
 
Example 11
Source File: Gl_320_texture_offset.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 2.0f / 3.0f, 0.1f, 1000.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    clearColor.put(new float[]{1.0f, 0.5f, 0.0f, 1.0f}).rewind();
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));

    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glUseProgram(programName[Program.OFFSET]);
    gl3.glUniform2iv(uniformOffset, 1, new int[]{48, -80}, 0);

    for (int i = 0; i < Program.MAX; ++i) {
        gl3.glUseProgram(programName[i]);
        gl3.glUniformMatrix4fv(uniformMvp[i], 1, false, mvp.toFa_(), 0);
        gl3.glUniform1i(uniformDiffuse[i], 0);

        gl3.glViewport(viewport[i].x, viewport[i].y, viewport[i].z, viewport[i].w);

        gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);
    }

    return true;
}
 
Example 12
Source File: Gl_320_texture_derivative.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL3 gl3) {

        jgli.Texture2d texture = new Texture2d(jgli.Format.FORMAT_RGBA8_UNORM_PACK32, new int[]{64, 64});

        texture.clear(0, 0, 0, new byte[]{(byte) 255, (byte) 0, (byte) 0, (byte) 255});
        texture.clear(0, 0, 1, new byte[]{(byte) 255, (byte) 128, (byte) 0, (byte) 255});
        texture.clear(0, 0, 2, new byte[]{(byte) 255, (byte) 255, (byte) 0, (byte) 255});
        texture.clear(0, 0, 3, new byte[]{(byte) 0, (byte) 255, (byte) 0, (byte) 255});
        texture.clear(0, 0, 4, new byte[]{(byte) 0, (byte) 255, (byte) 255, (byte) 255});
        texture.clear(0, 0, 5, new byte[]{(byte) 0, (byte) 0, (byte) 255, (byte) 255});
        texture.clear(0, 0, 6, new byte[]{(byte) 255, (byte) 0, (byte) 0, (byte) 255});

        gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

        gl3.glGenTextures(1, textureName);

        gl3.glActiveTexture(GL_TEXTURE0);
        gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

        jgli.Gl.Format format = jgli.Gl.translate(texture.format());
        for (int level = 0; level < texture.levels(); ++level) {

            gl3.glTexImage2D(GL_TEXTURE_2D, level,
                    format.internal.value,
                    texture.dimensions(level)[0], texture.dimensions(level)[1],
                    0,
                    format.external.value, format.type.value,
                    texture.data(level));
        }

        if (texture.levels() == 1) {
            gl3.glGenerateMipmap(GL_TEXTURE_2D);
        }

        gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        return true;
    }
 
Example 13
Source File: Gl_320_fbo_srgb_decode_ext.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL3 gl3) {

        boolean validated = true;

        try {

            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
            assert (!texture.empty());

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl3.glGenTextures(Texture.MAX, textureName);

            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);

            jgli.Gl.Format format = jgli.Gl.translate(texture.format());
            for (int level = 0; level < texture.levels(); ++level) {
                gl3.glTexImage2D(GL_TEXTURE_2D, level,
                        format.internal.value,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        0,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            gl3.glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, windowSize.x * framebufferScale,
                    windowSize.y * framebufferScale, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);

            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RENDERBUFFER));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
            gl3.glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, windowSize.x * framebufferScale,
                    windowSize.y * framebufferScale, 0, GL_DEPTH_COMPONENT, GL_FLOAT, null);

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_320_fbo_srgb_decode_ext.class.getName()).log(Level.SEVERE, null, ex);
        }
        return validated;
    }
 
Example 14
Source File: Gl_320_fbo_blit.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL3 gl3) {

        try {
            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));

            gl3.glGenTextures(Texture.MAX, textureName);
            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

            jgli.Gl.Format format = jgli.Gl.translate(texture.format());

            for (int level = 0; level < texture.levels(); level++) {

                gl3.glTexImage2D(GL_TEXTURE_2D, level,
                        format.internal.value,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        0,
                        format.external.value, format.type.value,
                        texture.data(level));
            }
            gl3.glGenerateMipmap(GL_TEXTURE_2D); // Allocate all mipmaps memory

            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            gl3.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, FRAMEBUFFER_SIZE.x,
                    FRAMEBUFFER_SIZE.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);

            gl3.glBindTexture(GL_TEXTURE_2D, 0);

        } catch (IOException ex) {
            Logger.getLogger(Gl_320_fbo_blit.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }
 
Example 15
Source File: Gl_320_fbo_depth.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL3 gl3) {

        boolean validated = true;

        try {

            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));

            if (texture.empty()) {
                throw new Error("texture empty");
            }

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl3.glGenTextures(Texture.MAX, textureName);

            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

            for (int level = 0; level < texture.levels(); level++) {
                gl3.glCompressedTexImage2D(GL_TEXTURE_2D, level,
                        GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        0,
                        texture.size(level),
                        texture.data(level));
            }

            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RENDERBUFFER));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
            gl3.glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, windowSize.x, windowSize.y,
                    0, GL_DEPTH_COMPONENT, GL_FLOAT, null);

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_320_fbo_depth.class.getName()).log(Level.SEVERE, null, ex);
        }
        return validated;
    }
 
Example 16
Source File: Gl_320_fbo_srgb_blend.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL3 gl3) {

        boolean validated = true;

        try {

            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
            assert (!texture.empty());

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl3.glGenTextures(Texture.MAX, textureName);

            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

            jgli.Gl.Format format = jgli.Gl.translate(texture.format());
            for (int level = 0; level < texture.levels(); ++level) {
                gl3.glTexImage2D(GL_TEXTURE_2D, level,
                        format.internal.value,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        0,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            gl3.glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, windowSize.x * framebufferScale,
                    windowSize.y * framebufferScale, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_320_fbo_srgb_blend.class.getName()).log(Level.SEVERE, null, ex);
        }
        return validated;
    }
 
Example 17
Source File: GlyphManagerOpenGLController.java    From constellation with Apache License 2.0 4 votes vote down vote up
private void bindCoordinates(GL3 gl, int uniformLocation, int textureUnit) {
    gl.glActiveTexture(GL3.GL_TEXTURE0 + textureUnit);
    gl.glBindTexture(GL3.GL_TEXTURE_BUFFER, coordinatesTextureName[0]);
    gl.glUniform1i(uniformLocation, textureUnit);
}
 
Example 18
Source File: Gl_320_fbo_depth.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    {
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl3.glMapBufferRange(
                GL_UNIFORM_BUFFER, 0, Mat4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

        Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.5f, 8.0f);
        Mat4 model = new Mat4(1.0f).scale(new Vec3(5.0f));
        pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_());

        // Make sure the uniform buffer is uploaded
        gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl3.glEnable(GL_DEPTH_TEST);
    gl3.glDepthFunc(GL_LESS);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);

    gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
    float[] depth = {1.0f};
    gl3.glClearBufferfv(GL_DEPTH, 0, depth, 0);

    // Bind rendering objects
    gl3.glUseProgram(programName[Program.TEXTURE]);
    gl3.glUniformBlockBinding(programName[Program.TEXTURE], uniformTransform, Semantic.Uniform.TRANSFORM0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
    gl3.glBindVertexArray(vertexArrayName.get(Program.TEXTURE));
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

    gl3.glDisable(GL_DEPTH_TEST);

    gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl3.glUseProgram(programName[Program.SPLASH]);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindVertexArray(vertexArrayName.get(Program.SPLASH));
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RENDERBUFFER));

    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1);

    return true;
}
 
Example 19
Source File: Gl_320_fbo_integer.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL3 gl3) {

        try {

            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
            gl3.glGenTextures(Texture.MAX, textureName);
            gl3.glActiveTexture(GL_TEXTURE0);
            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            jgli.Gl.Format format = jgli.Gl.translate(jgli.Format.FORMAT_RGB8_UINT_PACK8);

            for (int level = 0; level < texture.levels(); level++) {

                gl3.glTexImage2D(GL_TEXTURE_2D, level,
                        format.internal.value,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        0,
                        format.external.value, format.type.value,
                        texture.data(level));
            }
            gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
            gl3.glBindTexture(GL_TEXTURE_2D, 0);

            gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RENDERBUFFER));
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            gl3.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, windowSize.x / framebufferSize,
                    windowSize.y / framebufferSize, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, null);
            gl3.glBindTexture(GL_TEXTURE_2D, 0);

        } catch (IOException ex) {
            Logger.getLogger(Gl_320_fbo_integer_blit.class.getName()).log(Level.SEVERE, null, ex);
        }
        return checkError(gl3, "initTexture");
    }
 
Example 20
Source File: Gl_320_draw_image_space.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);

    gl3.glUseProgram(programName);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1);

    return true;
}