2011-12-16 63 views
0

我開始使用Apple的GLKit OpenGL OpenGL我有一些麻煩,讓我的精靈正常顯示。問題在於它們全都被細細的黑線包圍着。下面的屏幕截圖顯示了帶有包含透明度的png圖像紋理的兩個矩形(顯然)。爲什麼我的精靈在紋理周圍有陰影/線條/框架?

enter image description here

黑色的陰影,他們周圍是絕對不會的PNG圖像的一部分。綠色PNG沒有抗鋸齒,藍色有一個反鋸齒邊界。如果我只繪製一個精靈,黑色邊框也很明顯。代碼

特相關部分(希望如此......)是:

//render the scene 
-(void)render 
{ 
    glClearColor(69./255., 115./255., 213./255., 1.); 
    glClear(GL_COLOR_BUFFER_BIT); 
    [shapes enumerateObjectsUsingBlock:^(AAAShape *shape, NSUInteger idx, BOOL *stop) 
    { 
     [shape renderInScene:self]; 
    }]; 
} 

//creating and storing the effect inside shape class 
-(GLKBaseEffect *)effect 
{ 
    if(!effect) 
    { 
     effect = [[GLKBaseEffect alloc] init]; 
    } 
    return effect; 
} 

//rendering the shape (including effect configuration) 
-(void)renderInScene:(AAAScene *)scene 
{ 
    //TODO: Storing vertices in Buffer 
    self.effect.transform.projectionMatrix = scene.projectionMatrix; 
    self.effect.transform.modelviewMatrix = self.objectMatrix; 
    if(texture) 
    { 
     self.effect.texture2d0.enabled = GL_TRUE; 
     self.effect.texture2d0.envMode = GLKTextureEnvModeReplace; 
     self.effect.texture2d0.target = GLKTextureTarget2D; 
     self.effect.texture2d0.name = texture.name; 
    } 
    [self.effect prepareToDraw]; 

    if(texture) 
    { 
     glEnableVertexAttribArray(GLKVertexAttribTexCoord0); 
     glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, self.textureCoordinates); 
     glEnable(GL_BLEND); 
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
    } 

    glEnableVertexAttribArray(GLKVertexAttribPosition); 
    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, self.vertices); 
    glDrawArrays(GL_TRIANGLE_FAN, 0, self.vertexCount); 
    glDisableVertexAttribArray(GLKVertexAttribPosition); 

    if(texture) 
    { 
     glDisableVertexAttribArray(GLKVertexAttribTexCoord0); 
     glDisable(GL_BLEND); 
    } 
} 

任何想法嗎?謝謝。

回答

-3

來吧stackoverflowers,14小時,沒有答案;-)。在gamedev上,大衛花了14分鐘給this great answer。把他舉起來!

1

這爲我工作:

glEnable(GLES20.GL_BLEND); 
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 
+0

這是什麼回答了gamedev(見下文) – 2013-12-31 15:02:57