OpenGL-FBO和Alpha混合 [英] OpenGL - FBO and alpha blending

查看:341
本文介绍了OpenGL-FBO和Alpha混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找答案,但是我的问题找不到答案.

I was finding for answer, but I can't get answer for my problem.

我有FBO,但无法进行Alpha混合和多重采样. FBO将场景绘制为纹理,然后淹没到具有两个带纹理的三角形的默认帧缓冲区中.直接绘制到默认的帧缓冲区就可以了.

I have FBO and I can't get alpha blending and multisample to work. FBO draws scene to texture and then it's drown to default framebuffer with two textured triangles. Drawing directly to default framebuffer is fine.

这是默认帧缓冲区(顶部)和我的FBO(底部)之间的区别.

Here is difference between default framebuffer (top) and my FBO (bottom).

我使用带有2个彩色附件和1个深度附件的FBO. (仅使用GL_COLOR_ATTACHMENT0,第二个用于其他功能)

I use FBO with 2x color attachments and 1x depth attachments. (Only GL_COLOR_ATTACHMENT0 is used, second is for other function)

深度测试:已禁用

混合:已启用

多重采样:已启用

混合功能:GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA

Blending function: GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA

有什么想法吗?我究竟做错了什么?我无法混合任何透明对象,没有Alpha.如果您需要更多代码,我可以编辑帖子.

Any ideas? What am I doing wrong? I can't blend any transparent objects, there is no alpha. If you require more code, I can edit post.

此代码的代码结构更深,希望我能正确提取它.

This code is deeper in code structure, I hope, I extracted it properly.

设置FBO:

glGenFramebuffers(1, &_framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color0_texture_id, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, color1_texture_id, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_texture_id, 0);

设置颜色纹理:

glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

深度纹理相同,只是一行:

Depth texture is the same except one line:

// This is probably wrong
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);

混合现在正在工作,但仍然没有多重采样.怎么做?

Blending is working now, but still no multisample. How to do it?

推荐答案

要在渲染到FBO时使用多重采样,您需要使用glTexImage2DMultisample分配多采样纹理,并使用GL_TEXTURE_2D_MULTISAMPLE而不是GL_TEXTURE_2D将其附加到FBO.

To use multisampling when rendering to an FBO you need to allocate a multisample texture using glTexImage2DMultisample and attach that to the FBO using GL_TEXTURE_2D_MULTISAMPLE instead of GL_TEXTURE_2D.

来源: https://www.opengl.org/wiki/Multisampling#Allocating_a_Multisample_Render_Target

这篇关于OpenGL-FBO和Alpha混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆