長方形を描画するメソッドを追加。
GraphicUtilsクラスに次のメソッドを追加。
/** * 長方形を描写 */ public static void drawRectangle(GL10 gl,float x, float y, float width, float height, int red, int green, int blue, int alpha ){ final float [] squares = new float[]{ -0.5f * width + x, -0.5f * height + y, 0.0f, 0.5f * width + x, -0.5f * height + y, 0.0f, -0.5f * width + x, 0.5f * height + y, 0.0f, 0.5f * width + x, 0.5f * height + y, 0.0f, }; drawSquare(gl,squares,red, green, blue,alpha); }
レンダークラスで使う。
public class GLRenderer implements GLSurfaceView.Renderer { @Override public void onDrawFrame(GL10 gl) { GraphicUtils.makeWorld(gl); int one = 0x10000; int half = 0x08000; GraphicUtils.drawSquare(gl, 0.5f, 0.0f, one, one, 0, one ); GraphicUtils.drawRectangle(gl, 0.0f, 0.0f, 1.0f, 1.0f, one, half, 0, one ); GraphicUtils.drawRectangle(gl, -0.8f, 0.0f, 0.2f, 2.0f, one, half, 0, one ); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { } }