Example usage for org.lwjgl.opengl GL11 GL_VERTEX_ARRAY

List of usage examples for org.lwjgl.opengl GL11 GL_VERTEX_ARRAY

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 GL_VERTEX_ARRAY.

Prototype

int GL_VERTEX_ARRAY

To view the source code for org.lwjgl.opengl GL11 GL_VERTEX_ARRAY.

Click Source Link

Document

vertex_array

Usage

From source file:com.colonycraft.rendering.world.ChunkMeshRenderer.java

License:Apache License

public static void renderChunkMesh(World world, Chunk chunk, int meshType) {
    /* Bind the correct texture */
    GL11.glEnable(GL11.GL_TEXTURE_2D);/*from  w w w.  j av a 2 s  .co m*/
    TextureStorage.getTexture("terrain").bind();

    if (meshType == ChunkMesh.MESH_OPAQUE) {
        GL11.glDisable(GL11.GL_BLEND);
    } else if (meshType == ChunkMesh.MESH_TRANSLUCENT || meshType == ChunkMesh.MESH_GRASS) {
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_ALPHA_TEST);
        GL11.glAlphaFunc(GL11.GL_GREATER, 0.0f);
    }

    ChunkMesh cmesh = chunk.getMesh();
    Mesh mesh = cmesh.getMesh(meshType);
    if (mesh == null)
        return;

    /* Bind the buffer */
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, mesh.getVertexBufferHandle());

    /* Enable the different kinds of data in the buffer */
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

    if (meshType == ChunkMesh.MESH_GRASS) {
        GL20.glEnableVertexAttribArray(GRASS_ATTRIBUTE_LIGHT);
    } else {
        GL20.glEnableVertexAttribArray(CHUNK_ATTRIBUTE_LIGHT);
    }

    /* Define the starting positions */
    GL11.glVertexPointer(POSITION_SIZE, GL11.GL_FLOAT, STRIDE * FLOAT_SIZE, POSITION_OFFSET * FLOAT_SIZE);
    GL11.glTexCoordPointer(TEX_COORD_SIZE, GL11.GL_FLOAT, STRIDE * FLOAT_SIZE, TEX_COORD_OFFSET * FLOAT_SIZE);
    GL20.glVertexAttribPointer(CHUNK_ATTRIBUTE_LIGHT, 2, GL11.GL_FLOAT, false, STRIDE * FLOAT_SIZE,
            LIGHT_OFFSET * FLOAT_SIZE);

    /* Draw the buffer */
    GL11.glDrawArrays(GL11.GL_QUADS, 0, mesh.vertices());

    /* Unbind the buffer */
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    /* Disable the different kinds of data */
    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

    if (meshType == ChunkMesh.MESH_GRASS) {
        GL20.glDisableVertexAttribArray(GRASS_ATTRIBUTE_LIGHT);
    } else {
        GL20.glDisableVertexAttribArray(CHUNK_ATTRIBUTE_LIGHT);
    }

    if (meshType == ChunkMesh.MESH_TRANSLUCENT || meshType == ChunkMesh.MESH_GRASS) {
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glDisable(GL11.GL_ALPHA_TEST);
    }
}

From source file:com.dinasgames.engine.graphics.GL.java

public static void render(Vertex[] verts) {

    init();// w w w  .j  av  a  2 s.  c om

    int numberIndices = verts.length / 3;
    vertexBuffer = BufferUtils.createFloatBuffer(verts.length * 2);
    colorBuffer = BufferUtils.createFloatBuffer(verts.length);
    indexBuffer = BufferUtils.createFloatBuffer(verts.length);

    vertexBuffer.clear();
    colorBuffer.clear();
    indexBuffer.clear();

    for (Vertex vert : verts) {

        vertexBuffer.put(vert.x);
        vertexBuffer.put(vert.y);

        GLColor c = vert.color.toGLColor();

        colorBuffer.put(c.getRed());
        colorBuffer.put(c.getGreen());
        colorBuffer.put(c.getBlue());
        colorBuffer.put(c.getAlpha());

    }

    vertexBufferData(vertexBufferID, vertexBuffer);
    colorBufferData(colorBufferID, colorBuffer);

    // Push verticies to OpenGL
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferID);
    GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);

    // Push color values to OpenGL
    GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, colorBufferID);
    GL11.glColorPointer(4, GL11.GL_FLOAT, 0, 0);

    // Draw the shape
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
    GL11.glDrawElements(GL11.GL_TRIANGLES, numberIndices, GL11.GL_UNSIGNED_INT, 0);

    // Disalble client state for vertex and color
    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);

}

From source file:com.dinasgames.engine.graphics.RenderTarget.java

public void draw(Vertex[] verts, PrimitiveType type, RenderStates states) {

    if (verts == null) {
        return;/*from  w  w w  .  ja v  a  2 s  . com*/
    }

    if (verts.length == 0) {
        return;
    }

    if (activate(true)) {

        if (!mCache.glStatesSet) {
            resetGLStates();
        }

        boolean useVertexCache = (verts.length <= StatusCache.VertexCacheSize);
        if (useVertexCache) {

            for (int i = 0; i < verts.length; i++) {

                Vertex v = mCache.vertexCache[i];

                Vector2f p = Transform.multiply(states.transform, new Vector2f(verts[i].x, verts[i].y));

                v.x = p.x;
                v.y = p.y;

                v.color = verts[i].color;
                v.tx = verts[i].tx;
                v.ty = verts[i].ty;

            }

            if (!mCache.useVertexCache) {
                applyTransform(Transform.Identity);
            }

        } else {
            applyTransform(states.transform);
        }

        if (mCache.viewChanged) {
            applyCurrentView();
        }

        if (!mCache.lastBlendMode.equals(states.blendMode)) {
            applyBlendMode(states.blendMode);
        }

        int textureId = (states.texture != null ? states.texture.getTextureID() : 0);
        if (textureId != mCache.lastTextureId) {
            applyTexture(states.texture);
        }

        if (useVertexCache) {
            if (!mCache.useVertexCache) {
                verts = new Vertex[mCache.vertexCache.length];
                for (int i = 0; i < mCache.vertexCache.length; i++) {
                    verts[i] = new Vertex(mCache.vertexCache[i]);
                }
            } else {
                //verts = null;
                return;
            }
        }

        if (verts != null) {

            // Create some buffers to store vertex and color data
            FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(verts.length * 2);
            FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(verts.length * 4);
            FloatBuffer tcBuffer = BufferUtils.createFloatBuffer(verts.length * 2);

            // Copy the vertex and color data to the buffers
            for (Vertex vert : verts) {

                // Write vertex coordinate (XY)
                vertexBuffer.put(vert.x);
                vertexBuffer.put(vert.y);

                tcBuffer.put(vert.tx);
                tcBuffer.put(vert.ty);

                // Write Color (RGBA)
                GLColor c = vert.color.toGLColor();
                colorBuffer.put(c.getRed());
                colorBuffer.put(c.getGreen());
                colorBuffer.put(c.getBlue());
                colorBuffer.put(c.getAlpha());

            }

            // Flip the buffer so it can be used
            vertexBuffer.flip();
            colorBuffer.flip();
            tcBuffer.flip();

            GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
            GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
            GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

            // Give the buffers to OpenGL
            GL11.glVertexPointer(2, 0, vertexBuffer);
            GL11.glColorPointer(4, 0, colorBuffer);
            GL11.glTexCoordPointer(2, 0, tcBuffer);

        }

        int mode = -1;

        switch (type) {
        case Points:
            mode = GL11.GL_POINTS;
            break;
        case Lines:
            mode = GL11.GL_LINES;
            break;
        case LinesStrip:
            mode = GL11.GL_LINE_STRIP;
            break;
        case Triangles:
            mode = GL11.GL_TRIANGLES;
            break;
        case TrianglesStrip:
            mode = GL11.GL_TRIANGLE_STRIP;
            break;
        case TrianglesFan:
            mode = GL11.GL_TRIANGLE_FAN;
            break;
        case Quads:
            mode = GL11.GL_QUADS;
            break;
        }

        if (mode == -1) {
            return;
        }

        if (verts != null) {
            GL11.glDrawArrays(mode, 0, verts.length);
        }

        mCache.useVertexCache = useVertexCache;

    }

}

From source file:com.dinasgames.engine.graphics.RenderTarget.java

public void resetGLStates() {

    //if(true){return;}

    if (activate(true)) {
        //GL11.glShadeModel(GL11.GL_SMOOTH);
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_ALPHA_TEST);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);//from w  w w  .  j a  va  2  s . c o  m
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
        GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        //GL11.glEnable(GL13.GL_MULTISAMPLE);
        mCache.glStatesSet = true;

        applyBlendMode(BlendMode.BlendAlpha);
        applyTransform(Transform.Identity);
        applyTexture(null);

        mCache.useVertexCache = false;

        setView(new View(getView()));

    }
}

From source file:com.owens.oobjloader.lwjgl.VBO.java

License:BSD License

public void render() {

    GL11.glEnable(GL11.GL_TEXTURE_2D);/*from w w w . j  a v a 2  s .c  o m*/
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textId); // Bind The Texture

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, verticeAttributesID);

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, ATTR_V_STRIDE2_BYTES, ATTR_V_OFFSET_BYTES);

    GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
    GL11.glNormalPointer(GL11.GL_FLOAT, ATTR_N_STRIDE2_BYTES, ATTR_N_OFFSET_BYTES);

    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, ATTR_T_STRIDE2_BYTES, ATTR_T_OFFSET_BYTES);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesID);
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_INT, 0);

    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
}

From source file:com.timvisee.voxeltex.module.mesh.Mesh.java

License:Open Source License

/**
 * Render or draw the mesh using OpenGL.
 *//*  www .j  a v a 2s.c  o m*/
public void draw(Material material) {
    // Bind the vertex buffer
    glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
    GL11.glVertexPointer(this.raw.getVertexAxisCount(), GL11.GL_FLOAT, 0, 0L);

    // Bind the normal coordinate buffer if available
    if (hasNormalData()) {
        glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
        GL11.glNormalPointer(GL11.GL_FLOAT, 0, 0L);
    }

    // Bind the texture coordinate buffer if available
    if (hasTextureData()) {
        glBindBuffer(GL_ARRAY_BUFFER, vboTextureHandle);
        GL11.glTexCoordPointer(this.raw.getTextureAxisCount(), GL11.GL_FLOAT, 0, 0L);
    }

    // Enable the client states for the buffers that were bound
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    if (hasNormalData())
        GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
    if (hasTextureData())
        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

    // Draw the mesh
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.vertexCount);

    // Disable the client used states
    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
    if (hasNormalData())
        GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
    if (hasTextureData())
        GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

    // Unbind all buffers
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:de.codesourcery.flocking.LWJGLRenderer.java

License:Apache License

private void renderWorld(World world) {
    final double modelMax = world.getSimulationParameters().modelMax;
    xInc = Display.getWidth() / modelMax;
    yInc = Display.getHeight() / modelMax;

    GL11.glEnable(GL11.GL_DEPTH_TEST);//from  w w w.  j  av  a2 s  .  co  m
    GL11.glDepthMask(true);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDepthMask(false);

    GL11.glColor3f(0.5f, 0.5f, 1.0f);

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);

    final int triangleCount = world.getPopulationCount();

    // setup vertex data       
    final int vertexArrayLen = triangleCount * 3 * 2; // one triangle = 3 vertices * 2 int's per vertex
    final MyIntBuffer vertexBuffer = getVertexBuffer(vertexArrayLen);

    final IntBuffer vertexIntBuffer = vertexBuffer.getBuffer();
    final IBoidVisitor visitor = new IBoidVisitor() {

        @Override
        public void visit(Boid boid) {
            drawBoid(boid, vertexIntBuffer);
        }
    };
    world.visitAllBoids(visitor);

    vertexBuffer.rewind();

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBuffer.getHandle());
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexBuffer.getBuffer(), GL15.GL_DYNAMIC_DRAW);
    GL11.glVertexPointer(2, GL11.GL_INT, 0, 0);

    // setup index data
    MyIntBuffer indexBuffer = getIndexBuffer(triangleCount * 3);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBuffer.getHandle());
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBuffer.getBuffer(), GL15.GL_STATIC_DRAW);

    GL11.glDrawElements(GL11.GL_TRIANGLES, triangleCount * 3, GL11.GL_UNSIGNED_INT, 0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthMask(true);
}

From source file:espresso3d.engine.renderer.E3DGeometryRenderer.java

License:Open Source License

/**
 * Sets the OGL environment up to render points
 * /*from   w  w w.j  a  va 2s.c  o m*/
 * Disables textures, and vertex arrays
 *
 */
public void initPointRenderer() {
    //    if(currentRenderMode == RENDERMODE_POINT)
    //         return;

    /*       GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
    GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do
    GL11.glHint (GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);         // Set Perspective Calculations To Most Accurate
    */
    disableAllTextureUnits();
    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);

}

From source file:espresso3d.engine.renderer.E3DGeometryRenderer.java

License:Open Source License

public void initSolidAndLineRendering() {
    GL11.glDepthMask(true);/*from   w  ww.ja  va2 s. c o m*/
    GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
    GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); // Set Perspective Calculations To Most Accurate

    disableAllTextureUnits();
    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
}

From source file:espresso3d.engine.renderer.E3DGeometryRenderer.java

License:Open Source License

public void initTexturedRendering() {
    //       GL11.glDepthMask(true);
    //        GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
    //      GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do

    GL11.glDepthMask(true);//from w ww  .  ja  v  a  2 s .c o  m
    GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
    GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do
    GL11.glDisable(GL11.GL_BLEND);

    ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

}