Текстовая текстура iPhone OpenGLES 2.0 со странной рамкой (не обводкой)

Я использую CoreGraphcis для создания текстовой текстуры. К сожалению, текст отображается так (цвет текста такой же, как и фон, чтобы продемонстрировать странную границу).

введите здесь описание изображения

Я пробовал играть с цветами обводки и границами, я думаю, что это относится к OpenGLES 2.0, а не к CoreGraphics.

// Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
    glGenFramebuffers(1, &defaultFramebuffer);
    glGenRenderbuffers(1, &colorRenderbuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);

    glActiveTexture(GL_TEXTURE0);
    glUniform1i(uniforms[UNIFORM_SAMPLER], 0);

    // Set up the texture state.
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    texture = [[FW2Texture alloc] initWithString:@"Text"];
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.width, texture.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.imageData);

И основной графический бит:

-(id)initWithString:(NSString*)str {
if((self = [super init])) {
    UIFont *font = [UIFont systemFontOfSize:17];
    CGSize size = [str sizeWithFont:font];

    NSInteger i;

    width = size.width;
    if((width != 1) && (((int)width) & (((int)width) - 1))) {
        i = 1;
        while(i < width)
            i *= 2;
        width = i;
    }

    height = size.height;
    if((height != 1) && (((int)height) & (((int)height) - 1))) {
        i = 1;
        while(i < height)
            i *= 2;
        height = i;
    }

    NSInteger BitsPerComponent = 8;

    int bpp = BitsPerComponent / 2;
    int byteCount = width * height * bpp;
    uint8_t *data = (uint8_t*) calloc(byteCount, 1);

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big;
    CGContextRef context = CGBitmapContextCreate(data,
                                                 width,
                                                 height,
                                                 BitsPerComponent,
                                                 bpp * width,
                                                 colorSpace,
                                                 bitmapInfo);
    CGColorSpaceRelease(colorSpace);

    CGContextSetGrayFillColor(context, 0.5f, 1.0f);
    CGContextTranslateCTM(context, 0.0f, height);
    CGContextScaleCTM(context, 1.0f, -1.0f);
    UIGraphicsPushContext(context);

    [str drawInRect:CGRectMake(0,
                               0,
                               size.width,
                               size.height)
           withFont:font
      lineBreakMode:UILineBreakModeWordWrap
          alignment:UITextAlignmentCenter];
    UIGraphicsPopContext();
    CGContextRelease(context);

    imageData = (uint8_t*)[[NSData dataWithBytesNoCopy:data length:byteCount freeWhenDone:YES] bytes];
}
return self;

}


person jbg    schedule 19.05.2011    source источник


Ответы (1)


Какой у тебя glBlendFunc? Вы берете предварительно умноженную альфу от CoreGraphics, поэтому, например. вместо граничного пикселя (r, g, b, 0,5) он будет (0,5 * r, 0,5 * g, 0,5 * b, 0,5). Это означает, что вы должны скомпоновать с включенным смешиванием, используя glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA), чтобы получить srcColour + (1 - альфа srcColour)*dstColour.

person Tommy    schedule 19.05.2011