开发者

Problem with getFloatv function in GL11 (Android)

开发者 https://www.devze.com 2023-03-29 02:54 出处:网络
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.

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 Modelvi开发者_Python百科ew 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.


I don't program in Java, so for all I know, your problem could be in the way the memory is being passed to glGetFloatv. In any case, I found this page floating around out there, maybe it will help you.

0

精彩评论

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