我有一个GLSurfaceView类,必须显示带纹理的正方形。我正在尝试使用纹理/多边形尺寸来适应屏幕,然后我需要使用投影。
我使用3个类与android 1.5兼容:
MatrixGrabber.java MatrixStack.java MatrixTrackingGL.java
这是它给出错误的代码的一部分:
private MatrixGrabber mg = new MatrixGrabber(); //create the matrix grabber object in your initialization code
.
.
.
DisplayMetrics dm = new DisplayMetrics();
((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(dm);
screenW=dm.widthPixels;
screenH=dm.heightPixels;
modelMatrix=mg.mModelView;
projMatrix=mg.mProjection;
mView[0] = 0;
mView[1] = 0;
mView[2] = screenW; //width
mView[3] = screenH; //height
.
.
.
public void onDrawFrame(GL10 gl) {
//Clear Screen And Depth Buffer
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity(); //Reset The Current Modelview Matrix
mg.getCurrentProjection(gl);
mg.getCurrentModelView(gl);
.
.
.
这就是错误:
02-17 09:13:59.952: WARN/dalvikvm(11405): threadid=8: thread exiting with uncaught exception (group=0x4001d7e0)
02-17 09:13:59.960: ERROR/AndroidRuntime(11405): FATAL EXCEPTION: GLThread 9
02-17 09:13:59.960: ERROR/AndroidRuntime(11405): java.lang.ClassCastException: com.google.android.gles_jni.GLImpl
02-17 09:13:59.960: ERROR/AndroidRuntime(11405): at com.DemoMagazine.MatrixGrabber.getMatrix(MatrixGrabber.java:56)
02-17 09:13:59.960: ERROR/AndroidRuntime(11405): at com.DemoMagazine.MatrixGrabber.getCurrentProjection(MatrixGrabber.java:52)
02-17 09:13:59.960: ERROR/AndroidRuntime(11405): at com.DemoMagazine.SquareGLSurfaceView.onDrawFrame(SquareGLSurfaceView.java:112)
02-17 09:13:59.960: ERROR/AndroidRuntime(11405): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
02-17 09:13:59.960: ERROR/AndroidRuntime(11405): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
答案 0 :(得分:0)
我在尝试获取矩阵时遇到了一些问题,但是它们似乎是固定的,将矩阵模式设置为我将获得的矩阵,在您的情况下:
public void onDrawFrame(GL10 gl) {
//Clear Screen And Depth Buffer
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity(); //Reset The Current Modelview Matrix
mg.getCurrentModelView(gl);
gl.glMatrixMode(GL10.GL_PROJECTION);
mg.getCurrentProjection(gl);
并记住你现在处于投影模式,如果你需要,你可以回到模型视图。这对我有用。
问候!