2013-07-22 3 views
-1

OpenGL 색상을 혼합하려는 경우 모두 검은 색으로 보입니다. 그것이 버텍스 컬러인지 아니면 글로벌 glColor4f()인지 상관 없습니다.블렌딩을 사용하는 Android OpenGL Black 색상

전체 그리기 방법은 다음과 같습니다

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

뿐 아니라 알파 블렌딩 있지만 혼합이 오류의 원인이된다. 코드에 문제가 있다는 것을 알고 있지만 그게 무엇인지 알고 싶습니다.

미리 감사드립니다.

모든 사람들이 어제이 질문을 보았습니다. 그러나 나는 그것으로 모든 것을 엉망으로 만들었다. 나는 단지 깨끗하게 시작하고 싶었다.

답변

0

해결책이 아니라 단지 직감. 태블릿에서 일부 게임을 할 때 특정 텍스처에 문제가 있기 때문에 담배와 같은 그래픽을 검정 상자로 렌더링합니다.

코드가 좋고 그래픽이 제대로 렌더링되지 않는 OpenGL일까요?

+0

PNG 파일에는 문제가 없어야한다고 생각합니다. 또는 비트 맵을 다른 방법으로 인코딩하여 작동 시키도록 할 수 있습니까? 그리고이 문제는 텍스쳐링 없이도 존재합니다. –

1

죄송합니다. 해결책을 찾았습니다. 그리고 나는 내가 그것을 확인하지 않았을 정도로 어리 석다라고 말할 수있다.

블렌딩 상태를 사용하여 OpenGL 기능 대신 블렌딩 기능을 결정합니다. 정적 값은 정적 클래스를 사용하여 초기화되었습니다.

OpenGL에는 문제가 없습니다.