Examples of FloatBuffer


Examples of java.nio.FloatBuffer

    private static void logic() {
        glLoadIdentity();
        cam.applyTranslations();
        cam.applyPerspectiveMatrix();
        glGetFloat(GL_MODELVIEW_MATRIX, modelView);
        FloatBuffer projection = BufferTools.reserveData(16);
        glGetFloat(GL_PROJECTION_MATRIX, projection);
        glLoadIdentity();
        glLoadMatrix(modelView);
        glMultMatrix(projection);
        //        glGetFloat(GL_MODELVIEW_MATRIX, modelView);
View Full Code Here

Examples of java.nio.FloatBuffer

        while (Mouse.next()) {
            // If the left mouse button has been pressed ...
            if (Mouse.isButtonDown(0) && Mouse.getEventButtonState()) {
                glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
                glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
                FloatBuffer pixels = BufferTools.reserveData(3);
                // Read the pixel colour at the mouse coordinates and store the information (red-green-blue) in
                // "pixels".
                glReadPixels(Mouse.getX(), Mouse.getY(), 1, 1, GL_RGB, GL_FLOAT, pixels);
                // If the pixel colour equals the triangle's picking colour ...
                if (BufferTools.bufferEquals(pixels, pickingTriangleColour, 3)) {
View Full Code Here

Examples of java.nio.FloatBuffer

    /** Generate the shadow map. */
    private static void drawShadowMap() {
        /**
         * The model-view matrix of the light.
         */
        FloatBuffer lightModelView = BufferUtils.createFloatBuffer(16);
        /**
         * The projection matrix of the light.
         */
        FloatBuffer lightProjection = BufferUtils.createFloatBuffer(16);
        Matrix4f lightProjectionTemp = new Matrix4f();
        Matrix4f lightModelViewTemp = new Matrix4f();
        /**
         * The radius that encompasses all the objects that cast shadows in the scene. There should
         * be no object farther away than 50 units from [0, 0, 0] in any direction.
         * If an object exceeds the radius, the object may cast shadows wrongly.
         */
        float sceneBoundingRadius = 50;
        /**
         * The distance from the light to the scene, assuming that the scene is located
         * at [0, 0, 0]. Using the Pythagorean theorem, the distance is calculated by taking the square-root of the
         * sum of each of the components of the light position squared.
         */
        float lightToSceneDistance = (float) Math.sqrt(lightPosition.get(0) * lightPosition.get(0) +
                lightPosition.get(1) * lightPosition.get(1) +
                lightPosition.get(2) * lightPosition.get(2));
        /**
         * The distance to the object that is nearest to the camera. This excludes objects that do not cast shadows.
         * This will be used as the zNear parameter in gluPerspective.
         */
        float nearPlane = lightToSceneDistance - sceneBoundingRadius;
        if (nearPlane < 0) {
            System.err.println("Camera is too close to scene. A valid shadow map cannot be generated.");
        }
        /**
         * The field-of-view of the shadow frustum in degrees. Formula taken from the OpenGL SuperBible.
         */
        float fieldOfView = (float) Math.toDegrees(2.0F * Math.atan(sceneBoundingRadius / lightToSceneDistance));
        glMatrixMode(GL_PROJECTION);
        // Store the current projection matrix.
        glPushMatrix();
        glLoadIdentity();
        // Generate the 'shadow frustum', a perspective projection matrix that shows all the objects in the scene.
        gluPerspective(fieldOfView, 1, nearPlane, nearPlane + sceneBoundingRadius * 2);
        // Store the shadow frustum in 'lightProjection'.
        glGetFloat(GL_PROJECTION_MATRIX, lightProjection);
        glMatrixMode(GL_MODELVIEW);
        // Store the current model-view matrix.
        glPushMatrix();
        glLoadIdentity();
        // Have the 'shadow camera' look toward [0, 0, 0] and be location at the light's position.
        gluLookAt(lightPosition.get(0), lightPosition.get(1), lightPosition.get(2), 0, 0, 0, 0, 1, 0);
        glGetFloat(GL_MODELVIEW_MATRIX, lightModelView);
        // Set the view port to the shadow map dimensions so no part of the shadow is cut off.
        glViewport(0, 0, shadowMapWidth, shadowMapHeight);
        // Bind the extra frame buffer in which to store the shadow map in the form a depth texture.
        glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
        // Clear only the depth buffer bit. Clearing the colour buffer is unnecessary, because it is disabled (we
        // only need depth components).
        glClear(GL_DEPTH_BUFFER_BIT);
        // Store the current attribute state.
        glPushAttrib(GL_ALL_ATTRIB_BITS);
        {
            // Disable smooth shading, because the shading in a shadow map is irrelevant. It only matters where the
            // shape
            // vertices are positioned, and not what colour they have.
            glShadeModel(GL_FLAT);
            // Enabling all these lighting states is unnecessary for reasons listed above.
            glDisable(GL_LIGHTING);
            glDisable(GL_COLOR_MATERIAL);
            glDisable(GL_NORMALIZE);
            // Disable the writing of the red, green, blue, and alpha colour components,
            // because we only need the depth component.
            glColorMask(false, false, false, false);
            // An offset is given to every depth value of every polygon fragment to prevent a visual quirk called
            // 'shadow
            // acne'.
            glEnable(GL_POLYGON_OFFSET_FILL);
            // Draw the objects that cast shadows.
            drawScene();
            /**
             * Copy the pixels of the shadow map to the frame buffer object depth attachment.
             *  int target -> GL_TEXTURE_2D
             *  int level  -> 0, has to do with mip-mapping, which is not applicable to shadow maps
             *  int internalformat -> GL_DEPTH_COMPONENT
             *  int x, y -> 0, 0
             *  int width, height -> shadowMapWidth, shadowMapHeight
             *  int border -> 0
             */
            glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, shadowMapWidth, shadowMapHeight, 0);
            // Restore the previous model-view matrix.
            glPopMatrix();
            glMatrixMode(GL_PROJECTION);
            // Restore the previous projection matrix.
            glPopMatrix();
            glMatrixMode(GL_MODELVIEW);
            glBindFramebuffer(GL_FRAMEBUFFER, 0);
        }// Restore the previous attribute state.
        glPopAttrib();
        // Restore the view port.
        glViewport(0, 0, Display.getWidth(), Display.getHeight());
        lightProjectionTemp.load(lightProjection);
        lightModelViewTemp.load(lightModelView);
        lightProjection.flip();
        lightModelView.flip();
        depthModelViewProjection.setIdentity();
        // [-1,1] -> [-0.5,0.5] -> [0,1]
        depthModelViewProjection.translate(new Vector3f(0.5F, 0.5F, 0.5F));
        depthModelViewProjection.scale(new Vector3f(0.5F, 0.5F, 0.5F));
View Full Code Here

Examples of java.nio.FloatBuffer

        final int amountOfVertices = 3;
        final int vertexSize = 2;
        final int colorSize = 3;

        FloatBuffer vertexData = BufferUtils.createFloatBuffer(amountOfVertices * vertexSize);
        vertexData.put(new float[]{-0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f});
        vertexData.flip();

        FloatBuffer colorData = BufferUtils.createFloatBuffer(amountOfVertices * colorSize);
        colorData.put(new float[]{1, 0, 0, 0, 1, 0, 0, 0, 1});
        colorData.flip();

        while (!Display.isCloseRequested()) {
            glClear(GL_COLOR_BUFFER_BIT);

            glEnableClientState(GL_VERTEX_ARRAY);
View Full Code Here

Examples of java.nio.FloatBuffer

        final int amountOfVertices = 3;
        final int vertexSize = 3;
        final int colorSize = 3;

        FloatBuffer vertexData = BufferUtils.createFloatBuffer(amountOfVertices * vertexSize);
        vertexData.put(new float[]{-0.5f, -0.5f, 0, 0.5f, -0.5f, 0, 0.5f, 0.5f, 0});
        vertexData.flip();

        FloatBuffer colorData = BufferUtils.createFloatBuffer(amountOfVertices * colorSize);
        colorData.put(new float[]{1, 0, 0, 0, 1, 0, 0, 0, 1});
        colorData.flip();

        int vboVertexHandle = glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
        glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
View Full Code Here

Examples of java.nio.FloatBuffer

        glEnable(GL_CULL_FACE);
        glCullFace(GL_BACK);
        glEnable(GL_FOG);

        {
            FloatBuffer fogColours = BufferUtils.createFloatBuffer(4);
            fogColours.put(new float[]{fogColor.r, fogColor.g, fogColor.b, fogColor.a});
            glClearColor(fogColor.r, fogColor.g, fogColor.b, fogColor.a);
            fogColours.flip();
            glFog(GL_FOG_COLOR, fogColours);
            glFogi(GL_FOG_MODE, GL_LINEAR);
            glHint(GL_FOG_HINT, GL_NICEST);
            glFogf(GL_FOG_START, fogNear);
            glFogf(GL_FOG_END, fogFar);
View Full Code Here

Examples of java.nio.FloatBuffer

        glEnable(GL_FOG);

        Controller joystick = ControllerEnvironment.getDefaultEnvironment().getControllers()[0];

        {
            FloatBuffer fogColours = BufferUtils.createFloatBuffer(4);
            fogColours.put(new float[]{fogColor.r, fogColor.g, fogColor.b, fogColor.a});
            glClearColor(fogColor.r, fogColor.g, fogColor.b, fogColor.a);
            fogColours.flip();
            glFog(GL_FOG_COLOR, fogColours);
            glFogi(GL_FOG_MODE, GL_LINEAR);
            glHint(GL_FOG_HINT, GL_NICEST);
            glFogf(GL_FOG_START, fogNear);
            glFogf(GL_FOG_END, fogFar);
View Full Code Here

Examples of java.nio.FloatBuffer

    private static void render() {
        glClear(GL_COLOR_BUFFER_BIT); // | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT
        glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
        if (useReadPixels) {
            FloatBuffer colorAtMouse = BufferTools.reserveData(16);
            int mouse_x = Mouse.getX();
            int mouse_y = Mouse.getY();
            for (int i = 0; i < 50; i++) {
                glReadPixels(mouse_x, mouse_y, 1, 1, GL_RGB, GL_FLOAT, colorAtMouse);
                if (colorAtMouse.get(0) + colorAtMouse.get(1) + colorAtMouse.get(2) > 0.5f) {
                    glColor3d(0.8, 0.8, 0);
                } else {
                    glColor3f(1, 1, 1);
                }
            }
View Full Code Here

Examples of java.nio.FloatBuffer

     * plane of the box has it's own copy of the texture coordinates. That is, the texture coordinates are repeated for
     * each six faces.
     */
    private void setTextureData() {
        TriMesh triMesh;
  FloatBuffer tex;
  int mask = 0x1;

  for (int i = 0; i < 6; i++, mask <<= 1) {
            triMesh = faces[i];
      if ((texturedFaces & mask) != 0) {
    FloatBuffer tbuf = BufferUtils.createVector2Buffer(4);
    triMesh.setTextureCoords(new TexCoords(tbuf));
    tbuf.put(1).put(0);
    tbuf.put(0).put(0);
    tbuf.put(0).put(1);
    tbuf.put(1).put(1);
      } else {
    triMesh.setTextureCoords(new TexCoords(null));
      }
  }
    }
View Full Code Here

Examples of java.nio.FloatBuffer

  /** Bulk input of a float array. */
  public float[] readFloats (int length) throws KryoException {
    if (capacity - position >= length * 4 && isNativeOrder()) {
      float[] array = new float[length];
      FloatBuffer buf = niobuffer.asFloatBuffer();
      buf.get(array);
      position += length * 4;
      niobuffer.position(position);
      return array;
    } else
      return super.readFloats(length);
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.