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:opengl.Player.java

public void Draw() {
    float[] vertices = { (0.0f * ScaleX) + x, (0.0f * ScaleY) + y, (0.0f * ScaleX) + x, (1.0f * ScaleY) + y,
            (1.0f * ScaleX) + x, (1.0f * ScaleY) + y, (1.0f * ScaleX) + x, (0.0f * ScaleY) + y };
    FloatBuffer triangle = BufferUtils.createFloatBuffer(vertices.length);
    triangle.put(vertices);//from  ww  w. j ava2 s .  c  o m
    triangle.flip();
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    // GL11.glColorPointer(3, GL11.GL_FLOAT, 0, triangleVertexBuffer);
    GL11.glVertexPointer(2, 0, triangle);
    GL11.glDrawArrays(GL11.GL_QUADS, 0, vertices.length / 2);
    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
}

From source file:opengl.test.object.endgame.endgame.java

public void render(int status) {

    this.bind();// use porgrma --> ket thuc disable program

    GL30.glBindVertexArray(this.vao);// bind vao -- > unbind vao
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    this.VertexAttribPointer();

    GL20.glEnableVertexAttribArray(0);// set index ve 0 
    if (status == endgame.win)
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDWIN);
    else if (status == endgame.lose)
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDLOSE);
    else//www  .j  a  v a 2s  . co m
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDDRAW);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.size);
    //GL11.glDrawElements(GL11.GL_TRIANGLES, this.indices.capacity(), GL11.GL_UNSIGNED_INT, 0);// capacity --> luon luon chua max
    //GL11.
    GL20.glDisableVertexAttribArray(0);// disable 

    GL30.glBindVertexArray(0);// unbind vao

    this.unbind();// dsiable program
}

From source file:opengl.test.object.table.table.java

@Override
public void render() {

    this.bind();// use porgrma --> ket thuc disable program

    GL30.glBindVertexArray(this.vao);// bind vao -- > unbind vao
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    this.VertexAttribPointer();

    GL20.glEnableVertexAttribArray(0);// set index ve 0 

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.size);
    //GL11.glDrawElements(GL11.GL_TRIANGLES, this.indices.capacity(), GL11.GL_UNSIGNED_INT, 0);// capacity --> luon luon chua max
    //GL11.//from   w  w w.  j  ava 2 s.  com
    GL20.glDisableVertexAttribArray(0);// disable 

    GL30.glBindVertexArray(0);// unbind vao

    this.unbind();// dsiable program
}

From source file:opengl.test.object.tivi.tivi.java

@Override
public void render() {

    this.bind();// use porgrma --> ket thuc disable program

    GL30.glBindVertexArray(this.vao);// bind vao -- > unbind vao
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    this.VertexAttribPointer();

    GL20.glEnableVertexAttribArray(0);// set index ve 0 
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.size);
    //GL11.glDrawElements(GL11.GL_TRIANGLES, this.indices.capacity(), GL11.GL_UNSIGNED_INT, 0);// capacity --> luon luon chua max
    //GL11./*from  www.ja v  a 2  s  .co m*/
    GL20.glDisableVertexAttribArray(0);// disable 

    GL30.glBindVertexArray(0);// unbind vao

    this.unbind();// dsiable program
}

From source file:org.ajgl.graphics.VertexArrays.java

License:Open Source License

/**
 * Draws the vertex array; Uses redundant vertices. You need to enable 
 * {@link org.lwjgl.opengl.GL11#GL_VERTEX_ARRAY GL_VERTEX_ARRAY} before 
 * you can use this method.//from  w  w  w  . j  a va2 s. c om
 * @param beginMode - The OpenGL begin mode
 * @param vertexPointData - The number of points per vertex data (i.e. 1-1D, 2-2D, 3-3D)
 * @param vertexNumber - The number of vertices
 * @param first - The start point of the array
 * @param stride - The stride offset; used for interleaving data
 * @param vertices - The vertex vertices
 */
@OpenGLInfo(fwdCompatible = false, openGLVersion = "1.1", status = "Release")
public static void drawArrays(@BeginMode int beginMode, int vertexPointData, int vertexNumber, int first,
        int stride, FloatBuffer vertices) {
    // point to and draw vertex array
    GL11.glVertexPointer(vertexPointData, stride, vertices);
    GL11.glDrawArrays(beginMode, first, vertexNumber);
}

From source file:org.ajgl.graphics.VertexBufferedObject.java

License:Open Source License

/**
 * Draws a vertex buffered object; Uses redundant vertices. You need to enable 
 * {@link org.lwjgl.opengl.GL11#GL_VERTEX_ARRAY GL_VERTEX_ARRAY} before 
 * you can use this method./*from w w  w . j  a v  a 2  s . c  o m*/
 * @param vertexHandler - The vertex buffered object vertex handler
 * @param vertexPointData - The number of points per vertex data (i.e. 1-1D, 2-2D, 3-3D)
 * @param vertexNumber - The number of vertices
 * @param first - The start point of the array
 * @param stride - The stride offset; used for interleaving data
 * @param offSet - initial offset for the data
 * @param dataType - The OpenGL dataType
 * @param beginMode - The OpenGL begin mode
 */
public static void drawVboArrays(int vertexHandler, int vertexPointData, int vertexNumber, int first,
        int stride, int offSet, @GLDataType int dataType, @BeginMode int beginMode) {
    // bind vertex data
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexHandler);
    GL11.glVertexPointer(vertexPointData, dataType, stride, offSet);
    // Draw vertex buffer object
    GL11.glDrawArrays(beginMode, first, vertexNumber);
}

From source file:org.bonsaimind.badgersvoyage.opengl.RenderObject.java

License:Open Source License

public void render() {
    GL30.glBindVertexArray(vaoId);
    GL20.glEnableVertexAttribArray(0);

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, verticesCount);
}

From source file:org.craftmania.rendering.ChunkMeshRenderer.java

License:Apache License

public static void renderChunkMesh(Chunk chunk, MeshType meshType) {
    if (chunk.getMesh().getVBO(meshType) <= 0) {
        return;//from www.  j a  v a 2s  . c  o  m
    }

    /* Bind the correct texture */
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    TextureStorage.getTexture("terrain").bind();

    if (meshType == MeshType.OPAQUE) {
        GL11.glDisable(GL11.GL_BLEND);
    } else if (meshType == MeshType.TRANSLUCENT) {
        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 mesh = chunk.getMesh();

    /* Bind the buffer */
    ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, mesh.getVBO(meshType));

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

    // System.out.println("Chunk Vertices = " + mesh.getVertexCount());

    /* 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);
    GL11.glColorPointer(COLOR_SIZE, GL11.GL_FLOAT, STRIDE * FLOAT_SIZE, COLOR_OFFSET * FLOAT_SIZE);

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

    /* Unbind the buffer */
    ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);

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

    if (meshType == MeshType.TRANSLUCENT) {
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glDisable(GL11.GL_ALPHA_TEST);
    }
}

From source file:org.free.jake2.render.lwjgl.Surf.java

License:Open Source License

/**
 * DrawGLFlowingPoly// ww w.  j  ava2 s  .  c  o  m
 * version that handles scrolling texture
 */
void DrawGLFlowingPoly(glpoly_t p) {
    float scroll = -64 * ((r_newrefdef.time / 40.0f) - (int) (r_newrefdef.time / 40.0f));
    if (scroll == 0.0f) {
        scroll = -64.0f;
    }
    p.beginScrolling(scroll);
    GL11.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts);
    p.endScrolling();
}

From source file:org.free.jake2.render.lwjgl.Surf.java

License:Open Source License

/**
 * GL_RenderLightmappedPoly/*from w  ww .ja  v a 2  s  .  c om*/
 * @param surf
 */
void GL_RenderLightmappedPoly(msurface_t surf) {

    // ersetzt goto
    boolean gotoDynamic = false;
    int map;
    for (map = 0; map < Defines.MAXLIGHTMAPS && (surf.styles[map] != (byte) 255); map++) {
        if (r_newrefdef.lightstyles[surf.styles[map] & 0xFF].white != surf.cached_light[map]) {
            gotoDynamic = true;
            break;
        }
    }

    // this is a hack from cwei
    if (map == 4) {
        map--;
    }

    // dynamic this frame or dynamic previously
    boolean is_dynamic = false;
    if (gotoDynamic || (surf.dlightframe == r_framecount)) {
        //   label dynamic:
        if (gl_dynamic.value != 0) {
            if ((surf.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66
                    | Defines.SURF_WARP)) == 0) {
                is_dynamic = true;
            }
        }
    }

    glpoly_t p;
    FloatBuffer texCoord = globalPolygonInterleavedBuf;
    image_t image = R_TextureAnimation(surf.texinfo);
    int lmtex = surf.lightmaptexturenum;

    if (is_dynamic) {
        // ist raus gezogen worden int[] temp = new int[128*128];
        int smax, tmax;

        if (((surf.styles[map] & 0xFF) >= 32 || surf.styles[map] == 0) && (surf.dlightframe != r_framecount)) {
            smax = (surf.extents[0] >> 4) + 1;
            tmax = (surf.extents[1] >> 4) + 1;

            R_BuildLightMap(surf, temp, smax);
            R_SetCacheState(surf);

            GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + surf.lightmaptexturenum);

            lmtex = surf.lightmaptexturenum;

            GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, surf.light_s, surf.light_t, smax, tmax,
                    GL_LIGHTMAP_FORMAT, GL11.GL_UNSIGNED_BYTE, temp);

        } else {
            smax = (surf.extents[0] >> 4) + 1;
            tmax = (surf.extents[1] >> 4) + 1;

            R_BuildLightMap(surf, temp, smax);

            GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + 0);

            lmtex = 0;

            GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, surf.light_s, surf.light_t, smax, tmax,
                    GL_LIGHTMAP_FORMAT, GL11.GL_UNSIGNED_BYTE, temp);

        }

        c_brush_polys++;

        GL_MBind(GL_TEXTURE0, image.texnum);
        GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + lmtex);

        // ==========
        //     PGM
        if ((surf.texinfo.flags & Defines.SURF_FLOWING) != 0) {
            float scroll;

            scroll = -64 * ((r_newrefdef.time / 40.0f) - (int) (r_newrefdef.time / 40.0f));
            if (scroll == 0.0f) {
                scroll = -64.0f;
            }

            for (p = surf.polys; p != null; p = p.chain) {
                p.beginScrolling(scroll);
                GL11.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts);
                p.endScrolling();
            }
        } else {
            for (p = surf.polys; p != null; p = p.chain) {
                GL11.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts);
            }
        }
        // PGM
        // ==========
    } else {
        c_brush_polys++;

        GL_MBind(GL_TEXTURE0, image.texnum);
        GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + lmtex);

        // ==========
        //     PGM
        if ((surf.texinfo.flags & Defines.SURF_FLOWING) != 0) {
            float scroll;

            scroll = -64 * ((r_newrefdef.time / 40.0f) - (int) (r_newrefdef.time / 40.0f));
            if (scroll == 0.0) {
                scroll = -64.0f;
            }

            for (p = surf.polys; p != null; p = p.chain) {
                p.beginScrolling(scroll);
                GL11.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts);
                p.endScrolling();
            }
        } else {
            // PGM
            //  ==========
            for (p = surf.polys; p != null; p = p.chain) {
                GL11.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts);
            }

            // ==========
            // PGM
        }
        // PGM
        // ==========
    }
}