Android Open Source - minecraft-connect-4 Texture






From Project

Back to project page minecraft-connect-4.

License

The source code is released under:

MIT License

If you think the Android project minecraft-connect-4 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/* COPYRIGHT (C) 2014 Aleksandr Belkin. All Rights Reserved. */
package sq.squ1rr.mcc4.board;
/*w w  w. j  a va  2  s.  com*/
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLUtils;
import sq.squ1rr.mcc4.R;

/**
 * Initialises textures and saves some info about them.
 * @author Aleksandr Belkin
 */
public enum Texture {
    MENU      (R.drawable.menu),            // menu button
    DIRT      (R.drawable.dirt_dark_hd),    // dirt texture
    GRASS     (R.drawable.grass_hd),        // grass texture
    PLAYER1   (R.drawable.player),          // player sprite
    PLAYER2   (-1),                         // opponent sprite (defined later)
    TOKEN1    (-1),                         // player #1 token (defined later)
    TOKEN2    (-1);                         // player #2 token (defined later)
    
    /** hold resource ID for the texture */
    private int resourceId;
    
    /** OpenGL texture ID */
    private int textureId;
    
    /** texture width */
    private int width;
    
    /** texture height */
    private int height;
    
    /**
     * Constructor
     * @param _resourceId
     */
    Texture(int _resourceId) {
        resourceId = _resourceId;
    }
    
    /**
     * Set custom resource ID
     * @param _resourceId
     */
    public void setResource(int _resourceId) {
        resourceId = _resourceId;
    }
    
    /**
     * Returns resource ID
     * @return
     */
    public int getResource() {
        return resourceId;
    }
    
    /**
     * Loads texture from resources to OpenGL texture
     * @param gl
     * @param context
     * @param _textureId
     */
    public void load(GL10 gl, Context context, int _textureId) {
        textureId = _textureId;
        
        // bind texture
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
        
        // create nearest filtered texture
        gl.glTexParameterf(
            GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST
        );
        gl.glTexParameterf(
            GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR
        );
        
        // load bitmap
        Bitmap bitmap = BitmapFactory.decodeResource(
            context.getResources(), resourceId
        );
        
        // create two-dimensional texture image from our bitmap 
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
        
        width = bitmap.getWidth();
        height = bitmap.getHeight();
        
        // Clean up
        bitmap.recycle();
    }
    
    /**
     * Sets texture ID
     * @param _textureId
     */
    public void set(int _textureId) {
        textureId = _textureId;
    }
    
    /**
     * Returns texture ID
     * @return
     */
    public int get() {
        return textureId;
    }
    
    /**
     * Returns height of the texture
     * @return
     */
    public int getHeight() {
        return height;
    }
    
    /**
     * Returns width of the texture
     * @return
     */
    public int getWidth() {
        return width;
    }
    
    /**
     * Initialises all the textures provided that all of them do have
     * resources associated
     * @param gl
     * @param context
     */
    public static void initialise(GL10 gl, Context context) {
        int[] textures = new int[Texture.values().length];
        
        Texture[] values = Texture.values();
        
        // generate one texture pointer
        gl.glGenTextures(values.length, textures, 0);
        
        for(int i = 0; i < values.length; ++i) {
            values[i].load(gl, context, textures[i]);
        }
    }
}




Java Source Code List

sq.squ1rr.mcc4.AboutMenu.java
sq.squ1rr.mcc4.BaseActivity.java
sq.squ1rr.mcc4.GameActivity.java
sq.squ1rr.mcc4.MainMenuActivity.java
sq.squ1rr.mcc4.MainMenu.java
sq.squ1rr.mcc4.MenuLayout.java
sq.squ1rr.mcc4.OptionsMenu.java
sq.squ1rr.mcc4.QuickGameMenu.java
sq.squ1rr.mcc4.StatsMenu.java
sq.squ1rr.mcc4.Stats.java
sq.squ1rr.mcc4.ai.Ai.java
sq.squ1rr.mcc4.ai.EasyAi.java
sq.squ1rr.mcc4.ai.HardAi.java
sq.squ1rr.mcc4.ai.NormalAi.java
sq.squ1rr.mcc4.ai.PeacefulAi.java
sq.squ1rr.mcc4.board.BoardDialogue.java
sq.squ1rr.mcc4.board.BoardLogic.java
sq.squ1rr.mcc4.board.BoardRenderer.java
sq.squ1rr.mcc4.board.BoardView.java
sq.squ1rr.mcc4.board.GameBoard.java
sq.squ1rr.mcc4.board.Texture.java
sq.squ1rr.mcc4.gl.Rectangle.java
sq.squ1rr.mcc4.gl.SpriteBatch.java
sq.squ1rr.mcc4.gl.SpriteString.java
sq.squ1rr.mcc4.gl.Sprite.java
sq.squ1rr.mcc4.layout.LayoutManager.java
sq.squ1rr.mcc4.layout.McButton.java
sq.squ1rr.mcc4.layout.McGroup.java
sq.squ1rr.mcc4.layout.McSelector.java
sq.squ1rr.mcc4.layout.McStyle.java
sq.squ1rr.mcc4.layout.McText.java
sq.squ1rr.mcc4.layout.McToggler.java
sq.squ1rr.mcc4.layout.McToken.java
sq.squ1rr.mcc4.rules.GameRules.java
sq.squ1rr.mcc4.rules.Player.java
sq.squ1rr.mcc4.rules.Rule.java
sq.squ1rr.mcc4.util.GlobalConstants.java