1

私はopenglビュー(CAEAGLLayer)を透明にレンダリングしようとしているので、その背後にUIViewを置くことができます。次の設定を使用して、透明なopengl背景を実現しています。

CAEAGLLayer* layer = (CAEAGLLayer*)eaglLayer;
layer.opaque = NO;
layer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
                            kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
                            nil
                            ];

私の問題は、opengl シーンのオブジェクトが透明になり、それらを通して見ることができるようになったことです (約 50% の透明度)。

シーン内のオブジェクトを透明にせずに、opengl シーンの背景を透明にするにはどうすればよいですか。

すべてのレイヤー、UIView、および UIWindows のアルファ値は 1.0 であり、layer.opaque が YES に設定されている場合はすべて単色であるため、シーン内のフラグメント シェーダーは問題を引き起こしていないことに注意してください。また、それが役立つ場合は、これがユニティ プロジェクトであることも付け加えておきます。

編集:

Unity セットアップのコードの一部。

int OpenEAGL_UnityCallback(UIWindow** window, int* screenWidth, int* screenHeight,  int* openglesVersion)
{
    CGRect rect = [[UIScreen mainScreen] bounds];

    // Create a full-screen window
    _window = [[UIWindow alloc] initWithFrame:rect];
    EAGLView* view = [[EAGLView alloc] initWithFrame:rect];
    UnityViewController *controller = [[UnityViewController alloc] init];
    sGLViewController = controller;

#if defined(__IPHONE_3_0)
    if( _ios30orNewer )
        controller.wantsFullScreenLayout = TRUE;
#endif

    controller.view = view;

    CreateSplashView( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? (UIView*)_window : (UIView*)view );
    CreateActivityIndicator(_splashView);

    // add only now so controller have chance to reorient *all* added views
    [_window addSubview:view];
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        [_window bringSubviewToFront:_splashView];

    if( !UnityUseOSAutorotation() )
    {
        _autorotEnableHandling = true;
        [[NSNotificationCenter defaultCenter] postNotificationName: UIDeviceOrientationDidChangeNotification object: [UIDevice currentDevice]];
    }

    // reposition activity indicator after we rotated views
    if (_activityIndicator)
        _activityIndicator.center = CGPointMake([_splashView bounds].size.width/2, [_splashView bounds].size.height/2);

    int openglesApi =
#if defined(__IPHONE_3_0) && USE_OPENGLES20_IF_AVAILABLE
    kEAGLRenderingAPIOpenGLES2;
#else
    kEAGLRenderingAPIOpenGLES1;
#endif

    for (; openglesApi >= kEAGLRenderingAPIOpenGLES1 && !_context; --openglesApi)
    {
        if (!UnityIsRenderingAPISupported(openglesApi))
            continue;

        _context = [[EAGLContext alloc] initWithAPI:openglesApi];
    }

    if (!_context)
        return false;

    if (![EAGLContext setCurrentContext:_context]) {
        _context = 0;
        return false;
    }

    const GLuint colorFormat = UnityUse32bitDisplayBuffer() ? GL_RGBA8_OES : GL_RGB565_OES;

    if (!CreateWindowSurface(view, colorFormat, GL_DEPTH_COMPONENT16_OES, UnityGetDesiredMSAASampleCount(MSAA_DEFAULT_SAMPLE_COUNT), NO, &_surface)) {
        return false;
    }

    glViewport(0, 0, _surface.w, _surface.h);
    [_window makeKeyAndVisible];
    [view release];

    *window = _window;
    *screenWidth = _surface.w;
    *screenHeight = _surface.h;
    *openglesVersion = _context.API;

    _glesContextCreated = true;

    return true;
}

void PresentSurface(EAGLSurfaceDesc* surface)
{
    if(_skipPresent)
    {
        UNITY_DBG_LOG ("SKIP PresentSurface:\n");
        return;
    }
    UNITY_DBG_LOG ("PresentSurface:\n");

    EAGLContext *oldContext = [EAGLContext currentContext];
    if (oldContext != _context)
        [EAGLContext setCurrentContext:_context];

    PreparePresentSurfaceGLES(surface);

    // presentRenderbuffer presents currently bound RB, so make sure we have the correct one bound
    GLES_CHK( glBindRenderbufferOES(GL_RENDERBUFFER_OES, surface->renderbuffer) );
    if(![_context presentRenderbuffer:GL_RENDERBUFFER_OES])
        printf_console("failed to present renderbuffer (%s:%i)\n", __FILE__, __LINE__ );

    AfterPresentSurfaceGLES(surface);

    if(oldContext != _context)
        [EAGLContext setCurrentContext:oldContext];
}


bool CreateSurface(EAGLView *view, EAGLSurfaceDesc* surface)
{
    CAEAGLLayer* eaglLayer = (CAEAGLLayer*)surface->eaglLayer;
    assert(eaglLayer == [view layer]);

    CGSize newSize = [eaglLayer bounds].size;
    newSize.width  = roundf(newSize.width);
    newSize.height = roundf(newSize.height);

#ifdef __IPHONE_4_0
    int resolution = UnityGetTargetResolution();

    if (    (resolution == kTargetResolutionNative || resolution == kTargetResolutionHD)
         && [view respondsToSelector:@selector(setContentScaleFactor:)]
         && [[UIScreen mainScreen] respondsToSelector:@selector(scale)]
       )
    {
            CGFloat scaleFactor = [UIScreen mainScreen].scale;
            [view setContentScaleFactor:scaleFactor];
            newSize.width = roundf(newSize.width * scaleFactor);
            newSize.height = roundf(newSize.height * scaleFactor);
            UnitySetInputScaleFactor(scaleFactor);
    }
#endif

    surface->w = newSize.width;
    surface->h = newSize.height;

    UNITY_DBG_LOG ("CreateWindowSurface: FBO\n");
    CreateSurfaceGLES(surface);
    GLES_CHK( glBindRenderbufferOES(GL_RENDERBUFFER_OES, surface->renderbuffer) );

    return true;
}

extern "C" bool AllocateRenderBufferStorageFromEAGLLayer(void* eaglLayer)
{
    return [_context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)eaglLayer];
}

extern "C" void InitEAGLLayer(void* eaglLayer, bool use32bitColor)
{
    CAEAGLLayer* layer = (CAEAGLLayer*)eaglLayer;

    const NSString* colorFormat = use32bitColor ? kEAGLColorFormatRGBA8 : kEAGLColorFormatRGB565;

    layer.opaque = NO;
    layer.drawableProperties =  [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
                                    colorFormat, kEAGLDrawablePropertyColorFormat,
                                    nil
                                ];
}
4

2 に答える 2

0

アルファ < 1 でフレームバッファをクリアします。つまり、

glClearColor(r, g, b, alpha); // where alpha < 1
glClear(GL_COLOR_BUFFER_BIT | … );

完全な透明度を得るには、アルファ = 0 が必要です。

于 2012-10-18T10:52:13.950 に答える
0

問題はPSDにあるようです。Unity では、テクスチャ用に psd をロードできます。彼らは奇妙な透明性の問題を引き起こしていました。それらをjpegに交換したところ、問題は修正されました。

于 2012-10-18T13:15:41.877 に答える