本文介绍了GL11(Android)中的getFloatv函数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 Open GL ES,并希望获得比 g​​oogle 在 TouchRotateActivity 示例.为了做到这一点,我想将我的 Modelview 矩阵乘以之前状态下的 ModelView 矩阵.

但我遇到以下问题:getFloatv 函数在我的浮点数组中返回 0 值,我不明白为什么(我的 ModelView 矩阵不为空:如果是,我不会在屏幕上显示我的立方体).

有人可以帮我找出问题所在吗?以下是代码的变化.

private float[] 上一个;公共 CubeRenderer() {mCube = 新立方体();以前的 = 新的浮动 [16];}公共无效onDrawFrame(GL10 gl){GL11 gl11 = (GL11) gl;gl11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);gl11.glMatrixMode(GL11.GL_MODELVIEW);gl11.glLoadIdentity();gl11.glTranslatef(0, 0, -3.0f);gl11.glRotatef(mAngleX, 0, 1, 0);gl11.glRotatef(mAngleY, 1, 0, 0);gl11.glEnableClientState(GL11.GL_VERTEX_ARRAY);gl11.glEnableClientState(GL11.GL_COLOR_ARRAY);/*if(!previous.equals(new float[16]))gl11.glMultMatrixf(previous, 0);*/gl11.glGetFloatv(GL11.GL_MODELVIEW_MATRIX, 上一个, 0);Log.d("尾矩阵",Integer.toString(previous.length));for(int i=0; i

提前谢谢你.

解决方案

根据您的设备,您可能正在使用 PixelFlinger 软件 GL 渲染器,不幸的是,至少在 1.2 版中没有实现 glGetFloat.如果是这种情况,检查 logcat 输出应该会显示与此有关的消息.

解决方案是自己处理矩阵,这样一开始就不需要从 OpenGL 中检索它们.像这样.

I'm learning Open GL ES and would like to get a more intuitive interface with 3D objects than the one suggested by google in the TouchRotateActivity sample.In order to do that, I would like to multiply my Modelview matrix by the ModelView matrix in the previous state.

But I encounter the following problem : getFloatv function returns 0 values in my float array, and I don't understand why (my ModelView matrix is not empty : if it was, I wouldn't get my cube on the screen).

Could someone help me to figure out what the problem is? Here are the changes in the code .

private float[] previous;

public CubeRenderer() {
    mCube = new Cube();
    previous = new float[16];
}

public void onDrawFrame(GL10 gl) {
    GL11 gl11 = (GL11) gl;

    gl11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    gl11.glMatrixMode(GL11.GL_MODELVIEW);
    gl11.glLoadIdentity();
    gl11.glTranslatef(0, 0, -3.0f);
    gl11.glRotatef(mAngleX, 0, 1, 0);
    gl11.glRotatef(mAngleY, 1, 0, 0);

    gl11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    gl11.glEnableClientState(GL11.GL_COLOR_ARRAY);

    /*if(!previous.equals(new float[16]))
        gl11.glMultMatrixf(previous, 0);*/
    gl11.glGetFloatv(GL11.GL_MODELVIEW_MATRIX, previous, 0);

    Log.d("taille matrice",Integer.toString(previous.length));
    for(int i=0; i<previous.length;i++)
        Log.d(Integer.toString(i),Float.toString(previous[i]));

    mCube.draw(gl11);
}

Thank you in advance.

解决方案

Depending on your device you might be using the PixelFlinger software GL renderer, which unfortunately does not implement glGetFloat, at least as of version 1.2. Checking the logcat output should reveal messages to this effect if this is the case.

The solution is to handle the matrices yourself so there's no need to retrieve them from OpenGL in the first place. Like so.

这篇关于GL11(Android)中的getFloatv函数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 16:49