我想绘制一个由 obs-display 渲染的透明窗口,当我设置 aplha 通道时,它在渲染时不起作用。
obs填充默认背景颜色(0x4C4C4C),obs的代码将alpha设置为1.0,我尝试将其他值设置为0.5f,但它不起作用。
// libobs/obs-display.c
static inline void render_display_begin(struct obs_display *display,
uint32_t cx, uint32_t cy, bool size_changed)
{
struct vec4 clear_color;
gs_load_swapchain(display->swap);
if (size_changed)
gs_resize(cx, cy);
gs_begin_scene();
// obs fill a default background color(0x4C4C4C)
vec4_from_rgba(&clear_color, display->background_color);
// obs's code set the alpha to 1.0 here
// I try to set the others value like 0.5f, but it is not working
clear_color.w = 1.0f;
gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH | GS_CLEAR_STENCIL,
&clear_color, 1.0f, 0);
gs_enable_depth_test(false);
/* gs_enable_blending(false); */
gs_set_cull_mode(GS_NEITHER);
gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f);
gs_set_viewport(0, 0, cx, cy);
}
void gs_clear(uint32_t clear_flags, const struct vec4 *color,
float depth, uint8_t stencil)
{
GLbitfield gl_flags = 0;
if (clear_flags & GS_CLEAR_COLOR) {
glClearColor(color->x, color->y, color->z, color->w);
gl_flags |= GL_COLOR_BUFFER_BIT;
}
if (clear_flags & GS_CLEAR_DEPTH) {
glClearDepth(depth);
gl_flags |= GL_DEPTH_BUFFER_BIT;
}
if (clear_flags & GS_CLEAR_STENCIL) {
glClearStencil(stencil);
gl_flags |= GL_STENCIL_BUFFER_BIT;
}
glClear(gl_flags);
}