Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.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
Java Android OpenGL混合黑色_Java_Android_Opengl Es_Blending - Fatal编程技术网

Java Android OpenGL混合黑色

Java Android OpenGL混合黑色,java,android,opengl-es,blending,Java,Android,Opengl Es,Blending,似乎当我想在OpenGL中混合颜色时都是黑色的。无论是逐顶点颜色还是全局glColor4f() 整个绘图方法如下所示: public void Draw(Texture2D texture, Rectangle destination, Rectangle source, GLColor color, Vector2 origin, float Rotation) { //Enable Blending GL.glEnable(GL10.GL_BLEND);

似乎当我想在OpenGL中混合颜色时都是黑色的。无论是逐顶点颜色还是全局glColor4f()

整个绘图方法如下所示:

public void Draw(Texture2D texture, Rectangle destination, Rectangle source, GLColor color, Vector2 origin, float Rotation)
{
        //Enable Blending
        GL.glEnable(GL10.GL_BLEND);
        GL.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

        //Generate Vertices

        float[] vertices = {-origin.X, -origin.Y,
                            destination.Width - origin.X, -origin.Y,
                            destination.Width - origin.X, destination.Height - origin.Y,
                            -origin.X, destination.Height - origin.Y};

        FloatBuffer vertexBuffer = ByteBuffer.allocateDirect(vertices.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
        vertexBuffer.put(vertices);
        vertexBuffer.flip();


        //Generate Indices
        short[] indices = {0, 1, 2, 2, 3, 0};
        ShortBuffer indexBuffer = ByteBuffer.allocateDirect(indices.length * 2).order(ByteOrder.nativeOrder()).asShortBuffer();
        indexBuffer.put(indices);
        indexBuffer.flip();

        //Generate UV of Vertices
        float minU = 0;
        float maxU = 1;
        float minV = 0;
        float maxV = 1;

        if (source != null)
        {
            minU = (float)source.X / (float)texture.getWidth();
            maxU = (float)(source.X + source.Width) / (float)texture.getWidth();
            minV = (float)source.Y / (float)texture.getHeight();
            maxV = (float)(source.Y + source.Height) / (float)texture.getHeight();
        }
        float[] vertexUVs = {minU, minV,
                            maxU, minV,
                            maxU, maxV,
                            minU, maxV};
        FloatBuffer uvBuffer = ByteBuffer.allocateDirect(vertexUVs.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
        uvBuffer.put(vertexUVs);
        uvBuffer.flip();

        //Calculate Matrix
        TransformationMatrix matrix = new TransformationMatrix();
        matrix.Translate(destination.X + origin.X, destination.Y + origin.Y, 0);
        matrix.Rotate(0, 0, Rotation);

        //Bind Vertices
        GL.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        GL.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        //Bind Pointers
        GL.glEnable(GL10.GL_TEXTURE_2D);
        GL.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
        GL.glTexCoordPointer(2, GL10.GL_FLOAT, 0, uvBuffer);

        //Do Transformations
        GL.glMatrixMode(GL10.GL_MODELVIEW);
        GL.glLoadIdentity();
        GL.glTranslatef(matrix.TranslationX, matrix.TranslationY, matrix.TranslationZ);
        GL.glRotatef((float)Math.sqrt(matrix.RotationX * matrix.RotationX + matrix.RotationY*matrix.RotationY + matrix.RotationZ*matrix.RotationZ), matrix.RotationX, matrix.RotationY, matrix.RotationZ);

        //Bind Texture
        GL.glBindTexture(GL10.GL_TEXTURE_2D, texture.ID);

        //Color
        GL.glColor4f(color.R, color.G, color.B, color.A);

        //Draw Elements
        GL.glDrawElements(GL10.GL_TRIANGLES, vertices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);

        //Disable things
        GL.glDisable(GL10.GL_TEXTURE_2D);
        GL.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        GL.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        GL.glBindTexture(GL10.GL_TEXTURE_2D, 0);
        GL.glDisable(GL10.GL_BLEND)
}
不仅仅是alpha混合,任何混合都会导致此错误。 我知道我的代码有问题,但我想知道那是什么

提前谢谢


昨天看到这个问题的人都很抱歉。但我把一切都搞砸了。我只是想从头做起。

不是一个解决方案,只是一种预感。当我在平板电脑上玩一些游戏时,它会将一些图形(如烟雾)渲染为黑匣子,因为某些纹理存在问题


也许您的代码很好,只是OpenGL没有正确渲染图形?

很抱歉占用了您的时间。我找到了解决办法。我可以说我太蠢了,我没有检查它

我使用混合状态来确定混合功能,而不是openGL函数。静态值没有初始化,因为我在该类中使用了一个静态函数


openGL没有问题。

我认为PNG文件应该没有问题。或者我可以用其他方式对位图进行编码以使其正常工作?而且这个问题在没有纹理的情况下也存在。