gpt4 book ai didi

iphone - 具有透明背景的 OpenGL ES 2.0 GLKit

转载 作者:技术小花猫 更新时间:2023-10-29 10:21:53 26 4
gpt4 key购买 nike

有没有办法让 GLKView 的背景透明?我试过解决方案 here但这对我不起作用。

*编辑:我需要帮助使其完全透明。背景主要是白色和灰色,但我只是用更鲜艳的颜色进行了测试,果然你可以隐约看到背景。任何想法为什么它会部分透明但不完全使用以下代码?

这是我的 View Controller 中的代码:

- (void)viewDidLoad
{
[super viewDidLoad];

self.context = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2] autorelease];
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.view.layer;
eaglLayer.opaque = NO;

if (!self.context) {
NSLog(@"Failed to create ES context");
}

GLKView *view = (GLKView *)self.view;
view.context = self.context;

view.backgroundColor = [UIColor clearColor];

view.drawableDepthFormat = GLKViewDrawableDepthFormat24;

[self setupGL];
}

- (void)setupGL
{
[EAGLContext setCurrentContext:self.context];

self.effect = [[[GLKBaseEffect alloc] init] autorelease];
self.effect.light0.enabled = GL_FALSE;
self.effect.light0.diffuseColor = GLKVector4Make(1.0f, 0.4f, 0.4f, 0.0f);
self.effect.light0.ambientColor = GLKVector4Make(1.0f, 0.4f, 0.4f, 0.0f);

glDisable(GL_DEPTH_TEST);

glGenVertexArraysOES(1, &_vertexArray);
glBindVertexArrayOES(_vertexArray);

glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_DYNAMIC_DRAW);

glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, VERTEX_POS_DATA_SIZE, GL_FLOAT, GL_FALSE, VERTEX_DATA_SIZE * sizeof(GLfloat), BUFFER_OFFSET(0));

glEnableVertexAttribArray(GLKVertexAttribColor);
glVertexAttribPointer(GLKVertexAttribColor, VERTEX_COLOR_DATA_SIZE, GL_FLOAT, GL_FLOAT, VERTEX_DATA_SIZE * sizeof(GLfloat), BUFFER_OFFSET(VERTEX_POS_DATA_SIZE * sizeof(GLfloat)));

glLineWidth(10.0);
}

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
if (!needsRedraw) return;
needsRedraw = NO;

glClearColor(0.65f, 0.65f, 0.65f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

[self.effect prepareToDraw];

glDrawArrays(GL_LINE_STRIP, 0, vertexCount);
}

我已经尝试将 的 backgroundColor 设置为 [UIColor clearColor] 并将 eaglLayer 设置为不透明。哎呀,我什至尝试将 eaglLayer 的 backgroundColor 设置为不透明度为 0 的 CGColorRef。

最佳答案

嗯,我认为这无关紧要,因为 alpha 已经是 0.0f,但是当我改变时

glClearColor(0.65f, 0.65f, 0.65f, 0.0f);

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

它使背景完全透明。

感谢大家的建议和帮助!

关于iphone - 具有透明背景的 OpenGL ES 2.0 GLKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10636176/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com