开发者

Works on emulator, not on phone

开发者 https://www.devze.com 2023-01-04 14:22 出处:网络
This code: public void onSurfaceChanged(GL10 gl, int w, int h) { gl.glViewport(0, 0, w, h);// gl.glMatrixMode(GL10.GL_PROJECTION);

This code:

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

gl.glViewport(0, 0, w, h);// 
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();    
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
// set camera zoom
GLU.gluPerspective(gl, 45.0f,(float) w / h, 0.1f, 100.0f);
// point camera
GLU.gluLookAt(gl, 0, 1, 5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
}
public void onDrawFrame(GL10 gl) {
// clear last frame
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// set model and projection matrices to identity
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
GLU.gluLookAt(gl, 0, 1, 5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);    
square.draw(gl);
}

works as expected on the emulator (on Android 2.1 virtual device) but on phone (HTC Desire Android 2.1) it just clears the screen, can't开发者_如何学编程 see anything drawn. If I comment out the

gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
GLU.gluLookAt(gl, 0, 1, 5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

it works on the phone, but not if I have the gluLookAt call in onDrawFrame.

What's the problem with gluLookAt in onDrawFrame?


You shouldn't need to call

gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();

every frame. If you're using GLU.gluLookAt() it should handle all of that. Granted, clearing the projection matrix shouldn't cause any problems, but maybe there is some sort of optimization going on that causes it to break. What happens if you comment out those two lines?

0

精彩评论

暂无评论...
验证码 换一张
取 消