android模拟器 opengl,Android模拟器与手机opengl不一致

public abstract class AbstractRenderer implements Renderer {

float x = 0.5f;

float y = 1f;

float z = 3;

boolean displayCoordinateSystem = true;

public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) {

gl.glDisable(GL10.GL_DITHER);

gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);

gl.glClearColor(.5f, .5f, .5f, 1);

gl.glShadeModel(GL10.GL_SMOOTH);

gl.glEnable(GL10.GL_DEPTH_TEST);

}

public void onSurfaceChanged(GL10 gl, int w, int h) {

gl.glViewport(0, 0, w, h);

float ratio = (float) w / h;

gl.glMatrixMode(GL10.GL_PROJECTION);

gl.glLoadIdentity();

gl.glFrustumf(-ratio, ratio, -1, 1, 0, 10);

}

public void onDrawFrame(GL10 gl) {

gl.glDisable(GL10.GL_DITHER);

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

gl.glMatrixMode(GL10.GL_MODELVIEW);

gl.glLoadIdentity();

GLU.gluLookAt(gl, x, y, z, 0f, 0, 0f, 0f, 1f, 0f);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

if(displayCoordinateSystem) {

drawCoordinateSystem(gl);

}

draw(gl);

// gl.glFlush();

}

private void drawCoordinateSystem(GL10 gl) {

ByteBuffer vbb = ByteBuffer.allocateDirect(6*3*4);

vbb.order(ByteOrder.nativeOrder());

FloatBuffer vertices = vbb.asFloatBuffer();

ByteBuffer ibb = ByteBuffer.allocateDirect(6*2);

ibb.order(ByteOrder.nativeOrder());

ShortBuffer indexes = ibb.asShortBuffer();

final float coordLength = 27f;

//add point (-1, 0, 0)

vertices.put(-coordLength);

vertices.put(0);

vertices.put(0);

//add point (1, 0, 0)

vertices.put(coordLength);

vertices.put(0);

vertices.put(0);

//add point (0, -1, 0)

vertices.put(0);

vertices.put(-coordLength);

vertices.put(0);

//add point (0, 1, 0)

vertices.put(0);

vertices.put(coordLength);

vertices.put(0);

//add point (0, 0, -1)

vertices.put(0);

vertices.put(0);

vertices.put(-coordLength);

//add point (0, 0, 1)

vertices.put(0);

vertices.put(0);

vertices.put(coordLength);

for(int i = 0; i < 6; i++) {

indexes.put((short)i);

}

vertices.position(0);

indexes.position(0);

gl.glColor4f(1, 1, 0, 0.5f);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);

gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, indexes);

indexes.position(2);

gl.glColor4f(0, 1, 0, 0.5f);

gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, indexes);

indexes.position(4);

gl.glColor4f(0, 0, 1, 0.5f);

gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, indexes);

}

protected abstract void draw(GL10 gl);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值