[英]Why do my sprites have a dark shadow/line/frame surrounding the texture?
我正在用Apple的GLKit手啟動OpenGL,但在使我的精靈正確顯示時遇到了一些麻煩。 問題在於它們全都被細黑線包圍。 下面的屏幕快照顯示了兩個帶有png圖像紋理的矩形,這些紋理包含透明度(顯然)。
圍繞它們的黑色陰影絕對不是pngS的一部分。 完成綠色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);
}
}
有任何想法嗎? 謝謝。
這對我有用:
glEnable( GLES20.GL_BLEND );
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
來上stackoverflowers,14個小時,沒有答案;-)。 在gamedev上,David花了14分鍾給出了一個很好的答案 。 投票給他!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.