Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.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 OpenGL ES纹理映射溢出_Android_Opengl Es_Mapping_Overflow_Textures - Fatal编程技术网

Android OpenGL ES纹理映射溢出

Android OpenGL ES纹理映射溢出,android,opengl-es,mapping,overflow,textures,Android,Opengl Es,Mapping,Overflow,Textures,我想为2d精灵工作表设置动画。我有一个精灵表,有很多不同帧大小的角色动画。对于单个动画,我缩放顶点以适合一帧,然后更改动画的纹理位置。对于一个动画效果很好,但是当切换到另一个具有不同帧大小和缩放顶点并再次拟合纹理的动画时,我得到了副作用,即纹理是拉伸的而不是拟合的,它仅在一个动画帧上,但使两个动画之间的更改看起来非常糟糕 我认为,这是因为顶点大小的变化。因此,我的想法是,有一个固定的顶点大小,并适合纹理,而不将其拉伸到整个顶点(每个动画的高度是固定的) 也许一个图像会有帮助,所以我创建了一个:

我想为2d精灵工作表设置动画。我有一个精灵表,有很多不同帧大小的角色动画。对于单个动画,我缩放顶点以适合一帧,然后更改动画的纹理位置。对于一个动画效果很好,但是当切换到另一个具有不同帧大小和缩放顶点并再次拟合纹理的动画时,我得到了副作用,即纹理是拉伸的而不是拟合的,它仅在一个动画帧上,但使两个动画之间的更改看起来非常糟糕

我认为,这是因为顶点大小的变化。因此,我的想法是,有一个固定的顶点大小,并适合纹理,而不将其拉伸到整个顶点(每个动画的高度是固定的)

也许一个图像会有帮助,所以我创建了一个:

这是我的代码,希望足够了:

public boolean nextFrame() {

    float textureWidth = textureMap()[currentAnimation][0];
    float frameCount = textureMap()[currentAnimation][1];
    float frameWidth = textureWidth / frameCount;

    if (loop) {
        if (currentFrame == frameCount)
            currentFrame = 0;
    } else {
        if (currentFrame == frameCount) {
            setAnimation(AnimationConstants.IDLE);
            loop = true;
            return false;
        }
    }

    float x_left = (float) currentFrame * frameWidth / textureWidth;
    float x_right = (float) (currentFrame * frameWidth + frameWidth)
            / textureWidth;

    texture[0] = x_left; // top left x
    texture[1] = 1.0f; // top left y

    texture[2] = x_left; // bottom left x
    texture[3] = 0.0f; // bottom left y

    texture[4] = x_right; // top right x
    texture[5] = 1.0f; // top right y

    texture[6] = x_right; // bottom right x
    texture[7] = 0.0f; // bottom right y

    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(texture.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());
    textureBuffer = byteBuffer.asFloatBuffer();
    textureBuffer.put(texture);
    textureBuffer.position(0);

    currentFrame++;

    return true;
}

private void newVertex() {
    float textureWidth = textureMap()[currentAnimation][0];
    float frameCount = textureMap()[currentAnimation][1];
    float frameWidth = textureWidth / frameCount;

    float width = (float) frameWidth / (float) frameHeight;

    vertices[0] = pos_x; // bottom left x
    vertices[1] = pos_y; // bottom left y

    vertices[3] = pos_x; // top left x
    vertices[4] = pos_y + (1.0f * scale); // top left y

    vertices[6] = pos_x + (width * scale); // bottom right x
    vertices[7] = pos_y; // bottom right y

    vertices[9] = pos_x + (width * scale); // top right x
    vertices[10] = pos_y + (1.0f * scale); // top right y

    // z values
    vertices[2] = -0.2f; // bottom left z
    vertices[5] = -0.2f; // top left z
    vertices[8] = -0.2f; // bottom right z
    vertices[11] = -0.2f; // top right z

    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());

    vertexBuffer = byteBuffer.asFloatBuffer();

    vertexBuffer.put(vertices);

    vertexBuffer.position(0);
}
因此,对于每个新动画,我都调用newVertex()。

签出。
我想你应该用同样的想法。如果需要,我可以详细描述如何在您的案例中正确放置纹理。

因此,您需要场景2,但正在向我们展示场景1的代码?只是词汇表上的一点。你们所谓的顶点实际上是一个顶点缓冲区对象,即一个几何体。真正的顶点是一个空间点,根据定义,它没有大小。@mkbeckish right,我想要情况2,但我不知道。因为我对opengl非常陌生,上面是我为显示我的代码情况而编写的第一个代码,因为可能整个概念都错了,我不知道。@rockeye和以前一样,我对它非常陌生,所以感谢您提供的信息,对吧,我指的是顶点缓冲区对象,尤其是正方形。