Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android OpenGLES绘图缓冲区,空白屏幕_Android_Opengl Es - Fatal编程技术网

Android OpenGLES绘图缓冲区,空白屏幕

Android OpenGLES绘图缓冲区,空白屏幕,android,opengl-es,Android,Opengl Es,我试图用FloatBuffer为顶点绘制基本体,用ShortBuffer为索引绘制基本体。一切正常,没有崩溃或警告,但屏幕是空白的。我可以毫无困难地和敌人一起画画。 如果有人能看一下代码,我会非常感激 public abstract class PrimitiveBase extends DrawableEntity { protected float[] _vertices; protected short[] _indices; private FloatBuffe

我试图用FloatBuffer为顶点绘制基本体,用ShortBuffer为索引绘制基本体。一切正常,没有崩溃或警告,但屏幕是空白的。我可以毫无困难地和敌人一起画画。 如果有人能看一下代码,我会非常感激

public abstract class PrimitiveBase extends DrawableEntity {
    protected float[] _vertices;
    protected short[] _indices;

    private FloatBuffer _verticesBuffer;
    private ShortBuffer _indicesBuffer;

    public PrimitiveBase(Sprite sprite, float x, float y) {
        super(sprite, x, y);

    }

    protected abstract void setVertices();

    @Override
    public void draw(float x, float y, float scaleX, float scaleY) {
        GL10 gl = GlSystem.getGl();

        gl.glPushMatrix();
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();

        gl.glScalef(scaleX, scaleY, 1.0F);

        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

        gl.glVertexPointer(2, GL10.GL_FLOAT, 0, _verticesBuffer);
        gl.glColor4f(1.0F, 0, 0, 0);

        gl.glDrawElements(GL10.GL_TRIANGLES, _indices.length,
                GL10.GL_UNSIGNED_SHORT, _indicesBuffer);

        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

        gl.glPushMatrix();
    }

    @Override
    public void load(EntityManager parent) {

        setVertices();

        ByteBuffer vbb = ByteBuffer.allocateDirect(_vertices.length * 4);
        vbb.order(ByteOrder.nativeOrder());
        _verticesBuffer = vbb.asFloatBuffer();

        _verticesBuffer.put(_vertices);
        _verticesBuffer.position(0);

        ByteBuffer ibb = ByteBuffer.allocateDirect(_indices.length * 2);
        ibb.order(ByteOrder.nativeOrder());
        _indicesBuffer = ibb.asShortBuffer();
        _indicesBuffer.put(_indices);
        _indicesBuffer.position(0);
    }

}

public class Rectangle extends PrimitiveBase {
    private float _width;
    private float _heigth;

    public Rectangle(Sprite sprite, float x, float y, float width, float height) {
        super(sprite, x, y);
        _heigth = height;
        _width = width;
    }

    @Override
    protected void setVertices() {
        _vertices = new float[8];
        _indices = new short[] { 0, 1, 2, 0, 2, 3 };

        _vertices[0] = getX() - (_width / 2);
        _vertices[1] = getY() + (_heigth / 2);

        _vertices[2] = getX() + (_width / 2);
        _vertices[3] = getY() + (_heigth / 2);

        _vertices[4] = getX() + (_width / 2);
        _vertices[5] = getY() - (_heigth / 2);

        _vertices[6] = getX() - (_width / 2);
        _vertices[7] = getY() - (_heigth / 2);

    }

}

缓冲区是否包含有效值?你的顶点实际上在你的观察体积内?是的,它在观察体积内,我创建的矩形以(0,0)为中心,也尝试过使其非常大,但没有结果。这些值是否有效是一个更难的问题。所有的初始化代码都在上面的代码中。getX()=0,getY()=0..你的投影矩阵是什么样子的?我希望你不要在任何地方启用混合,因为目前你的矩形的alpha值为0(如果你不关心第四个分量,或者至少知道它的含义,请不要使用
glColor4
)。当我在我自己的电脑前时,我会检查它。