texture.java

来自「一个java 3D程序的源代码」· Java 代码 · 共 61 行

JAVA
61
字号
import java.awt.image.PixelGrabber;
import java.awt.*;


//only represents power of 2 textures
public class texture{
	public Image img;

	public int[] Texture;

	public int height;

	public int width;

	public int heightMask;

	public int widthMask;

	public int widthBits;

	public int heightBits;

	public PixelGrabber pg;



	public texture(Image img, int widthBits , int heightBits){
		this.img = img;

		this.widthBits = widthBits;
		this.heightBits = heightBits;

		height = (int)Math.pow(2, heightBits);
		width = (int)Math.pow(2, widthBits);

		Texture = new int[width*height];

		heightMask = height -1;
		widthMask = width - 1;

		PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, Texture, 0, width);
		try {
			pg.grabPixels();
		}catch(Exception e){}
	}

	public texture(int[] Texture, int widthBits , int heightBits){
		this.Texture = Texture;

		this.widthBits = widthBits;
		this.heightBits = heightBits;

		height = (int)Math.pow(2, heightBits);
		width = (int)Math.pow(2, widthBits);

		heightMask = height -1;
		widthMask = width - 1;

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?