多维数据集在显示屏中不可见

时间:2012-09-28 21:35:10

标签: android opengl-es

我正试图在我的显示器上显示一个正方形但我不能。我的问题是什么?如何在屏幕(屏幕中央)上显示它?

这是我的渲染类:

public class GLRenderEx implements Renderer {

    private GLCube cube;
    Context c;

    GLCube quad; // ( NEW )

    // Constructor
    public GLRenderEx(Context context) {
        // Set up the data-array buffers for these shapes ( NEW )
        quad = new GLCube(); // ( NEW )
    }

    // Call back when the surface is first created or re-created.
    @Override
       public void onSurfaceCreated(GL10 gl, EGLConfig config) {
          // NO CHANGE - SKIP
       }

    // Call back after onSurfaceCreated() or whenever the window's size changes.
    @Override
       public void onSurfaceChanged(GL10 gl, int width, int height) {
          // NO CHANGE - SKIP
       }

    // Call back to draw the current frame.
    @Override
    public void onDrawFrame(GL10 gl) {
        // Clear color and depth buffers using clear-values set earlier
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

        gl.glLoadIdentity(); // Reset model-view matrix ( NEW )
        gl.glTranslatef(-1.5f, 0.0f, -6.0f); // Translate left and into the
                                                // screen ( NEW )

        // Translate right, relative to the previous translation ( NEW )
        gl.glTranslatef(3.0f, 0.0f, 0.0f);
        quad.draw(gl); // Draw quad ( NEW )
    }
}

这是我的方形课程:

public class GLCube {

    private FloatBuffer vertexBuffer; // Buffer for vertex-array

    private float[] vertices = { // Vertices for the square
    -1.0f, -1.0f, 0.0f, // 0. left-bottom
            1.0f, -1.0f, 0.0f, // 1. right-bottom
            -1.0f, 1.0f, 0.0f, // 2. left-top
            1.0f, 1.0f, 0.0f // 3. right-top
    };

    // Constructor - Setup the vertex buffer
    public GLCube() {
        // Setup vertex array buffer. Vertices in float. A float has 4 bytes
        ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
        vbb.order(ByteOrder.nativeOrder()); // Use native byte order
        vertexBuffer = vbb.asFloatBuffer(); // Convert from byte to float
        vertexBuffer.put(vertices); // Copy data into buffer
        vertexBuffer.position(0); // Rewind
    }

    // Render the shape
    public void draw(GL10 gl) {
        // Enable vertex-array and define its buffer
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
        // Draw the primitives from the vertex-array directly
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    }

}

1 个答案:

答案 0 :(得分:0)

我没有看到任何投影矩阵,所以我必须假设你使用身份投影矩阵。在这种情况下,在所有轴上渲染的唯一内容将介于-1和1之间。

以(1.5,0,-6)为中心的四边形将在z轴上太远而无法看到。

尝试删除两个翻译调用,看看它是否可见。