Example usage for org.lwjgl.opengl GL11 glDrawArrays

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

Introduction

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

Prototype

public static void glDrawArrays(@NativeType("GLenum") int mode, @NativeType("GLint") int first,
        @NativeType("GLsizei") int count) 

Source Link

Document

Constructs a sequence of geometric primitives by successively transferring elements for count vertices.

Usage

From source file:eu.over9000.veya.rendering.Shadow.java

License:Open Source License

public void renderQuad() {
    if (quadVAO == 0) {
        final float[] quadVertices = {
                // Positions        // Texture Coords
                -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
                1.0f, -1.0f, 0.0f, 1.0f, 0.0f, };
        // Setup plane VAO

        final FloatBuffer fb = BufferUtils.createFloatBuffer(quadVertices.length);

        fb.put(quadVertices);// w  w w.j av  a  2  s  .  c  o m
        fb.flip();

        quadVAO = GL30.glGenVertexArrays();
        quadVBO = GL15.glGenBuffers();
        GL30.glBindVertexArray(quadVAO);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, quadVBO);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, fb, GL15.GL_STATIC_DRAW);
        GL20.glEnableVertexAttribArray(0);
        GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 5 * Float.BYTES, 0);
        GL20.glEnableVertexAttribArray(1);
        GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 5 * Float.BYTES, 3 * Float.BYTES);
    }
    GL30.glBindVertexArray(quadVAO);
    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4);
    GL30.glBindVertexArray(0);
}

From source file:game.level.map.TileMap.java

License:Open Source License

public void Render() {
    GL11.glPushMatrix();/*w  w w  .  ja va  2s.com*/
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0L);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
    GL11.glColorPointer(3, GL11.GL_FLOAT, 0, 0L);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBONormalHandle);
    GL11.glNormalPointer(GL11.GL_FLOAT, 0, 0L);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    if (DebugMode) {
        GL11.glDrawArrays(GL11.GL_LINE_LOOP, 0, Quads * 16);
    } else {
        GL11.glDrawArrays(GL11.GL_QUADS, 0, Quads * 16);
    }

    for (int y = 0; y < tiles.length; y++) {
        for (int x = 0; x < tiles[0].length; x++) {
            if (tiles[y][x].IsFloor) {
                try {
                    tiles[y][x].Render(x, y);
                } catch (Exception e) {

                }

            }
        }
    }
    GL11.glPopMatrix();
    // }
}

From source file:game.skybox.lwjgl.SkyboxRenderer.java

public void render() {
    GL30.glBindVertexArray(cube.getVaoID());
    GL20.glEnableVertexAttribArray(0);//from ww  w .  j a v a2  s  .c o  m
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texture);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, cube.getVertexCount());
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);
}

From source file:go.graphics.swing.opengl.LWJGLDrawContext.java

License:Open Source License

@Override
public void fillQuad(float x1, float y1, float x2, float y2) {
    ByteBuffer quadPoints = ByteBuffer.allocateDirect(4 * 2 * 4);
    quadPoints.order(ByteOrder.nativeOrder());
    FloatBuffer floatBuff = quadPoints.asFloatBuffer();
    floatBuff.put(x1);/*from   w w w  .ja va 2 s .  c o  m*/
    floatBuff.put(y1);

    floatBuff.put(x1);
    floatBuff.put(y2);

    floatBuff.put(x2);
    floatBuff.put(y2);

    floatBuff.put(x2);
    floatBuff.put(y1);

    floatBuff.position(0);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, floatBuff);
    GL11.glDrawArrays(GL11.GL_QUADS, 0, 4);
    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
}

From source file:go.graphics.swing.opengl.LWJGLDrawContext.java

License:Open Source License

@Override
public void drawLine(float[] points, boolean loop) {
    if (points.length % 3 != 0) {
        throw new IllegalArgumentException("Point array length needs to be multiple of 3.");
    }//from   w  w w  . j a va  2 s.  c o  m
    ByteBuffer floatBuff = generateTemporaryFloatBuffer(points);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, floatBuff);
    GL11.glDrawArrays(loop ? GL11.GL_LINE_LOOP : GL11.GL_LINE_STRIP, 0, points.length / 3);
    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
}

From source file:go.graphics.swing.opengl.LWJGLDrawContext.java

License:Open Source License

private void drawQuadWithTexture(TextureHandle texture, ByteBuffer buffer, int len)
        throws IllegalBufferException {
    bindTexture(texture);/*from w  w  w.  j av a 2s .com*/
    GL11.glVertexPointer(3, GL11.GL_FLOAT, 5 * 4, buffer);
    buffer.position(3 * 4);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 5 * 4, buffer);
    GL11.glDrawArrays(GL11.GL_QUADS, 0, len);
}

From source file:go.graphics.swing.opengl.LWJGLDrawContext.java

License:Open Source License

private void drawTrianglesWithTexture(TextureHandle texture, ByteBuffer buffer, int triangles)
        throws IllegalBufferException {
    bindTexture(texture);// ww  w  .j a v  a  2s .  com

    GL11.glVertexPointer(3, GL11.GL_FLOAT, 5 * 4, buffer);
    buffer.position(3 * 4);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 5 * 4, buffer);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, triangles * 3);
}

From source file:go.graphics.swing.opengl.LWJGLDrawContext.java

License:Open Source License

@Override
public void drawTrianglesWithTextureColored(TextureHandle texture, ByteBuffer buffer, int triangles)
        throws IllegalBufferException {
    bindTexture(texture);//from w ww  .j  av a 2 s.c o m

    GL11.glVertexPointer(3, GL11.GL_FLOAT, 6 * 4, buffer);
    buffer.position(3 * 4);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 6 * 4, buffer);
    buffer.position(5 * 4);
    GL11.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 6 * 4, buffer);

    GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, triangles * 3);
    GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
}

From source file:go.graphics.swing.opengl.LWJGLDrawContext.java

License:Open Source License

@Override
public void drawQuadWithTexture(TextureHandle texture, GeometryHandle geometry) throws IllegalBufferException {
    if (geometry == null) {
        throw new NullPointerException("Cannot draw a null geometry");
    }/*  w  ww. ja v a 2  s.  c om*/
    if (canUseVBOs) {
        bindTexture(texture);

        bindArrayBuffer(geometry);
        GL11.glVertexPointer(3, GL11.GL_FLOAT, 5 * 4, 0);
        GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 5 * 4, 3 * 4);

        GL11.glDrawArrays(GL11.GL_QUADS, 0, 4);

        bindArrayBuffer(null);
    } else {
        drawQuadWithTexture(texture, getGeometryBuffer(geometry), 4);
    }
}

From source file:go.graphics.swing.opengl.LWJGLDrawContext.java

License:Open Source License

@Override
public void drawTrianglesWithTexture(TextureHandle texture, GeometryHandle geometry, int triangleCount)
        throws IllegalBufferException {
    if (canUseVBOs) {
        bindTexture(texture);/* w  w w.  ja v  a  2s. c o m*/

        bindArrayBuffer(geometry);
        GL11.glVertexPointer(3, GL11.GL_FLOAT, 5 * 4, 0);
        GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 5 * 4, 3 * 4);

        GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, triangleCount * 3);

        bindArrayBuffer(null);
    } else {
        ByteBuffer buffer = getGeometryBuffer(geometry);
        buffer.rewind();
        drawTrianglesWithTexture(texture, buffer, buffer.remaining() / 5 / 4);
    }
}