GLMesh.java


Dosyayı İndir
package com.godoro.androidopengl;

import android.graphics.*;
import android.opengl.*;

import java.nio.*;

import javax.microedition.khronos.opengles.*;

public class GLMesh {

    private FloatBuffer mVerticesBuffer = null;
    private ShortBuffer mIndicesBuffer = null;
    private FloatBuffer mTextureBuffer;

    private int mTextureId = -1;
    private Bitmap mBitmap;

    private boolean mShouldLoadTexture = false;

    private int mNumOfIndices = -1;

    private final float[] mRGBA = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };


    private FloatBuffer mColorBuffer = null;

    public float x = 0;

    public float y = 0;

    public float z = 0;

    public float rx = 0;

    public float ry = 0;

    public float rz = 0;

    public void draw(GL10 gl) {
        gl.glFrontFace(GL10.GL_CCW);
        gl.glEnable(GL10.GL_CULL_FACE);
        gl.glCullFace(GL10.GL_BACK);
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVerticesBuffer);
        gl.glColor4f(mRGBA[0], mRGBA[1], mRGBA[2], mRGBA[3]);
        if (mColorBuffer != null) {
            gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
            gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColorBuffer);
        }


        if (mShouldLoadTexture) {
            mTextureId=GLUtilities.loadTexture(gl,mBitmap);
            mShouldLoadTexture = false;
        }
        if (mTextureId != -1 && mTextureBuffer != null) {
            gl.glEnable(GL10.GL_TEXTURE_2D);
            gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);


            gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);
            gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureId);
        }


        gl.glTranslatef(x, y, z);
        gl.glRotatef(rx, 1, 0, 0);
        gl.glRotatef(ry, 0, 1, 0);
        gl.glRotatef(rz, 0, 0, 1);


        gl.glDrawElements(GL10.GL_TRIANGLES, mNumOfIndices,
                GL10.GL_UNSIGNED_SHORT, mIndicesBuffer);

        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);


        if (mTextureId != -1 && mTextureBuffer != null) {
            gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        }

        gl.glDisable(GL10.GL_CULL_FACE);
    }


    protected void setVertices(float[] vertices) {
        mVerticesBuffer=GLUtilities.toFloatBuffer(vertices);
    }

    protected void setIndices(short[] indices) {
        mIndicesBuffer=GLUtilities.toShortBuffer(indices);
        mNumOfIndices = indices.length;
    }


    protected void setTextureCoordinates(float[] textureCoords) {
        mTextureBuffer=GLUtilities.toFloatBuffer(textureCoords);
    }


    protected void setColor(float red, float green, float blue, float alpha) {
        mRGBA[0] = red;
        mRGBA[1] = green;
        mRGBA[2] = blue;
        mRGBA[3] = alpha;
    }


    protected void setColors(float[] colors) {
        mColorBuffer=GLUtilities.toFloatBuffer(colors);
    }

    public void loadBitmap(Bitmap bitmap) {
        this.mBitmap = bitmap;
        mShouldLoadTexture = true;
    }



}

				
Dosyayı İndir

Bu Sayfayı Paylaş:




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir