首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多维数据集在显示中不可见

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

Stack Overflow用户
提问于 2012-09-29 05:35:10
回答 1查看 102关注 0票数 0

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

下面是我的渲染类:

代码语言:javascript
复制
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 )
    }
}

下面是我的square类:

代码语言:javascript
复制
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);
    }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-29 05:39:39

我看不到任何投影矩阵,所以我必须假设您使用单位投影矩阵。在这种情况下,在所有轴上渲染的唯一对象将介于-1和1之间。

以(1.5,0,-6)为中心的四边形在z轴上太远而不可见。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12647687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档