Code example for GL11

Methods: glColor4f, glDrawArrays, glMultMatrixf, glPopMatrix, glPushMatrix, glScalef, glTexEnvf, glTranslatef

0
        } 
 
        GL11 gl = mGL;
        mLastAlpha = alpha;
        if (alpha >= 0.95f) {
            gl.glTexEnvf(GL11.GL_TEXTURE_ENV,
                         GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
        } else { 
            gl.glTexEnvf(GL11.GL_TEXTURE_ENV,
                         GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
            gl.glColor4f(alpha, alpha, alpha, alpha);
        } 
    } 
 
    public void drawRect(int x, int y, int width, int height) {
        float[] matrix = mMatrixValues;
        mTransformation.getMatrix().getValues(matrix);
        drawRect(x, y, width, height, matrix, mTransformation.getAlpha());
    } 
 
    private void drawRect( 
        int x, int y, int width, int height, float[] matrix, float alpha) {
        GL11 gl = mGL;
        gl.glPushMatrix();
        setAlphaValue(alpha);
        gl.glMultMatrixf(toGLMatrix(matrix), 0);
        gl.glTranslatef(x, y, 0);
        gl.glScalef(width, height, 1);
        gl.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4);
        gl.glPopMatrix();
    } 
 
    public void drawRect(int x, int y, int width, int height, float alpha) {
        float[] matrix = mMatrixValues;
        mTransformation.getMatrix().getValues(matrix);
        drawRect(x, y, width, height, matrix, alpha);
    } 
 
    private float[] mapPoints(Matrix matrix, int x1, int y1, int x2, int y2) {
        float[] point = mPointBuffer;
        point[0] = x1;
        point[1] = y1;
        point[2] = x2;
        point[3] = y2;
        matrix.mapPoints(point);
        return point;
    } 
 
    public void clipRect(int x0, int y0, int width0, int height0) {
        float[] point = mapPoints(mTransformation.getMatrix(), x0, y0 + height0, x0 + width0, y0);
 
        int x, y, width, height;
        // mMatrix could be a rotation matrix. In this case, we need to find 
        // the boundaries after rotation. (only handle 90 * n degrees) 
        if (point[0] > point[2]) {
            x = (int) point[2];
            width = (int) point[0] - x;
        } else { 
            x = (int) point[0];
            width = (int) point[2] - x;
        } 
        if (point[1] > point[3]) {
            y = (int) point[3];
            height = (int) point[1] - y;
        } else { 
            y = (int) point[1];
            height = (int) point[3] - y;
        } 
        mGL.glScissor(x, y, width, height);
    } 
 
    public void clearClip() { 
        mGL.glScissor(0, 0, getWidth(), getHeight());
    } 
 
    private static float[] toGLMatrix(float[] v) {
        v[15] = v[8];
        v[13] = v[5];
        v[5] = v[4];
        v[4] = v[1];
        v[12] = v[2];
        v[1] = v[3];
        v[3] = v[6];
        v[2] = 0;
        v[6] = 0;
        v[8] = 0;
        v[9] = 0;
        v[10] = 1;
        return v;
    } 
 
    public void drawTexture( 
        Texture texture, int x0, int y0, int width0, int height0, float alpha) {
 
        if (!texture.bind(this, mGL)) {
            throw new RuntimeException("cannot bind" + texture.toString());
        } 
        if (width0 <= 0 || height0 <= 0) return;
 
        Matrix matrix = mTransformation.getMatrix();