[英]Why do my sprites have a dark shadow/line/frame surrounding the texture?
I'm starting OpenGL with Apple's GLKit hand I'm having some trouble to get my sprites displayed properly. 我正在用Apple的GLKit手启动OpenGL,但在使我的精灵正确显示时遇到了一些麻烦。 The Problem is that they all are surrounded with thin dark lines.
问题在于它们全都被细黑线包围。 The screen shot below shows two rectangles with a png image textures containing transparency (obviously).
下面的屏幕快照显示了两个带有png图像纹理的矩形,这些纹理包含透明度(显然)。
The black shadows, surrounding them are definitely not part of the pngS. 围绕它们的黑色阴影绝对不是pngS的一部分。 The green png is done without anti-aliasing the blue one has an anti-aliased border.
完成绿色png时不会进行抗锯齿,蓝色的png具有抗锯齿的边框。 The black border is also apparent if I draw only one sprite.
如果仅绘制一个精灵,则黑色边框也很明显。
Te relevant part (hope so...) of code is: 代码的相关部分(希望如此)是:
//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);
}
}
Any ideas anyone? 有任何想法吗? Thank you.
谢谢。
This worked for me: 这对我有用:
glEnable( GLES20.GL_BLEND );
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Come on stackoverflowers, 14 hours and no answers ;-). 来上stackoverflowers,14个小时,没有答案;-)。 On gamedev it took David 14 minutes to give this great answer .
在gamedev上,David花了14分钟给出了一个很好的答案 。 Vote him up!
投票给他!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.