-1

It seems when i want to blend in OpenGL Colors are all black. No matter if it's a per vertex color or a global glColor4f().

The whole drawing method looks like this:

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)
}

Not just a alpha blending but any blending is causing this error. I know it's a problem with my code but I want to know what is that.

Thanks in advance!

For all the people saw this question yesterday sorry. But I messed up everything with it. I just wanted to start clean.

Daniel Sharp
  • 169
  • 1
  • 2
  • 12

2 Answers2

1

Sorry for stealing your time. I found the solution. And I can say I'm so stupid that I didn't check it.

I use blend states to determine blending functionality instead openGL functions. The static values were not initialized beauce I used a static function in that class to do so.

There's no problem with openGL.

Daniel Sharp
  • 169
  • 1
  • 2
  • 12
0

Not a solution but just a hunch. When I play some games on my tablet it renders some graphics such as smoke as black boxes because there's a problem with certain textures.

Maybe your code is fine and it's just OpenGL that's not rendering the graphic properly?

SaturnsEye
  • 6,297
  • 10
  • 46
  • 62
  • I think there shouldn't be problem with PNG files. Or can I encode bitmaps somehow else to make it work? And this problem also exists without texturing. – Daniel Sharp Jul 22 '13 at 14:49