MatrixGrabber 的问题:java.lang.ClassCastException:com.google.android.gles_jni.GLImpl

发布于 2025-01-07 06:20:58 字数 2042 浏览 2 评论 0原文

我有一个 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)

i have a GLSurfaceView class that must show a square with a texture. I'm trying to fit the screen with the texture/polygon dimensions, then i need to use projections.

I'm using 3 classes to have compatibility with android 1.5:

MatrixGrabber.java
MatrixStack.java
MatrixTrackingGL.java

This is the part of the code that it is giving the error:

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); 
.
.
.

And this is the error:

    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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以畏孤独 2025-01-14 06:20:58

我在尝试获取矩阵时也遇到了一些问题,但在您的情况下,它们似乎已修复,将矩阵模式设置为我将要获得的模式:

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);

并记住您现在处于投影模式,如果需要,您可以去返回模型视图。这对我有用。

问候!

I had some problems as well trying to get the matrix, but they seem to be fixed setting the matrixmode to the one i am going to get, in your case:

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);

and remember you are now in projection mode, if you need so you can go back to modelview. This worked for me.

Regards!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文