Code example for GL10

Methods: glBindTexture, glColor4f, glDisable, glDisableClientState, glDrawArrays, glEnable, glEnableClientState, glLineWidth, glPopMatrix, glPushMatrix

0
	abstract public boolean IsScalable(); 
	abstract public boolean IsRotatable(); 
	 
	//공통적으로 사용될 수 있는 그리기 함수 
	public void Draw(GL10 gl) {
		gl.glPushMatrix();
		if(bitmap_ != null) {
			BindTexture(gl);
			gl.glEnable(GL10.GL_TEXTURE_2D);
			gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, texPtr_[0]);
			gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, GLESHelper.UVArrayToBuffer(uvs_.toArray(new float[][]{})));
		} 
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		gl.glLineWidth(stroke_);
		gl.glColor4f(color_[1], color_[2], color_[3], color_[0]);
		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, GLESHelper.ArrayToBuffer(vertices_.toArray(new float[][]{})));
		gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, vertices_.size());
		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
		if(bitmap_ != null) {
			gl.glDisable(GL10.GL_TEXTURE_2D);
			gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
		} 
		gl.glPopMatrix();
	} 
	 
	//변환은 MathHelper 클래스 참조. 
	public void FreeTransform(int index, float x, float y) {
		vertices_.get(index)[0] = x;
		vertices_.get(index)[1] = y;
	} 
	 
	public void Translate(float dx, float dy) {
		MathHelper.TranslateVertices(vertices_, dx, dy);
	} 
	 
	public void Rotate(float radian, float originX, float originY) {
		MathHelper.RotateVertices(vertices_, radian, originX, originY);
	} 
	 
	public void Scale(float scaleX, float scaleY, float originX, float originY) {
		MathHelper.ScaleVertices(vertices_, scaleX, scaleY, originX, originY);
	} 
	 
	//도형이 선택되었는가를 판단하는 함수. 기본적으로는 다각형이라고 가정하고 점이 내부에 포함되는지 검사. 
	public boolean IsSelected(float x, float y) {
		boolean including = false;
		float xi, yi, xj, yj;
		for(int i=0, j = vertices_.size()-1; i<vertices_.size(); j = i++) {
			xi = vertices_.get(i)[0];
			yi = vertices_.get(i)[1];
			xj = vertices_.get(j)[0];
			yj = vertices_.get(j)[1];
			if(((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi)) {
				including = !including;
			} 
		} 
		return including;
	} 
	 
	public ArrayList<float[]> GetVertices() {
		return vertices_;
	} 
	 
	public void SetColor(float[] color) {
		color_ = color;
	} 
	 
	public float[] GetColor() { 
		return color_;
	} 
	 
	public void SetStroke(float stroke) {
		stroke_ = stroke;
	} 
	 
	public float GetStroke() { 
		return stroke_;
	} 
	 
	//비트맵을 받아서 텍스쳐를 설정함. 
	//도형의 경계가 되는 사각형을 구해서 그 사각형에 텍스쳐를 입히듯이 uv 좌표를 계산한다. 
	public void SetTexture(Bitmap bitmap) {
		Rect r = GetRect();
		int width = r.right - r.left;
		int height = r.bottom - r.top;
		for(int i=0; i<vertices_.size(); ++i) {
			uvs_.add(new float[]{
				(vertices_.get(i)[0] - r.left)/width,
				(vertices_.get(i)[1] - r.top)/height
			}); 
		} 
		bitmap_ = bitmap.copy(Config.ARGB_8888, true);
	    texBinded_ = true;
	} 
	 
	//설정된 텍스쳐를 바인딩함. 
	public void BindTexture(GL10 gl) {
		if(texBinded_ == true) {
			gl.glGenTextures(1, texPtr_, 0);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, texPtr_[0]);
			gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
			gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
			gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
			gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
			GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap_, 0);