Search in sources :

Example 1 with GL3Viewer

use of maspack.render.GL.GL3.GL3Viewer in project artisynth_core by artisynth.

the class MultiViewer method addGL3Viewer.

public void addGL3Viewer(String title, int x, int y, int w, int h) {
    if (gl3resources == null) {
        GLProfile glp3 = GLProfile.get(GLProfile.GL3);
        GLCapabilities cap = new GLCapabilities(glp3);
        cap.setSampleBuffers(true);
        cap.setNumSamples(8);
        // get attribute map from GLSL generator
        StringIntPair[] attributes = GLSLGenerator.ATTRIBUTES;
        GL3VertexAttributeMap attributeMap = new GL3VertexAttributeMap(new GL3VertexAttributeInfo(attributes[0].getString(), attributes[0].getInt()), new GL3VertexAttributeInfo(attributes[1].getString(), attributes[1].getInt()), new GL3VertexAttributeInfo(attributes[2].getString(), attributes[2].getInt()), new GL3VertexAttributeInfo(attributes[3].getString(), attributes[3].getInt()));
        for (int i = 4; i < attributes.length; ++i) {
            attributeMap.add(new GL3VertexAttributeInfo(attributes[i].getString(), attributes[i].getInt()));
        }
        gl3resources = new GL3SharedResources(cap, attributeMap);
    }
    GLViewer viewer = new GL3Viewer(null, gl3resources, w, h);
    addViewer(title, viewer, x, y, w, h);
}
Also used : GL3VertexAttributeInfo(maspack.render.GL.GL3.GL3VertexAttributeInfo) GLCapabilities(com.jogamp.opengl.GLCapabilities) GLViewer(maspack.render.GL.GLViewer) GL3SharedResources(maspack.render.GL.GL3.GL3SharedResources) GL3Viewer(maspack.render.GL.GL3.GL3Viewer) GL3VertexAttributeMap(maspack.render.GL.GL3.GL3VertexAttributeMap) StringIntPair(maspack.render.GL.GL3.GLSLGenerator.StringIntPair) GLProfile(com.jogamp.opengl.GLProfile)

Example 2 with GL3Viewer

use of maspack.render.GL.GL3.GL3Viewer in project artisynth_core by artisynth.

the class DebuggingGL3Test method addContent.

@Override
protected void addContent(maspack.test.GL.MultiViewer mv) {
    SimpleSelectable ss = new SimpleSelectableBase() {

        final File[] shaders = { new File(PathFinder.findSourceDir(GL3Viewer.class) + "/shaders/debug_vertex.glsl"), new File(PathFinder.findSourceDir(GL3Viewer.class) + "/shaders/debug_fragment.glsl") };

        int vao = 0;

        int vbo = 0;

        boolean initialized = false;

        private void init(GL3 gl) {
            int[] ibuff = new int[10];
            gl.glGenVertexArrays(1, ibuff, 0);
            vao = ibuff[0];
            gl.glGenBuffers(1, ibuff, 1);
            vbo = ibuff[1];
            fill(gl);
            initialized = true;
        }

        private void fill(GL3 gl) {
            gl.glBindVertexArray(vao);
            float[] triangle = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f };
            java.nio.ByteBuffer vbuff = java.nio.ByteBuffer.allocateDirect(4 * triangle.length);
            for (float f : triangle) {
                vbuff.putFloat(f);
            }
            vbuff.flip();
            gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo);
            gl.glBufferData(GL3.GL_ARRAY_BUFFER, vbuff.limit(), vbuff, GL3.GL_STATIC_DRAW);
        }

        @Override
        public void render(Renderer renderer, int flags) {
            GL3Viewer viewer = (GL3Viewer) renderer;
            GL3 gl = viewer.getGL().getGL3();
            GLSupport.checkAndPrintGLError(gl);
            viewer.setShaderOverride(shaders, shaders);
            if (!initialized) {
                init(gl);
            }
            viewer.useProgram(gl, shaders);
            gl.glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
            gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);
            // re-bind vao
            fill(gl);
            gl.glBindVertexArray(vao);
            gl.glEnableVertexAttribArray(0);
            gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo);
            gl.glVertexAttribPointer(0, 3, GL3.GL_FLOAT, false, 0, 0);
            gl.glDrawArrays(GL3.GL_TRIANGLES, 0, 3);
            gl.glDisableVertexAttribArray(0);
            gl.glBindVertexArray(0);
            viewer.setShaderOverride(null, null);
        // throw new RuntimeException("Exit rendering");
        }
    };
    mv.addRenderable(ss);
}
Also used : SimpleSelectable(maspack.test.GL.MultiViewer.SimpleSelectable) Renderer(maspack.render.Renderer) GL3Viewer(maspack.render.GL.GL3.GL3Viewer) File(java.io.File) GL3(com.jogamp.opengl.GL3)

Aggregations

GL3Viewer (maspack.render.GL.GL3.GL3Viewer)2 GL3 (com.jogamp.opengl.GL3)1 GLCapabilities (com.jogamp.opengl.GLCapabilities)1 GLProfile (com.jogamp.opengl.GLProfile)1 File (java.io.File)1 GL3SharedResources (maspack.render.GL.GL3.GL3SharedResources)1 GL3VertexAttributeInfo (maspack.render.GL.GL3.GL3VertexAttributeInfo)1 GL3VertexAttributeMap (maspack.render.GL.GL3.GL3VertexAttributeMap)1 StringIntPair (maspack.render.GL.GL3.GLSLGenerator.StringIntPair)1 GLViewer (maspack.render.GL.GLViewer)1 Renderer (maspack.render.Renderer)1 SimpleSelectable (maspack.test.GL.MultiViewer.SimpleSelectable)1