Examples of FloatBuffer


Examples of java.nio.FloatBuffer

         * Vertex Arrays and Vertex Buffer Objects
         */

        // Create a new FloatBuffer (complex array of floats) with the capacity
        // of the length of the points * 3 (because we have 3 vertices per point)
        FloatBuffer vertexArray = BufferUtils.createFloatBuffer(points.length * 3);
        // Iterate over all the points and store them in the FloatBuffer
        for (Point p : points) {
            vertexArray.put(new float[]{p.x, p.y, p.z});
        }
        // Make the buffer read-able for OpenGL
        vertexArray.flip();

        // Create the handle for the VBO
        int vertexBufferObject = glGenBuffers();
        // Bind the VBO for usage (in this case: storing information)
        glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
View Full Code Here

Examples of java.nio.FloatBuffer

        } catch (IOException e) {
            e.printStackTrace();
            cleanUp();
            System.exit(1);
        }
        FloatBuffer vertices = BufferTools.reserveData(model.getFaces().size() * 9);
        FloatBuffer normals = BufferTools.reserveData(model.getFaces().size() * 9);
        for (Model.Face face : model.getFaces()) {
            vertices.put(BufferTools.asFloats(model.getVertices().get(face.getVertexIndices()[0] - 1)));
            vertices.put(BufferTools.asFloats(model.getVertices().get(face.getVertexIndices()[1] - 1)));
            vertices.put(BufferTools.asFloats(model.getVertices().get(face.getVertexIndices()[2] - 1)));
            normals.put(BufferTools.asFloats(model.getNormals().get(face.getNormalIndices()[0] - 1)));
            normals.put(BufferTools.asFloats(model.getNormals().get(face.getNormalIndices()[1] - 1)));
            normals.put(BufferTools.asFloats(model.getNormals().get(face.getNormalIndices()[2] - 1)));
        }
        vertices.flip();
        normals.flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
        glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
        glBufferData(GL_ARRAY_BUFFER, normals, GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
View Full Code Here

Examples of java.nio.FloatBuffer

    }

    /** Generate the shadow map. */
    private static void generateShadowMap() {
        float lightToSceneDistance, nearPlane, fieldOfView;
        FloatBuffer lightModelView = BufferUtils.createFloatBuffer(16);
        FloatBuffer lightProjection = BufferUtils.createFloatBuffer(16);
        Matrix4f lightProjectionTemp = new Matrix4f();
        Matrix4f lightModelViewTemp = new Matrix4f();

        float sceneBoundingRadius = 95.0F;

        lightToSceneDistance = (float) Math.sqrt(lightPosition.get(0) * lightPosition.get(0) + lightPosition.get(1) *
                lightPosition.get(1) + lightPosition.get(2) * lightPosition.get(2));

        nearPlane = lightToSceneDistance - sceneBoundingRadius;

        fieldOfView = (float) Math.toDegrees(2.0F * Math.atan(sceneBoundingRadius / lightToSceneDistance));

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(fieldOfView, 1.0F, nearPlane, nearPlane + (2.0F * sceneBoundingRadius));
        glGetFloat(GL_PROJECTION_MATRIX, lightProjection);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(lightPosition.get(0), lightPosition.get(1), lightPosition.get(2), 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F);
        glGetFloat(GL_MODELVIEW_MATRIX, lightModelView);
        glViewport(0, 0, shadowWidth, shadowHeight);

        if (useFBO) {
            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffer);
        }

        glClear(GL_DEPTH_BUFFER_BIT);

        // Set rendering states to the minimum required, for speed.
        glShadeModel(GL_FLAT);
        glDisable(GL_LIGHTING);
        glDisable(GL_COLOR_MATERIAL);
        glDisable(GL_NORMALIZE);
        glColorMask(false, false, false, false);

        glEnable(GL_POLYGON_OFFSET_FILL);

        renderObjects(false);

        glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, shadowWidth, shadowHeight, 0);

        // Unbind the framebuffer if we are using them.
        if (useFBO) {
            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
        }

        // Setup the rendering states.
        glShadeModel(GL_SMOOTH);
        glEnable(GL_LIGHTING);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_NORMALIZE);
        glColorMask(true, true, true, true);
        glDisable(GL_POLYGON_OFFSET_FILL);

        lightProjectionTemp.load(lightProjection);
        lightModelViewTemp.load(lightModelView);
        lightProjection.flip();
        lightModelView.flip();

        Matrix4f tempMatrix = new Matrix4f();
        tempMatrix.setIdentity();
        tempMatrix.translate(new Vector3f(0.5F, 0.5F, 0.5F));
View Full Code Here

Examples of java.nio.FloatBuffer

            /*
                    * If we dont have the ambient shadow extention, we will need to
                    * add an extra rendering pass.
                    */
            if (!ambientShadowsAvailable) {
                FloatBuffer lowAmbient = BufferUtils.createFloatBuffer(4);
                lowAmbient.put(new float[]{0.1F, 0.1F, 0.1F, 1.0F});
                lowAmbient.flip();

                FloatBuffer lowDiffuse = BufferUtils.createFloatBuffer(4);
                lowDiffuse.put(new float[]{0.35F, 0.35F, 0.35F, 1.0F});
                lowDiffuse.flip();

                glLight(GL_LIGHT0, GL_AMBIENT, lowAmbient);
                glLight(GL_LIGHT0, GL_DIFFUSE, lowDiffuse);

                renderObjects(true);
View Full Code Here

Examples of java.nio.FloatBuffer

    public static int[] createVBO(Model model) {
        int vboVertexHandle = glGenBuffers();
        int vboNormalHandle = glGenBuffers();
        // TODO: Implement materials with VBOs
        FloatBuffer vertices = reserveData(model.getFaces().size() * 9);
        FloatBuffer normals = reserveData(model.getFaces().size() * 9);
        for (Model.Face face : model.getFaces()) {
            vertices.put(asFloats(model.getVertices().get(face.getVertexIndices()[0] - 1)));
            vertices.put(asFloats(model.getVertices().get(face.getVertexIndices()[1] - 1)));
            vertices.put(asFloats(model.getVertices().get(face.getVertexIndices()[2] - 1)));
            normals.put(asFloats(model.getNormals().get(face.getNormalIndices()[0] - 1)));
            normals.put(asFloats(model.getNormals().get(face.getNormalIndices()[1] - 1)));
            normals.put(asFloats(model.getNormals().get(face.getNormalIndices()[2] - 1)));
        }
        vertices.flip();
        normals.flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
        glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
        glVertexPointer(3, GL_FLOAT, 0, 0L);
        glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
        glBufferData(GL_ARRAY_BUFFER, normals, GL_STATIC_DRAW);
View Full Code Here

Examples of java.nio.FloatBuffer

     * @param matrix4f the Matrix4f that is to be turned into a readable FloatBuffer
     *
     * @return a FloatBuffer representation of matrix4f
     */
    public static FloatBuffer asFloatBuffer(Matrix4f matrix4f) {
        FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
        matrix4f.store(buffer);
        return buffer;
    }
View Full Code Here

Examples of java.nio.FloatBuffer

     * @param matrix4f the Matrix4f that is to be turned into a FloatBuffer that is readable to OpenGL (but not to you)
     *
     * @return a FloatBuffer representation of matrix4f
     */
    public static FloatBuffer asFlippedFloatBuffer(Matrix4f matrix4f) {
        FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
        matrix4f.store(buffer);
        buffer.flip();
        return buffer;
    }
View Full Code Here

Examples of java.nio.FloatBuffer

     * @param values the float values that are to be turned into a readable FloatBuffer
     *
     * @return a readable FloatBuffer containing values
     */
    public static FloatBuffer asFloatBuffer(float... values) {
        FloatBuffer buffer = BufferUtils.createFloatBuffer(values.length);
        buffer.put(values);
        return buffer;
    }
View Full Code Here

Examples of java.nio.FloatBuffer

     * @param values the float values that are to be turned into a FloatBuffer
     *
     * @return a FloatBuffer readable to OpenGL (not to you!) containing values
     */
    public static FloatBuffer asFlippedFloatBuffer(float... values) {
        FloatBuffer buffer = BufferUtils.createFloatBuffer(values.length);
        buffer.put(values);
        buffer.flip();
        return buffer;
    }
View Full Code Here

Examples of java.nio.FloatBuffer

        int[] vbos;
        try {
            model = OBJLoader.loadModel(new File(MODEL_LOCATION));
            int vboVertexHandle = glGenBuffers();
            int vboNormalHandle = glGenBuffers();
            FloatBuffer vertices = BufferTools.reserveData(model.getFaces().size() * 9);
            FloatBuffer normals = BufferTools.reserveData(model.getFaces().size() * 9);
            for (Model.Face face : model.getFaces()) {
                vertices.put(BufferTools.asFloats(model.getVertices().get(face.getVertexIndices()[0] - 1)));
                vertices.put(BufferTools.asFloats(model.getVertices().get(face.getVertexIndices()[1] - 1)));
                vertices.put(BufferTools.asFloats(model.getVertices().get(face.getVertexIndices()[2] - 1)));
                normals.put(BufferTools.asFloats(model.getNormals().get(face.getNormalIndices()[0] - 1)));
                normals.put(BufferTools.asFloats(model.getNormals().get(face.getNormalIndices()[1] - 1)));
                normals.put(BufferTools.asFloats(model.getNormals().get(face.getNormalIndices()[2] - 1)));
            }
            vertices.flip();
            normals.flip();
            glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
            glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
            glEnableVertexAttribArray(attributeVertex);
            glVertexAttribPointer(attributeVertex, 3, GL_FLOAT, false, 0, 0L);
            glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.