im试图渲染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场景的背景透明,同时仍然在场景中没有透明的对象。
请注意,所有层,Uiviews和Uiwindows的alpha值为1.0,场景中的片段着色器并没有引起问题,因为当所有内容都是纯色layer.opaque设置为"是"。我还要补充一点,如果有帮助,这是一个团结项目。
编辑:
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: FBOn");
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
];
}
用alpha&lt清除框架缓冲器;1,即
glClearColor(r, g, b, alpha); // where alpha < 1
glClear(GL_COLOR_BUFFER_BIT | … );
对于完整的透明度,您需要alpha =0。
好的,问题似乎与PSD有关。Unity使您可以在PSD中加载纹理。他们正在创建怪异的透明度问题。我把它们换成了jpegs,问题已解决。