OpenGL ES 1.0で書かれたコードは、GL_LINE_STRIP
を使用して20ポイントで線を描いています。コードをOpenGL ES 2.0にアップグレードしたい。コードは3クラスにあります:
mainActivity
MyGLRenderer
形状OpenGL ES 1.0コードをAndroidでOpenGL Es 2.0に変換するにはどうすればいいですか?
どうすればよいですか?どのように設定fragShader
とvertShader
と他の? は、ここにコードがある
を助けてください:
mainActivity =
public class mainActivuty extends Activity {
private GLSurfaceView surface;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
surface = new GLSurfaceView(this);
surface.setEGLContextClientVersion(1);
surface.setRenderer(new MyGLRenderer());
setContentView(surface);
}
public void onPause(){
super.onPause();
surface.onPause();
}
public void onResume() {
super.onResume();
surface.onResume();
}
}
MyGLRenderer =
public class MyGLRenderer implements Renderer {
Shape s;
public MyGLRenderer() {
s = new Shape();
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glClearColor(0.0f, 0.0f, 0.5f, 0.5f);
}
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -8);
s.draw(gl);
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 45.0f, (float) width/(float) height, 0.1f,
100.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
}
@Override
public void onSurfaceCreated(GL10 arg0, javax.microedition.khronos.egl.EGLConfig arg1) {
// TODO Auto-generated method stub
}
}
と形状=
public class Shape {
float vertices[] = {
-3.14f, -0.00159265f, 0f,
-2.826f, -0.31038f, 0f,
-2.512f, -0.588816f, 0f,
-2.198f, -0.809672f, 0f,
-1.884f, -0.951351f, 0f,
-1.57f, -1f, 0f,
-1.256f, -0.950859f, 0f,
-0.942f, -0.808736f, 0f,
-0.628f, -0.587528f, 0f,
-0.314f, -0.308866f, 0f,
0f, 0f, 0f,
0.314f, 0.308866f, 0f,
0.628f, 0.587528f, 0f,
0.942f, 0.808736f, 0f,
1.256f, 0.950859f, 0f,
1.57f, 1f, 0f,
1.884f, 0.951351f, 0f,
2.198f, 0.809672f, 0f,
2.512f, 0.588816f, 0f,
2.826f, 0.31038f, 0f,
3.14f, 0.00159265f, 0f
};
private short[] indices = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
FloatBuffer vertexBuffer;
ShortBuffer indexBuffer;
public Shape() {
ByteBuffer bb = ByteBuffer.allocateDirect(vertices.length * 4);
bb.order(ByteOrder.nativeOrder());
vertexBuffer = bb.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
ByteBuffer bb2=ByteBuffer.allocateDirect(indices.length*2);
bb2.order(ByteOrder.nativeOrder());
indexBuffer=bb2.asShortBuffer();
indexBuffer.put(indices);
indexBuffer.position(0);
}
public void draw(GL10 gl) {
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawElements(GL10.GL_LINE_STRIP,indices.length,GL10.GL_UNSIGNED_SHORT,indexBuffer);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
}
Tahnks
私はOpenGL ES 2.0に移行する必要があります。どのようにしてもシェーダ・マトリックスと移動マトリックス・メソッドをシェーダで検索していましたが、描画ラインについてはアリを見つけることができませんでした。すべては、三角形を描くことでした。 Open GL ES 2.0で 'GL_LINE_STRIP'の例題についていくつか参考にしてください。ありがとうalot –
実際に図面は両方のバージョンで同じです。あなたは三角形の代わりに線の細い線を使用するか、あなたの例にあるものを使用します。 –