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

The following examples show how to use com.jogamp.opengl.GL3#glBindSampler() . 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_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 2
Source File: Gl_330_sampler_anisotropy_ext.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);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glScissor(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, 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.glScissor(viewport[index].x, viewport[index].y, viewport[index].z, viewport[index].w);

        gl3.glBindSampler(0, samplerName.get(index));
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }

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

    return true;
}
 
Example 3
Source File: Gl_330_fbo_multisample_explicit_nv.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) FRAMEBUFFER_SIZE.x / FRAMEBUFFER_SIZE.y,
                0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f).scale(new Vec3(1, -1, 1));
        Mat4 mvp = perspective.mul(viewMat4()).mul(model);

        gl3.glEnable(GL_DEPTH_TEST);

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

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

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth.put(0, 1));
        gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, .5f).put(2, 0).put(3, 1));

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

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

        gl3.glDisable(GL_DEPTH_TEST);

        checkError(gl3, "renderFBO");
    }
 
Example 4
Source File: Gl_330_fbo_multisample_explicit_nv.java    From jogl-samples with MIT License 5 votes vote down vote up
private void resolveMultisampling(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.glViewport(0, 0, windowSize.x, windowSize.y);
        gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);

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

        gl3.glActiveTexture(GL_TEXTURE0);
        gl3.glBindTexture(GL_TEXTURE_RENDERBUFFER_NV, textureName.get(Texture.COLOR));
        gl3.glBindSampler(0, samplerName.get(0));

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

        gl3.glEnable(GL_SCISSOR_TEST);

        // Box
        {
            gl3.glScissor(1, 1, windowSize.x / 2 - 2, windowSize.y - 2);
            gl3.glUseProgram(programName[Program.RESOLVE_BOX]);
            gl3.glUniform1i(uniformDiffuse[Program.RESOLVE_BOX], 0);
            gl3.glUniformMatrix4fv(uniformMvp[Program.RESOLVE_BOX], 1, false, mvp.toFa_(), 0);
            gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5);
        }

        // Near
        {
            gl3.glScissor(windowSize.x / 2 + 1, 1, windowSize.x / 2 - 2, windowSize.y - 2);
            gl3.glUseProgram(programName[Program.RESOLVE_NEAR]);
            gl3.glUniform1i(uniformDiffuse[Program.RESOLVE_NEAR], 0);
            gl3.glUniformMatrix4fv(uniformMvp[Program.RESOLVE_NEAR], 1, false, mvp.toFa_(), 0);
            gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5);
        }

        gl3.glDisable(GL_SCISSOR_TEST);
    }
 
Example 5
Source File: Gl_330_sampler_wrap.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.glBindSampler(0, samplerName.get(Index));
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }

    return true;
}
 
Example 6
Source File: Gl_330_sampler_filter.java    From jogl-samples with MIT License 4 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);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

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

    // Bind the program for use
    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

    gl3.glBindSampler(Viewport.V00, samplerName.get(Viewport.V00));
    gl3.glBindSampler(Viewport.V10, samplerName.get(Viewport.V10));
    gl3.glBindSampler(Viewport.V11, samplerName.get(Viewport.V11));
    gl3.glBindSampler(Viewport.V01, samplerName.get(Viewport.V01));

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

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

    for (int index = 0; index < Viewport.MAX; ++index) {
        gl3.glUniform1i(uniformDiffuse, index);
        gl3.glScissor(viewport[index].x, viewport[index].y, viewport[index].z, viewport[index].w);
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }

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

    GL3 gl3 = (GL3) gl;

    // Pass 1
    {
        gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        gl3.glViewport(0, 0, windowSize.x >> 1, windowSize.y >> 1);
        gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1));
        gl3.glClearBufferfv(GL_COLOR, 1, clearColor);
        gl3.glClearBufferfv(GL_COLOR, 2, clearColor);
        gl3.glClearBufferfv(GL_COLOR, 3, clearColor);
    }

    // Pass 2
    gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

    gl3.glUseProgram(programNameSingle);

    {
        Mat4 projection = glm.ortho_(-2.0f, 2.0f, -1.5f, 1.5f, -1.0f, 1.0f);
        Mat4 view = new Mat4(1.0f);
        Mat4 model = new Mat4(0.2f);
        Mat4 mvp = projection.mul(view).mul(model);

        gl3.glUniformMatrix4fv(uniformMvpSingle, 1, false, mvp.toFa_(), 0);
        gl3.glUniform1i(uniformDiffuseSingle, 0);
    }

    for (int i = 0; i < Texture.MAX; ++i) {

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

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

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

    return true;
}