OpenGL渲染到纹理 [英] OpenGL Render to texture

查看:371
本文介绍了OpenGL渲染到纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这之前已经被问过了(我搜索过),但是我保证这一个是不同的。



我正在为Mac OS X Mountain Lion ,但我需要添加一点点绽放效果。我需要将整个场景渲染为屏幕尺寸的纹理,减小纹理的大小,将其传递通过像素缓冲区,然后将其用作四边形的纹理。



我再问一次,因为一些常用的技术似乎不起作用。我不能使用 #version 布局 out 在我的片段着色器中,因为他们不编译。如果我只是使用 gl_FragColor 作为正常,我得到随机片段的屏幕后面我的应用程序,而不是我试图渲染的场景。



因此,基本上,我如何使用Mac的Mac实现来正确地渲染纹理?您需要使用扩展程序吗?



我使用此处

解决方案

纹理最好使用 FBO ,它让您直接渲染到纹理中。如果您的硬件/驱动程序不支持OpenGL 3+,则必须通过 ARB_framebuffer_object 核心扩展或 EXT_framebuffer_object 扩展。



如果完全不支持FBO,您必须使用一个简单的 glCopyTexSubImage2D (即使只是GPU-GPU,更灵活但更复杂(已弃用)

http://www.songho.ca/opengl/gl_fbo.htmlrel =nofollow>关于FBO的教程提供了一个简单的示例,用于渲染纹理并使用此纹理进行渲染。由于问题缺少关于您在使用方法时遇到的特定问题的特定信息,因此现在对于通常的渲染到纹理资源的那些相当一般的googlable指针就足够了。


I know this has been asked before (I did search) but I promise you this one is different.

I am making an app for Mac OS X Mountain Lion, but I need to add a little bit of a bloom effect. I need to render the entire scene to a texture the size of the screen, reduce the size of the texture, pass it through a pixel buffer, then use it as a texture for a quad.

I ask this again because a few of the usual techniques do not seem to function. I cannot use the #version, layout, or out in my fragment shader, as they do not compile. If I just use gl_FragColor as normal, I get random pieces of the screen behind my app rather than the scene I am trying to render. The documentation doesn't say anything about such things.

So, basically, how can I render to a texture properly with the Mac implementation of OpenGL? Do you need to use extensions to do this?

I use the code from here

解决方案

Rendering to a texture is best done using FBOs, which let you render directly into the texture. If your hardware/driver doesn't support OpenGL 3+, you will have to use the FBO functionality through the ARB_framebuffer_object core extension or the EXT_framebuffer_object extension.

If FBOs are not supported at all, you will either have to resort to a simple glCopyTexSubImage2D (which involves a copy though, even if just GPU-GPU) or use the more flexible but rather intricate (and deprecated) PBuffers.

This tutorial on FBOs provides a simple example for rendering to a texture and using this texture for rendering afterwards. Since the question lacks specific information about the particular problems you encountered with your approach, those rather general googlable pointers to the usual render-to-texture resources need to suffice for now.

这篇关于OpenGL渲染到纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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