热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

OpenGL-从小于该屏幕的屏幕复制纹理-OpenGL-Copytexturefromscreensmallerthanthatscreen

Imtryingtocapturethescreentoatexturewithalowerresolutionthanthescreenitself(toren

I'm trying to capture the screen to a texture with a lower resolution than the screen itself (to render back onto the screen and create a blur/bloom effect), and it doesn't work quite well. I understand mipmaps can be used to do this, but I just can't get the correct sequence of commands to work.

我试图将屏幕捕获到分辨率低于屏幕本身的纹理(渲染回屏幕并创建模糊/绽放效果),并且它不能很好地工作。我知道mipmaps可以用来做到这一点,但我无法获得正确的命令序列。

My current code:

我目前的代码:

width=1024;
height=1024;

glGenTextures(1, &texture);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,  GL_MODULATE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );

glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, width, height, 0);

// code for rendering the screen back on goes here

1 个解决方案

#1


You can't capture and downfilter in one go. You have to capture the full screen to a larger texture first, then mipmaps should be created if auto-create mipmaps are enabled, then you can render one using that texture again, makig sure you adjust the mipmap level suitably.

你无法一次捕获和向下过滤。您必须首先捕获全屏到更大的纹理,然后如果启用了自动创建mipmap,则应创建mipmap,然后您可以再次使用该纹理渲染一个,确保您适当地调整mipmap级别。

However, that will look ugly, as the auto mipmapgeneration usually uses a box filter.

但是,这看起来很难看,因为自动mipmapgeneration通常使用盒式过滤器。

What I'd do is to set up some FBOs (Frame Buffer Objects) and GLSL shaders instead. That gives you finer control over all steps:

我要做的是设置一些FBO(帧缓冲对象)和GLSL着色器。这使您可以更好地控制所有步骤:

  • create the original image in a texture
  • 在纹理中创建原始图像

  • apply some nice gaussian low-pass filtering
  • 应用一些不错的高斯低通滤波

  • blend the filtering with the original image to the frame buffer
  • 将过滤与原始图像混合到帧缓冲区


推荐阅读
author-avatar
aaaaaaaaaa本尊
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有