简体   繁体   English

为什么我的子画面在纹理周围有深色阴影/线条/框架?

[英]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.

相关问题 纹理ASTextNode边框和阴影属性不起作用 - Texture ASTextNode border and shadow attributes do not work 在场景中添加两个自定义精灵,为什么这些精灵的方法会互相影响,谁能在我的代码中发现错误? 谢谢 - add two custom sprites into a scene,why do these sprites' methods will effect each other,anyone can find the mistake in my code? thanks 为什么我的Unity3D精灵在我的iPhone上渲染时会看起来像素化? - Why do my Unity3D sprites look pixelated when rendered on my iPhone? 为什么SpriteKit中的精灵不会从墙上弹起 - Why do sprites in SpriteKit not bounce off the wall 无法在导航栏下隐藏暗线-setBackgroundImage / shadow不起作用 - Can't hide dark line under nav bar - setBackgroundImage/shadow not working 我有一个纹理作为背景,但是它导致另一个纹理不在Spritekit中出现? - I have a texture as my background but it causing another texture not to appear in Spritekit? 为什么我的阴影层放置不正确? - Why is my shadow layer not positioned correctly? 为什么具有相同setPosition点的子画面看起来相距太远? - Why do sprites with the same setPosition point appear so far apart? 为什么我的 iOS 应用程序不禁用深色模式? - Why doesn't my iOS app disable dark mode? 为什么导航项/栏的颜色很暗? - Why is my navigation item/bar very dark in colour?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM