내가 그 뒤에 UIView를 넣을 수 있도록 OpenGL보기 (CAEAGLLayer)를 투명하게 렌더링하려고합니다. 투명한 OpenGL 백그라운드를 만들기 위해 다음 설정을 사용하고 있습니다.투명 OpenGL CAEAGLLayer
CAEAGLLayer* layer = (CAEAGLLayer*)eaglLayer;
layer.opaque = NO;
layer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
nil
];
내 문제는 이제 내 OpenGL 화면의 개체가 투명 해져서 (약 50 %의 투명도로) 볼 수 있습니다.
장면의 객체를 투명하게 유지하면서 OpenGL 장면의 배경을 투명하게 만들려면 어떻게해야합니까?
layer.opaque가 YES로 설정된 경우 모든 레이어, UIViews 및 UIWindows의 알파 값은 1.0이며 장면의 조각 쉐이더는 모든 것을 단색으로 처리하므로 문제가 발생하지 않습니다. 또한이 프로젝트가 도움이된다면 이것이 하나의 프로젝트라고 덧붙여 야합니다.
편집 :
화합의 일부 코드가 설정되었습니다.
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
];
}
투명도는 픽셀 화 된 모양을 나타냅니다 – user346443