• R/O
  • HTTP
  • SSH
  • HTTPS

nyartoolkit-and: Commit

NyARToolkit for Android v2.x, 3.x mainline.

master: NyARToolkit core.
android-1.6: for Android 1.6. obsolete version.
android-2.2: for Android 2.2. current version.


Commit MetaInfo

Revision1b44d6ca5509816b93c78e828756bc62e9980092 (tree)
Time2012-05-26 01:00:18
Authornyatla <nyatla@user...>
Commiternyatla

Log Message

backup

Change Summary

Incremental Difference

--- a/NyARToolKit for Android -Utils/src/jp/androidgroup/nyartoolkit/utils/CameraCapture.java
+++ /dev/null
@@ -1,5 +0,0 @@
1-package jp.androidgroup.nyartoolkit.utils;
2-
3-public class CameraCapture {
4-
5-}
--- /dev/null
+++ b/NyARToolKit for Android -Utils/src/jp/androidgroup/nyartoolkit/utils/gl/AndGLBasicSprite.java
@@ -0,0 +1,221 @@
1+package jp.androidgroup.nyartoolkit.utils.gl;
2+
3+import java.nio.FloatBuffer;
4+
5+import javax.microedition.khronos.opengles.GL10;
6+
7+import jp.androidgroup.nyartoolkit.sketch.AndSketch;
8+import android.graphics.Bitmap;
9+import android.graphics.Canvas;
10+import android.opengl.GLU;
11+import android.opengl.GLUtils;
12+
13+
14+/**
15+ * スプライトテクスチャ。
16+ * http://pr0jectze10.blogspot.jp/2011/02/androidopengl.html
17+ * を参考にしました。
18+ */
19+public class AndGLBasicSprite implements AndGLView.IGLViewEventListener
20+{
21+
22+ private int[] _gl_state_holder=new int[10];
23+
24+ public int index; // イメージバインドID
25+ protected Bitmap _image; // ビットマップイメージ
26+ protected Canvas _canvas;
27+ private GL10 _ref_gl;
28+ private boolean _is_attache;
29+ protected AndSketch _context;
30+
31+ /**
32+ * コンストラクタ
33+ */
34+ protected AndGLBasicSprite(AndGLView i_view)
35+ {
36+ i_view._evl.add(this);
37+ //bitmapの生成
38+ this._image =null;
39+ this._is_attache=false;
40+
41+ }
42+ /**
43+ * ビットマップをセットします。
44+ * @param i_bitmap
45+ * @param i_is_attache
46+ */
47+ protected void setBitmap(Bitmap i_bitmap,boolean i_is_attache)
48+ {
49+ this._image=i_bitmap;
50+ this._is_attache=i_is_attache;
51+ this._canvas=new Canvas(this._image);
52+ }
53+ /**
54+ * ビットマップをリサイズします。
55+ * この関数を実行するには、ビットマップを所有している必要があります。
56+ * @param i_w
57+ * @param i_h
58+ * @throws Exception
59+ */
60+ protected void resize(int i_w,int i_h) throws Exception
61+ {
62+ if(!this._is_attache){
63+ throw new Exception("can not resize no attached bitmap");
64+ }
65+ this._image.recycle();
66+ this._image=Bitmap.createBitmap(i_w, i_h, Bitmap.Config.ARGB_8888);
67+ this._canvas=new Canvas(this._image);
68+ }
69+
70+ private int _screen_height;
71+ private int _screen_width;
72+
73+ protected void sync()
74+ {
75+ GL10 gl=this._ref_gl;
76+ //GLが未初期化なら何もしない
77+ if(gl==null){
78+ return;
79+ }
80+ // ビットマップイメージの設定
81+ gl.glActiveTexture(AndGLHelper.TEXTURE_CHANNEL);
82+ gl.glBindTexture(GL10.GL_TEXTURE_2D,this.index);
83+ GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0,this._image, 0);
84+ }
85+ private FloatBuffer _draw_tmp = AndGLHelper.makeFloatBuffer(3*4); //Vertex
86+ private FloatBuffer _uv_tmp = AndGLHelper.makeFloatBuffer(2*4);// UVバッファ
87+
88+
89+ /**
90+ * This function changes the matrix mode to MODEL_VIEW , and changes some parameter.
91+ * @param i_x
92+ * @param i_y
93+ * @param i_w
94+ * @param i_h
95+ * @param i_sx
96+ * @param i_sy
97+ */
98+ protected void draw(int i_x, int i_y,int i_w,int i_h,int i_sx,int i_sy)
99+ {
100+ assert this._image!=null;
101+ int[] st=this._gl_state_holder;
102+ GL10 gl=this._ref_gl;
103+// { //<SaveGLstatus>
104+// gl.glGetIntegerv(GL10.GL_NORMALIZE,st,1);
105+// gl.glGetIntegerv(GL10.GL_LIGHTING,st,2);
106+// gl.glGetIntegerv(GL10.GL_VERTEX_ARRAY,st,3);
107+// gl.glGetIntegerv(GL10.GL_TEXTURE_COORD_ARRAY,st,4);
108+// gl.glGetIntegerv(GL10.GL_COLOR_ARRAY,st,5);
109+// //gl.glGetIntegerv(GL10.GL_MATRIX_MODE,st,5); //なんでないんだよ!
110+// }
111+ //set GL state
112+ gl.glActiveTexture(AndGLHelper.TEXTURE_CHANNEL);
113+ gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,GL10.GL_REPEAT);
114+ gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,GL10.GL_REPEAT);
115+ gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR);
116+ gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_LINEAR);
117+ // ポリゴン色とテクスチャ色の合成方法
118+ gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,GL10.GL_MODULATE);
119+
120+ gl.glEnable(GL10.GL_TEXTURE_2D);
121+ gl.glDisable(GL10.GL_NORMALIZE);
122+ gl.glDisable(GL10.GL_LIGHTING);
123+ gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
124+ gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
125+ gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
126+ gl.glBindTexture(GL10.GL_TEXTURE_2D,this.index);
127+
128+
129+ //平行投影へ。
130+ gl.glMatrixMode(GL10.GL_PROJECTION);
131+ gl.glPushMatrix();
132+ gl.glLoadIdentity();
133+ GLU.gluOrtho2D(gl,0,this._screen_width,0,this._screen_height);//平行投影
134+ gl.glMatrixMode(GL10.GL_MODELVIEW);
135+ gl.glPushMatrix();
136+ gl.glLoadIdentity();
137+
138+ // 描画
139+ gl.glVertexPointer(3, GL10.GL_FLOAT, 0,getVertices(i_x,i_y,i_w,i_h,this._draw_tmp));
140+
141+ // UV座標
142+ gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, getUv(0,0,i_w,i_h,this._uv_tmp));
143+ gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
144+
145+ gl.glPopMatrix();
146+ gl.glMatrixMode(GL10.GL_PROJECTION);
147+ gl.glPopMatrix();
148+
149+
150+// { //Restore
151+// if(st[1]!=0){gl.glEnable(GL10.GL_NORMALIZE);}
152+// if(st[2]!=0){gl.glEnable(GL10.GL_LIGHTING);}
153+// if(st[3]==0){gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);}
154+// if(st[4]==0){gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);}
155+// if(st[5]!=0){gl.glEnableClientState(GL10.GL_COLOR_ARRAY);}
156+// }
157+
158+ }
159+ private FloatBuffer getUv(int x, int y, int width,int height,FloatBuffer i_buf)
160+ {
161+ int bw=this._image.getWidth();
162+ int bh=this._image.getHeight();
163+ float l=((float)x)/((float)bw);
164+ float t=((float)y)/((float)bh);
165+ float r=((float)(width+x))/((float)bw);
166+ float b=((float)(height+y))/((float)bh);
167+ float[] vertices = {
168+ l,b,
169+ r,b,
170+ l,t,
171+ r,t};
172+ i_buf.put(vertices);
173+ i_buf.position(0);
174+ return i_buf;
175+ }
176+ private static FloatBuffer getVertices(int x, int y, int width,int height,FloatBuffer i_buf)
177+ {
178+ // 頂点バッファ
179+ float[] vertices = {
180+ x, y, 0,
181+ x + width, y, 0,
182+ x, y + height, 0,
183+ x + width, y + height, 0};
184+ i_buf.position(0);
185+ i_buf.put(vertices);
186+ i_buf.position(0);
187+ return i_buf;
188+ }
189+
190+ @Override
191+ public void onGlChanged(GL10 i_gl, int i_width, int i_height)
192+ {
193+ if(this._ref_gl!=null){
194+ int[] textures = {this.index};
195+ this._ref_gl.glDeleteTextures(1, textures, 0);
196+ }
197+ this._ref_gl=i_gl;
198+ this._screen_height=i_height;
199+ this._screen_width=i_width;
200+
201+ // テクスチャIDの設定
202+ int[] ids={-1};
203+ i_gl.glGenTextures(1, ids, 0);
204+ this.index=ids[0];
205+
206+ //bitmap画あるときはここでsync
207+ if(this._image!=null){
208+ this.sync();
209+ }
210+ }
211+ @Override
212+ public void onGlMayBeStop() {
213+ int[] textures = {this.index};
214+ this._ref_gl.glDeleteTextures(1, textures, 0);
215+ this._image = null;
216+ this._image.recycle();
217+ this._ref_gl=null;
218+
219+ }
220+}
221+
--- /dev/null
+++ b/NyARToolKit for Android -Utils/src/jp/androidgroup/nyartoolkit/utils/gl/AndGLBitmapSprite.java
@@ -0,0 +1,41 @@
1+package jp.androidgroup.nyartoolkit.utils.gl;
2+
3+import android.graphics.Bitmap;
4+
5+public class AndGLBitmapSprite extends AndGLBasicSprite
6+{
7+ private int _internal_w;
8+ private int _internal_h;
9+ public AndGLBitmapSprite(AndGLView i_view,int i_w,int i_h)
10+ {
11+ super(i_view);
12+ //2^nサイズを求める。
13+ int s=AndGLHelper.getPow2Size(i_w, i_h);
14+ this.setBitmap(Bitmap.createBitmap(s,s, Bitmap.Config.ARGB_8888),true);
15+ this._internal_w=i_w;
16+ this._internal_h=i_h;
17+ }
18+ private boolean _locked=false;
19+ public Bitmap lockBitmap()
20+ {
21+ assert this._locked==false;
22+ this._locked=true;
23+ return this._image;
24+ }
25+ public void unlockBitmap()
26+ {
27+ assert this._locked==true;
28+ this._locked=false;
29+ this.sync();
30+ }
31+
32+ public void draw(int i_dx,int i_dy,int i_w,int i_h,int i_sx,int i_sy)
33+ {
34+ super.draw(i_dx, i_dy, i_w, i_h, i_sx, i_sy);
35+ }
36+ public void draw(int i_dx,int i_dy)
37+ {
38+ super.draw(i_dx, i_dy,this._internal_w, this._internal_h,0,0);
39+ }
40+}
41+
--- /dev/null
+++ b/NyARToolKit for Android -Utils/src/jp/androidgroup/nyartoolkit/utils/gl/AndGLBox.java
@@ -0,0 +1,124 @@
1+package jp.androidgroup.nyartoolkit.utils.gl;
2+
3+import java.nio.ByteBuffer;
4+import java.nio.FloatBuffer;
5+
6+import javax.microedition.khronos.opengles.GL10;
7+
8+
9+
10+public class AndGLBox implements AndGLView.IGLViewEventListener
11+{
12+ private GL10 _ref_gl;
13+
14+ private FloatBuffer _vertex;
15+ private FloatBuffer _color;
16+ private ByteBuffer _index;
17+ public AndGLBox(AndGLView i_context,float i_size)
18+ {
19+ i_context._evl.add(this);
20+ float s=i_size/2;
21+ float[] square = {
22+ -s, -s, -s, // 0(bottom)
23+ s, -s, -s, //
24+ s, s, -s, //
25+ -s, s, -s, // 3
26+ -s, -s, s, // 4(top)
27+ s, -s, s, //
28+ s, s, s, //
29+ -s, s, s};
30+ this._vertex=AndGLHelper.makeFloatBuffer(square);
31+ float[] colors = {
32+ 0.0f, 0.0f, 0.0f, 1.0f,
33+ 1.0f, 0.0f, 0.0f, 1.0f,
34+ 1.0f, 1.0f, 0.0f, 1.0f,
35+ 0.0f, 1.0f, 0.0f, 1.0f,
36+ 0.0f, 0.0f, 1.0f, 1.0f,
37+ 1.0f, 0.0f, 1.0f, 1.0f,
38+ 1.0f, 1.0f, 1.0f, 1.0f,
39+ 0.0f, 1.0f, 1.0f, 1.0f
40+ };
41+ this._color=AndGLHelper.makeFloatBuffer(colors);
42+ // 面設定
43+ byte[] indices = {
44+ 0, 4, 5, 0, 5, 1,
45+ 1, 5, 6, 1, 6, 2,
46+ 2, 6, 7, 2, 7, 3,
47+ 3, 7, 4, 3, 4, 0,
48+ 4, 7, 6, 4, 6, 5,
49+ 3, 0, 1, 3, 1, 2};
50+ this._index=AndGLHelper.makeByteBuffer(indices);
51+ }
52+ /**
53+ * This function changes the matrix mode to MODEL_VIEW , and change some parameter.
54+ * @param i_x
55+ * @param i_y
56+ * @param i_z
57+ */
58+ public void draw(float i_x,float i_y,float i_z)
59+ {
60+ GL10 gl=this._ref_gl;
61+ gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
62+ gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
63+ gl.glDisable(GL10.GL_TEXTURE_2D);
64+ gl.glDisable(GL10.GL_NORMALIZE);
65+ gl.glDisable(GL10.GL_LIGHTING);
66+
67+ gl.glColorPointer( 4, GL10.GL_FLOAT, 0,this._color);
68+ gl.glVertexPointer( 3, GL10.GL_FLOAT, 0,this._vertex);
69+
70+ gl.glMatrixMode(GL10.GL_MODELVIEW);
71+ gl.glPushMatrix();
72+ gl.glTranslatef(i_x,i_y,i_z);
73+ gl.glPushMatrix();
74+ gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE,this._index);
75+ gl.glPopMatrix();
76+// gl.glEnable(GL10.GL_TEXTURE_2D);
77+// gl.glEnable(GL10.GL_NORMALIZE);
78+// gl.glEnable(GL10.GL_LIGHTING);
79+// gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
80+// gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
81+ }
82+ @Override
83+ public void onGlChanged(GL10 i_gl, int i_width, int i_height)
84+ {
85+ if(this._ref_gl!=null){
86+ }
87+ this._ref_gl=i_gl;
88+ }
89+ @Override
90+ public void onGlMayBeStop()
91+ {
92+ this._ref_gl=null;
93+ }
94+}
95+
96+/* (non-Javadoc)
97+ * @see jp.nyatla.nyartoolkit.android.renderer.DefaultRenderer#draw(javax.microedition.khronos.opengles.GL10)
98+ *//*
99+@Override
100+public void draw(GL10 gl)
101+{
102+ Log.d(TAG, "draw");
103+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
104+
105+ gl.glMatrixMode(GL10.GL_PROJECTION);
106+// gl.glLoadIdentity();
107+ gl.glLoadMatrixf(NyARToolKitWrapper.getInstance().getGlProjectionMatrix(), 0);
108+
109+// gl.glEnable(GL10.GL_CULL_FACE);
110+// gl.glShadeModel(GL10.GL_SMOOTH);
111+// gl.glEnable(GL10.GL_DEPTH_TEST);
112+// gl.glFrontFace(GL10.GL_CW);
113+
114+ if (NyARToolKitWrapper.getInstance().queryMarkerVisible()) {
115+ Log.d(TAG, "draw visible");
116+ gl.glMatrixMode(GL10.GL_MODELVIEW);
117+ gl.glLoadIdentity();
118+ gl.glLoadMatrixf(NyARToolKitWrapper.getInstance().queryMarkerTransformation(), 0);
119+
120+ Log.d(TAG, "draw model");
121+ _drawModel(gl);
122+ }
123+}
124+*/
\ No newline at end of file
--- /dev/null
+++ b/NyARToolKit for Android -Utils/src/jp/androidgroup/nyartoolkit/utils/gl/AndGLHelper.java
@@ -0,0 +1,46 @@
1+package jp.androidgroup.nyartoolkit.utils.gl;
2+import java.nio.ByteBuffer;
3+import java.nio.ByteOrder;
4+import java.nio.FloatBuffer;
5+
6+import javax.microedition.khronos.opengles.GL10;
7+
8+public class AndGLHelper
9+{
10+ public static final int TEXTURE_CHANNEL=GL10.GL_TEXTURE0;
11+
12+ public static FloatBuffer makeFloatBuffer(int i_len)
13+ {
14+ ByteBuffer bb = ByteBuffer.allocateDirect(i_len*4);
15+ bb.order(ByteOrder.nativeOrder());
16+ FloatBuffer fb = bb.asFloatBuffer();
17+ fb.position(0);
18+ return fb;
19+ }
20+ public static FloatBuffer makeFloatBuffer(float[] i_arr)
21+ {
22+ ByteBuffer bb = ByteBuffer.allocateDirect(i_arr.length*4);
23+ bb.order(ByteOrder.nativeOrder());
24+ FloatBuffer fb = bb.asFloatBuffer();
25+ fb.put(i_arr);
26+ fb.position(0);
27+ return fb;
28+ }
29+ public static ByteBuffer makeByteBuffer(byte[] i_arr)
30+ {
31+ ByteBuffer bb = ByteBuffer.allocateDirect(i_arr.length);
32+ bb.put(i_arr);
33+ bb.position(0);
34+ return bb;
35+ }
36+ public static int getPow2Size(int i_w,int i_h)
37+ {
38+ int c=i_w>i_h?i_w:i_h;
39+ int s=0x1;
40+ while(s<c){
41+ s=s<<1;
42+ }
43+ return s;
44+ }
45+}
46+
--- /dev/null
+++ b/NyARToolKit for Android -Utils/src/jp/androidgroup/nyartoolkit/utils/gl/AndGLTextLabel.java
@@ -0,0 +1,69 @@
1+package jp.androidgroup.nyartoolkit.utils.gl;
2+
3+import android.graphics.Bitmap;
4+import android.graphics.Color;
5+import android.graphics.Paint;
6+import android.graphics.Paint.Style;
7+import android.graphics.Typeface;
8+
9+public class AndGLTextLabel extends AndGLBasicSprite
10+{
11+ protected final Paint fgpaint= new Paint();
12+ protected final Paint bgpaint= new Paint();
13+ public AndGLTextLabel(AndGLView i_context)
14+ {
15+ super(i_context);
16+ //2^nサイズを求める。
17+ this.setBitmap(Bitmap.createBitmap(32,32, Bitmap.Config.ARGB_8888),true);
18+ this.fgpaint.setColor(Color.WHITE);
19+ this.fgpaint.setTypeface(Typeface.DEFAULT);
20+ this.fgpaint.setTextSize(16.0f);
21+ this.fgpaint.setAntiAlias(true);
22+ this.bgpaint.setColor(Color.BLACK);
23+ this.bgpaint.setStyle(Style.FILL);
24+
25+ }
26+ private int _last_str_w=1;
27+ private int _last_str_h=1;
28+ private String _last_str="";
29+ public void draw(double i_s,int i_dx,int i_dy)
30+ {
31+ this.draw(String.valueOf(i_s),i_dx,i_dy);
32+ }
33+ public void draw(long i_s,int i_dx,int i_dy)
34+ {
35+ this.draw(String.valueOf(i_s),i_dx,i_dy);
36+ }
37+ public void draw(String i_s,int i_dx,int i_dy)
38+ {
39+ Paint.FontMetrics fontMetrics = this.fgpaint.getFontMetrics();
40+ //文字列の内容が異なっていたら、テクスチャ/BMPの再構築
41+ int lw=this._last_str_w;
42+ int lh=this._last_str_h;
43+// if(i_s.compareTo(this._last_str)!=0){
44+ //bitmapの再構築を試行
45+ int w=(int)Math.ceil(this.fgpaint.measureText(i_s));
46+ int h=(int)Math.ceil(Math.abs(fontMetrics.ascent) +Math.abs(fontMetrics.descent) + Math.abs(fontMetrics.leading));
47+ //ビットマップのサイズをチェックしてリサイズ
48+ int s=AndGLHelper.getPow2Size(w,h);
49+ if(s> this._image.getWidth()|| s>this._image.getHeight()){
50+ try {
51+ this.resize(s,s);
52+ } catch (Exception e) {
53+ // TODO Auto-generated catch block
54+ e.printStackTrace();
55+ this._context._finish(e);
56+ }
57+ lw=lh=s;
58+ }
59+ this._last_str=i_s;
60+// }
61+ //埋め戻し
62+ this._canvas.drawRect(0, 0,lw,lh,this.bgpaint);
63+ this._canvas.drawText(i_s,0, Math.abs(fontMetrics.ascent),this.fgpaint);
64+ this.sync();
65+ super.draw(i_dx, i_dy,w,h, 0,0);
66+ this._last_str_w=w;
67+ this._last_str_h=h;
68+ }
69+}
--- /dev/null
+++ b/NyARToolKit for Android -Utils/src/jp/androidgroup/nyartoolkit/utils/gl/AndGLView.java
@@ -0,0 +1,120 @@
1+package jp.androidgroup.nyartoolkit.utils.gl;
2+
3+import java.util.ArrayList;
4+
5+import javax.microedition.khronos.egl.EGLConfig;
6+import javax.microedition.khronos.opengles.GL10;
7+
8+import jp.androidgroup.nyartoolkit.sketch.AndSketch;
9+
10+import android.graphics.PixelFormat;
11+import android.opengl.GLSurfaceView;
12+
13+public class AndGLView extends GLSurfaceView implements AndSketch.IAndSketchEventListerner
14+{
15+ public interface IGLFunctionEvent
16+ {
17+ public void setupGL(GL10 i_gl);
18+ public void drawGL(GL10 i_gl);
19+ }
20+ public interface IGLViewEventListener{
21+ public void onGlChanged(GL10 i_gl,int i_width,int i_height);
22+ public void onGlMayBeStop();
23+
24+ }
25+ public ArrayList<IGLViewEventListener> _evl=new ArrayList<IGLViewEventListener>();
26+
27+ public AndGLView(AndSketch i_context)
28+ {
29+ super(i_context);
30+ i_context._evlistener.add(this);
31+ this.setEGLConfigChooser( 8, 8, 8, 8, 16, 0);
32+ this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
33+ this.setRenderer(new GLRenderer(i_context,this));
34+
35+ }
36+
37+ @Override
38+ public void onAcResume()
39+ {
40+ super.onResume();
41+ }
42+ @Override
43+ public void onAcPause()
44+ {
45+ super.onPause();
46+ }
47+
48+ @Override
49+ public void onAcDestroy() throws Exception
50+ {
51+ }
52+
53+ @Override
54+ public void onAcStop() throws Exception
55+ {
56+ for(AndGLView.IGLViewEventListener i : this._evl) {
57+ i.onGlMayBeStop();
58+ }
59+ }
60+
61+
62+
63+}
64+
65+
66+
67+class GLRenderer implements GLSurfaceView.Renderer
68+{
69+ private AndGLView _view;
70+ private AndSketch _context;
71+ private AndGLView.IGLFunctionEvent _function_if;
72+ public final static int AST_NULL=0;
73+ public final static int AST_SETUP=1;
74+ public final static int AST_RUN =2;
75+ private int _ast=AST_NULL;
76+ /**
77+ * i_contextが{@link AndGLView.IGLFunctionEvent}を持つ場合
78+ * @param i_context
79+ * @param i_view
80+ */
81+ public GLRenderer(AndSketch i_context,AndGLView i_view)
82+ {
83+ this._view=i_view;
84+ this._context=i_context;
85+ if(!(i_context instanceof AndGLView.IGLFunctionEvent)){
86+ i_context._finish(new Exception());
87+ }
88+ this._function_if=(AndGLView.IGLFunctionEvent)i_context;
89+ }
90+ /**
91+ * Logging Tag
92+ */
93+ @Override
94+ public void onSurfaceCreated(GL10 gl, EGLConfig config)
95+ {
96+ // Transparent background
97+ gl.glClearColor(0.5f, 0.0f, 0.0f, 0.f);
98+ gl.glEnable(GL10.GL_DEPTH_TEST);
99+ this._ast=AST_SETUP;
100+ this._function_if.setupGL(gl);
101+ this._ast=AST_RUN;
102+
103+ }
104+ @Override
105+ public void onSurfaceChanged(GL10 gl, int width, int height)
106+ {
107+ //Surfaceの再構築で、Sketchの所有しているGLサーフェイスの
108+ for(AndGLView.IGLViewEventListener i : this._view._evl) {
109+ i.onGlChanged(gl,width,height);
110+ }
111+ gl.glViewport(0, 0, width, height);
112+ }
113+ @Override
114+ public void onDrawFrame(GL10 gl)
115+ {
116+ if(this._ast==AST_RUN){
117+ this._function_if.drawGL(gl);
118+ }
119+ }
120+}
\ No newline at end of file
Show on old repository browser