Example usage for org.lwjgl.opengl GL11 glDrawElements

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

Introduction

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

Prototype

public static void glDrawElements(@NativeType("GLenum") int mode,
        @NativeType("void const *") IntBuffer indices) 

Source Link

Document

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

Usage

From source file:jake2.desktop.LWJGLAdapter.java

License:Open Source License

@Override
public void glDrawElements(int mode, ShortBuffer indices) {
    GL11.glDrawElements(mode, indices);
}

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java

License:Open Source License

@Override
public void drawElements(int primitive, int count, int indexType, Buffer indices, int indicesOffset) {
    switch (indexType) {
    case IRenderingEngine.RE_UNSIGNED_BYTE:
        GL11.glDrawElements(primitiveToGL[primitive],
                DirectBufferUtilities.getDirectByteBuffer(count, indices, indicesOffset));
        break;/*w w  w . j  av a2s.co m*/
    case IRenderingEngine.RE_UNSIGNED_SHORT:
        GL11.glDrawElements(primitiveToGL[primitive],
                DirectBufferUtilities.getDirectShortBuffer(count << 1, indices, indicesOffset));
        break;
    case IRenderingEngine.RE_UNSIGNED_INT:
        GL11.glDrawElements(primitiveToGL[primitive],
                DirectBufferUtilities.getDirectIntBuffer(count << 2, indices, indicesOffset));
        break;
    default:
        log.error(String.format("drawElements unknown indexType=%d", indexType));
        break;
    }
}

From source file:kuake2.render.lwjgl.Mesh.java

License:Open Source License

/**
 * GL_DrawAliasFrameLerp/*  w w w  .  j a va  2  s .  c  o m*/
 * <p/>
 * interpolates between two frames and origins
 * FIXME: batch lerp all vertexes
 */
void GL_DrawAliasFrameLerp(qfiles.dmdl_t paliashdr, float backlerp) {
    qfiles.daliasframe_t frame = paliashdr.aliasFrames[currententity.frame];

    int[] verts = frame.verts;

    qfiles.daliasframe_t oldframe = paliashdr.aliasFrames[currententity.oldframe];

    int[] ov = oldframe.verts;

    float alpha;
    if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0)
        alpha = currententity.alpha;
    else
        alpha = 1.0f;

    // PMM - added double shell
    if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE
            | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0)
        GL11.glDisable(GL11.GL_TEXTURE_2D);

    float frontlerp = 1.0f - backlerp;

    // move should be the delta back to the previous frame * backlerp
    Math3D.VectorSubtract(currententity.oldorigin, currententity.origin, frontv);
    Math3D.AngleVectors(currententity.angles, vectors[0], vectors[1], vectors[2]);

    move[0] = Math3D.DotProduct(frontv, vectors[0]); // forward
    move[1] = -Math3D.DotProduct(frontv, vectors[1]); // left
    move[2] = Math3D.DotProduct(frontv, vectors[2]); // up

    Math3D.VectorAdd(move, oldframe.translate, move);

    for (int i = 0; i < 3; i++) {
        move[i] = backlerp * move[i] + frontlerp * frame.translate[i];
        frontv[i] = frontlerp * frame.scale[i];
        backv[i] = backlerp * oldframe.scale[i];
    }

    // ab hier wird optimiert

    GL_LerpVerts(paliashdr.num_xyz, ov, verts, move, frontv, backv);

    //GL11.glEnableClientState( GL11.GL_VERTEX_ARRAY );
    GL11.glVertexPointer(3, 0, vertexArrayBuf);

    // PMM - added double damage shell
    if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE
            | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) {
        GL11.glColor4f(shadelight[0], shadelight[1], shadelight[2], alpha);
    } else {
        GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
        GL11.glColorPointer(4, 0, colorArrayBuf);

        //
        // pre light everything
        //
        FloatBuffer color = colorArrayBuf;
        float l;
        int size = paliashdr.num_xyz;
        int j = 0;
        for (int i = 0; i < size; i++) {
            l = shadedots[(verts[i] >>> 24) & 0xFF];
            color.put(j, l * shadelight[0]);
            color.put(j + 1, l * shadelight[1]);
            color.put(j + 2, l * shadelight[2]);
            color.put(j + 3, alpha);
            j += 4;
        }
    }

    ARBMultitexture.glClientActiveTextureARB(GL_TEXTURE0);
    GL11.glTexCoordPointer(2, 0, textureArrayBuf);
    //GL11.glEnableClientState( GL11.GL_TEXTURE_COORD_ARRAY);

    int pos = 0;
    int[] counts = paliashdr.counts;

    IntBuffer srcIndexBuf = null;

    FloatBuffer dstTextureCoords = textureArrayBuf;
    FloatBuffer srcTextureCoords = paliashdr.textureCoordBuf;

    int dstIndex = 0;
    int srcIndex = 0;
    int count;
    int mode;
    int size = counts.length;
    for (int j = 0; j < size; j++) {

        // get the vertex count and primitive type
        count = counts[j];
        if (count == 0)
            break; // done

        srcIndexBuf = paliashdr.indexElements[j];

        mode = GL11.GL_TRIANGLE_STRIP;
        if (count < 0) {
            mode = GL11.GL_TRIANGLE_FAN;
            count = -count;
        }
        srcIndex = pos << 1;
        srcIndex--;
        for (int k = 0; k < count; k++) {
            dstIndex = srcIndexBuf.get(k) << 1;
            dstTextureCoords.put(dstIndex, srcTextureCoords.get(++srcIndex));
            dstTextureCoords.put(++dstIndex, srcTextureCoords.get(++srcIndex));
        }

        GL11.glDrawElements(mode, srcIndexBuf);
        pos += count;
    }

    // PMM - added double damage shell
    if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE
            | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0)
        GL11.glEnable(GL11.GL_TEXTURE_2D);

    GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
}

From source file:loon.core.graphics.opengl.LWjglGL10.java

License:Apache License

public final void glDrawElements(int mode, int count, int type, Buffer indices) {
    if (indices instanceof ShortBuffer && type == GL10.GL_UNSIGNED_SHORT) {
        GL11.glDrawElements(mode, (ShortBuffer) indices);
    } else if (indices instanceof ByteBuffer && type == GL10.GL_UNSIGNED_SHORT) {
        GL11.glDrawElements(mode, ((ByteBuffer) indices).asShortBuffer());
    } else if (indices instanceof ByteBuffer && type == GL10.GL_UNSIGNED_BYTE) {
        GL11.glDrawElements(mode, (ByteBuffer) indices);
    } else {//w  w  w . j a  va 2s.c  o  m
        throw new RuntimeException("Can't use " + indices.getClass().getName()
                + " with this method. Use ShortBuffer or ByteBuffer instead. Blame LWJGL");
    }
}

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

License:Open Source License

/**
 * GL_DrawAliasFrameLerp//w  w  w. j  a v  a 2 s .  c  om
 *
 * interpolates between two frames and origins FIXME: batch lerp all vertexes
 */
void GL_DrawAliasFrameLerp(qfiles.dmdl_t paliashdr, float backlerp) {
    qfiles.daliasframe_t frame = paliashdr.aliasFrames[currententity.frame];

    int[] verts1 = frame.verts;

    qfiles.daliasframe_t oldframe = paliashdr.aliasFrames[currententity.oldframe];

    int[] ov = oldframe.verts;

    float alpha;
    if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) {
        alpha = currententity.alpha;
    } else {
        alpha = 1.0f;
    }

    // PMM - added double shell
    if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE
            | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) {
        GL11.glDisable(GL11.GL_TEXTURE_2D);
    }

    float frontlerp = 1.0f - backlerp;

    // move should be the delta back to the previous frame * backlerp
    Math3D.VectorSubtract(currententity.oldorigin, currententity.origin, frontv);
    Math3D.AngleVectors(currententity.angles, vectors[0], vectors[1], vectors[2]);

    move[0] = Math3D.DotProduct(frontv, vectors[0]); // forward
    move[1] = -Math3D.DotProduct(frontv, vectors[1]); // left
    move[2] = Math3D.DotProduct(frontv, vectors[2]); // up

    Math3D.VectorAdd(move, oldframe.translate, move);

    for (int i = 0; i < 3; i++) {
        move[i] = backlerp * move[i] + frontlerp * frame.translate[i];
        frontv[i] = frontlerp * frame.scale[i];
        backv[i] = backlerp * oldframe.scale[i];
    }

    // ab hier wird optimiert
    GL_LerpVerts(paliashdr.num_xyz, ov, verts1, move, frontv, backv);

    //GL11.glEnableClientState( GL11.GL_VERTEX_ARRAY );
    GL11.glVertexPointer(3, 0, vertexArrayBuf);

    // PMM - added double damage shell
    if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE
            | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) {
        GL11.glColor4f(shadelight[0], shadelight[1], shadelight[2], alpha);
    } else {
        GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
        GL11.glColorPointer(4, 0, colorArrayBuf);

        //
        // pre light everything
        //
        FloatBuffer color = colorArrayBuf;
        float l;
        int size = paliashdr.num_xyz;
        int j = 0;
        for (int i = 0; i < size; i++) {
            l = shadedots[(verts1[i] >>> 24) & 0xFF];
            color.put(j, l * shadelight[0]);
            color.put(j + 1, l * shadelight[1]);
            color.put(j + 2, l * shadelight[2]);
            color.put(j + 3, alpha);
            j += 4;
        }
    }

    GL13.glClientActiveTexture(GL_TEXTURE0);
    GL11.glTexCoordPointer(2, 0, textureArrayBuf);
    //GL11.glEnableClientState( GL11.GL_TEXTURE_COORD_ARRAY);

    int pos = 0;
    int[] counts = paliashdr.counts;

    IntBuffer srcIndexBuf = null;

    FloatBuffer dstTextureCoords = textureArrayBuf;
    FloatBuffer srcTextureCoords = paliashdr.textureCoordBuf;

    int dstIndex = 0;
    int srcIndex = 0;
    int count;
    int mode;
    int size = counts.length;
    for (int j = 0; j < size; j++) {

        // get the vertex count and primitive type
        count = counts[j];
        if (count == 0) {
            break; // done
        }
        srcIndexBuf = paliashdr.indexElements[j];

        mode = GL11.GL_TRIANGLE_STRIP;
        if (count < 0) {
            mode = GL11.GL_TRIANGLE_FAN;
            count = -count;
        }
        srcIndex = pos << 1;
        srcIndex--;
        for (int k = 0; k < count; k++) {
            dstIndex = srcIndexBuf.get(k) << 1;
            dstTextureCoords.put(dstIndex, srcTextureCoords.get(++srcIndex));
            dstTextureCoords.put(++dstIndex, srcTextureCoords.get(++srcIndex));
        }

        GL11.glDrawElements(mode, srcIndexBuf);
        pos += count;
    }

    // PMM - added double damage shell
    if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE
            | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) {
        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }

    GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
}

From source file:org.oscim.gdx.GdxGL20.java

License:Apache License

public void glDrawElements(int mode, int count, int type, Buffer indices) {
    if (indices instanceof ShortBuffer && type == GL_UNSIGNED_SHORT)
        GL11.glDrawElements(mode, (ShortBuffer) indices);
    else if (indices instanceof ByteBuffer && type == GL_UNSIGNED_SHORT)
        GL11.glDrawElements(mode, ((ByteBuffer) indices).asShortBuffer()); // FIXME yay...
    else if (indices instanceof ByteBuffer && type == GL_UNSIGNED_BYTE)
        GL11.glDrawElements(mode, (ByteBuffer) indices);
    else//  w  ww.j a v a2s . c o m
        throw new GdxRuntimeException("Can't use " + indices.getClass().getName()
                + " with this method. Use ShortBuffer or ByteBuffer instead. Blame LWJGL");
}

From source file:org.oscim.gdx.LwjglGL20.java

License:Apache License

public void drawElements(int mode, int count, int type, Buffer indices) {
    if (indices instanceof ShortBuffer && type == com.badlogic.gdx.graphics.GL20.GL_UNSIGNED_SHORT)
        GL11.glDrawElements(mode, (ShortBuffer) indices);
    else if (indices instanceof ByteBuffer && type == com.badlogic.gdx.graphics.GL20.GL_UNSIGNED_SHORT)
        GL11.glDrawElements(mode, ((ByteBuffer) indices).asShortBuffer()); // FIXME yay...
    else if (indices instanceof ByteBuffer && type == com.badlogic.gdx.graphics.GL20.GL_UNSIGNED_BYTE)
        GL11.glDrawElements(mode, (ByteBuffer) indices);
    else/*from   w  w w.  j a  v a 2  s. co  m*/
        throw new GdxRuntimeException("Can't use " + indices.getClass().getName()
                + " with this method. Use ShortBuffer or ByteBuffer instead. Blame LWJGL");
}

From source file:playn.java.JavaGL20.java

License:Apache License

@Override
public void glDrawElements(int mode, int count, int type, Buffer indices) {
    if (indices instanceof ShortBuffer && type == GL_UNSIGNED_SHORT)
        GL11.glDrawElements(mode, (ShortBuffer) indices);
    else if (indices instanceof ByteBuffer && type == GL_UNSIGNED_SHORT)
        GL11.glDrawElements(mode, ((ByteBuffer) indices).asShortBuffer()); // FIXME
    // yay.../*  w w w .j  a v a  2s  . c  o  m*/
    else if (indices instanceof ByteBuffer && type == GL_UNSIGNED_BYTE)
        GL11.glDrawElements(mode, (ByteBuffer) indices);
    else
        throw new RuntimeException("Can't use " + indices.getClass().getName()
                + " with this method. Use ShortBuffer or ByteBuffer instead. Blame LWJGL");
}

From source file:processing.lwjgl.PLWJGL.java

License:Open Source License

public void drawElements(int mode, int count, int type, Buffer indices) {
    if (type == UNSIGNED_INT) {
        GL11.glDrawElements(mode, (IntBuffer) indices);
    } else if (type == UNSIGNED_BYTE) {
        GL11.glDrawElements(mode, (ByteBuffer) indices);
    } else if (type == UNSIGNED_SHORT) {
        GL11.glDrawElements(mode, (ShortBuffer) indices);
    }//from  w ww.ja va 2  s.  c  o m
}

From source file:processing.opengl.PLWJGL.java

License:Open Source License

@Override
public void drawElements(int mode, int count, int type, Buffer indices) {
    if (type == UNSIGNED_INT) {
        GL11.glDrawElements(mode, (IntBuffer) indices);
    } else if (type == UNSIGNED_BYTE) {
        GL11.glDrawElements(mode, (ByteBuffer) indices);
    } else if (type == UNSIGNED_SHORT) {
        GL11.glDrawElements(mode, (ShortBuffer) indices);
    }//w w  w .  j  a v a  2 s.c o  m
}