Package javax.media.opengl

Examples of javax.media.opengl.GL3


    @Override
    public void reshape(GLAutoDrawable glad, int x, int y, int w, int h) {
        System.out.println("reshape() x: " + x + " y: " + y + " width: " + w + " height: " + h);

        GL3 gl3 = glad.getGL().getGL3();

        gl3.glViewport(x, y, w, h);
    }
View Full Code Here


    public void init(GLAutoDrawable glad) {
        System.out.println("init");

        canvas.setAutoSwapBufferMode(false);

        GL3 gl3 = glad.getGL().getGL3();

        buildShaders(gl3);

        initializeVertexBuffer(gl3);

        texture = initializeTexture(gl3);

        gl3.glGenVertexArrays(1, IntBuffer.wrap(vertexArrayObject));
        gl3.glBindVertexArray(vertexArrayObject[0]);

        gl3.glEnable(GL3.GL_CULL_FACE);
        gl3.glCullFace(GL3.GL_BACK);
        gl3.glFrontFace(GL3.GL_CW);
    }
View Full Code Here

    @Override
    public void display(GLAutoDrawable glad) {
        System.out.println("display");

        GL3 gl3 = glad.getGL().getGL3();

        gl3.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        gl3.glClear(GL3.GL_COLOR_BUFFER_BIT);

        programObject.bind(gl3);
        {
            gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBufferObject[0]);

            gl3.glEnableVertexAttribArray(0);
            gl3.glEnableVertexAttribArray(1);
            {
                gl3.glActiveTexture(GL3.GL_TEXTURE0);
                texture.enable(gl3);
                texture.bind(gl3);
                gl3.glUniform1i(textureUnLoc, 0);
               
                gl3.glVertexAttribPointer(0, 4, GL3.GL_FLOAT, false, 0, 0);
                gl3.glVertexAttribPointer(1, 2, GL3.GL_FLOAT, false, 0, 4 * 4 * 4);

                gl3.glDrawArrays(GL3.GL_QUADS, 0, 4);
               
                texture.disable(gl3);
            }
            gl3.glDisableVertexAttribArray(0);
            gl3.glDisableVertexAttribArray(1);
        }
        programObject.unbind(gl3);

        glad.swapBuffers();
    }
View Full Code Here

        pmv.glTranslatef((float) (-(cp.max(X) + cp.min(X)) / 2.0), (float) (-(cp.max(Y) + cp.min(Y)) / 2.0), 0f);
    }

    @Override
    public void dispose(GLAutoDrawable drawable) {
        final GL3 gl = drawable.getGL().getGL3();

        shaderState.bind(gl);
        shaderState.destroy(gl);
        vertices.destroy(gl);
    }
View Full Code Here

    }

    @Override
    public void display(GLAutoDrawable drawable) {
        try {
            final GL3 gl = drawable.getGL().getGL3();
            shaderState.bind(gl);
            vao.bind(gl);
            int spaceshipLoc = gl.glGetUniformLocation(shaderProgram.program(), "spaceshipTex");
            gl.glUniform1i(spaceshipLoc, 0);
            gl.glActiveTexture(GL.GL_TEXTURE0);
            gl.glBindTexture(GL.GL_TEXTURE_2D, spaceshipTex.getTextureObject(gl));

            int explosionLoc = gl.glGetUniformLocation(shaderProgram.program(), "explosionTex");
            gl.glUniform1i(explosionLoc, 1);
            gl.glActiveTexture(GL.GL_TEXTURE0 + 1);
            gl.glBindTexture(GL.GL_TEXTURE_2D, explosionTex.getTextureObject(gl));

            vertices.clear();
            colors.clear();
            final FloatBuffer verticesb = (FloatBuffer) vertices.getBuffer();
            final FloatBuffer colorsb = (FloatBuffer) colors.getBuffer();
            long now = global.now();
            long clock = System.currentTimeMillis();
            fixPort(clock, true);
            MutableAABB currentPort = getCurrentPort(clock);
            portToMvMatrix(currentPort);
            double margins = WIDTH_MARGINS;

            final int n;
            if (clock - lastQueryTime > SB_QUERY_RATE) {
                n = query(now, SpatialQueries.contained(AABB.create(currentPort.min(X) - margins, currentPort.max(X) + margins, currentPort.min(Y) - margins, currentPort.max(Y) + margins)));
                lastQueryTime = clock;
            } else {
                n = indexGen.get();
                lastDispTime = clock;
            }

            int countInPort = 0;
            for (Record<SpaceshipState> s : ships.slice(0, n)) {
                long extrapolationTime = global.extrapolate ? Math.min(now, s.get($lastMoved) + MAX_EXTRAPOLATION_DURATION) : s.get($lastMoved);
                Spaceship.getCurrentLocation(s, extrapolationTime, verticesb);

                if (s.get($blowTime) > 0// 0.01 - start blow animation, 1.0 - end of animation
                    colorsb.put(Math.min(1.0f, (now - s.get($blowTime)) / EXPLOSION_DURATION));
                else
                    colorsb.put(0); // ship isn't blowing up
                colorsb.put((float) Spaceship.getCurrentHeading(s, extrapolationTime));

                // put the shotLength (0 for ship that's not firing)
                colorsb.put(now - s.get($timeFired) < SHOOT_DURATION ? (float) s.get($shotLength) : 0f);

                if (portContains(s.get($x), s.get($y)))
                    countInPort++;
            }
            setTitle((glxNode >= 0 ? "Node " + glxNode + ": " : "")
                    + countInPort + " Spaceships "
                    + (int) (port.max(X) - port.min(X)) + "x" + (int) (port.max(Y) - port.min(Y)));

            vertices.flip();
            colors.flip();

            int numElems = verticesb.limit() / 2;
            vertices.write(gl, 0, numElems);
            colors.write(gl, 0, numElems);

            shaderState.setUniform(gl, "in_Matrix", 4, 4, pmv.glGetMvMatrixf());

            gl.glClear(GL3.GL_COLOR_BUFFER_BIT);
            gl.glDrawArrays(GL3.GL_POINTS, 0, numElems);

            vao.unbind(gl);
            shaderState.unbind(gl);
        } catch (Throwable t) {
            System.err.println("XXXXXX");
View Full Code Here

TOP

Related Classes of javax.media.opengl.GL3

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.