SimpleCubeTextured.java


Dosyayı İndir
package com.godoro.androidopengl;

import android.graphics.*;

import java.nio.*;

import javax.microedition.khronos.opengles.*;

public class SimpleCubeTextured {

    private FloatBuffer vertexBuffer;
    private ByteBuffer indexBuffer;
    private FloatBuffer textureBuffer;



    private float vertexArray[] = {
            -1.0f, -1.0f, -1.0f,
            1.0f, -1.0f, -1.0f,
            1.0f, 1.0f, -1.0f,
            -1.0f, 1.0f, -1.0f,
            -1.0f, -1.0f, 1.0f,
            1.0f, -1.0f, 1.0f,
            1.0f, 1.0f, 1.0f,
            -1.0f, 1.0f, 1.0f
    };

    private byte indexArray[] = {
            0,1,2,
            0,2,3,
            // Back
            5,4,7,
            5,7,6,
            // Left
            4,0,3,
            4,3,7,
            // Right
            1,5,6,
            1,6,2,
            // Top
            3,2,6,
            3,6,7,
            // Bottom
            4,5,1,
            4,1,0,
    };

    private float textureArray[] = {

            1.0f, 1.0f,
            0.0f, 1.0f,
            0.0f, 0.0f,
            1.0f, 0.0f,

            1.0f, 1.0f,
            0.0f, 1.0f,
            0.0f, 0.0f,
            1.0f, 0.0f,

            1.0f, 1.0f,
            0.0f, 1.0f,
            0.0f, 0.0f,
            1.0f, 0.0f,

            1.0f, 1.0f,
            0.0f, 1.0f,
            0.0f, 0.0f,
            1.0f, 0.0f,

            1.0f, 1.0f,
            0.0f, 1.0f,
            0.0f, 0.0f,
            1.0f, 0.0f,

            1.0f, 1.0f,
            0.0f, 1.0f,
            0.0f, 0.0f,
            1.0f, 0.0f,

    };

    private float[] colorRGBA={
            1.0f,
            0.5f,
            0.3f,
            1.0f};
    private Bitmap textureBitmap;
    private int textureId=-1;
    private boolean textureShouldBeLoaded=false;

    public SimpleCubeTextured() {
        vertexBuffer = SimpleUtilities.toFloatBuffer(vertexArray);
        indexBuffer = SimpleUtilities.toByteBuffer(indexArray);
        textureBuffer=SimpleUtilities.toFloatBuffer(textureArray);
    }

    public Bitmap getTextureBitmap() {
        return textureBitmap;
    }

    public void setTextureBitmap(Bitmap textureBitmap) {
        this.textureBitmap = textureBitmap;
        textureShouldBeLoaded=true;
    }

    public void draw(GL10 gl) {

        if(textureShouldBeLoaded){
            textureId=SimpleUtilities.loadTexture(gl,textureBitmap);
            textureShouldBeLoaded=false;
        }
        if (textureId != -1 && textureBuffer != null) {
            gl.glEnable(GL10.GL_TEXTURE_2D);
            gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);


            gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
            gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
        }



        gl.glFrontFace(GL10.GL_CW);



        gl.glColor4f(colorRGBA[0],colorRGBA[1],colorRGBA[2],colorRGBA[3]);

        gl.glEnable(GL10.GL_TEXTURE_2D);
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);

        gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE,
                indexBuffer);

        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        if (textureId != -1 && textureBuffer != null) {
            gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        }
    }

}

				
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