QOpenGLTexture 两个纹理叠加
2016-03-02 15:57
465 查看
如何做纹理混合?
方法是,定义多个QOpenGLTexture,然后在fragment shader中添加相应的变量,然后把texture bind到对应的uniform变量上。
废话不多说
texture.frag
最后的0.2是一个混合系数。如果设置为0,则表示完全使用第一个纹理;设置为1,则完全使用第二个纹理。
程序中:
初始化texture
paintGL中使用:
这里为ourTexture1指定了一个unit,然后使用bind来把texture赋到指定unit的变量上去。
如果只有一个纹理,那么bind不需要传参数,默认是0;如果有多个纹理,则需要在bind的时候指定要把当前纹理放到哪个(uniform的)变量中,供fragment shader使用。
结果:
方法是,定义多个QOpenGLTexture,然后在fragment shader中添加相应的变量,然后把texture bind到对应的uniform变量上。
废话不多说
texture.frag
#version 400 core in vec3 ourColor; in vec2 TexCoord; out vec4 color; uniform sampler2D ourTexture; uniform sampler2D ourTexture1; void main() { color = mix(texture(ourTexture, TexCoord),texture(ourTexture1,TexCoord),0.3); }
最后的0.2是一个混合系数。如果设置为0,则表示完全使用第一个纹理;设置为1,则完全使用第二个纹理。
程序中:
初始化texture
texture = new QOpenGLTexture(QImage("./resources/texture/flower.jpg").mirrored()); texture->setMinificationFilter(QOpenGLTexture::Nearest); texture->setMagnificationFilter(QOpenGLTexture::Linear); texture->setWrapMode(QOpenGLTexture::Repeat); texture1 = new QOpenGLTexture(QImage("./resources/texture/DSCN4391.JPG").mirrored()); texture1->setMinificationFilter(QOpenGLTexture::Nearest); texture1->setMagnificationFilter(QOpenGLTexture::Linear); texture1->setWrapMode(QOpenGLTexture::Repeat);
paintGL中使用:
m_program->setUniformValue("ourTexture", 0); texture->bind(); m_program->setUniformValue("ourTexture1", 1); texture1->bind(1);
这里为ourTexture1指定了一个unit,然后使用bind来把texture赋到指定unit的变量上去。
如果只有一个纹理,那么bind不需要传参数,默认是0;如果有多个纹理,则需要在bind的时候指定要把当前纹理放到哪个(uniform的)变量中,供fragment shader使用。
结果:
color = mix(texture(ourTexture, TexCoord),texture(ourTexture1,TexCoord),0.3);原图: texture1
texture2
-- the end --
相关文章推荐
- linux下vsftp的搭建
- OpenWrt目录结构简介
- MyEclipse配置Tomcat没有Tomcat选项没有小猫图
- Nginx Upstream Keepalive 分析
- YARN环境中应用程序JAR包冲突问题的分析及解决
- 淘宝架构演变三阶段简单总结
- tomcat内存溢出解决,java.lang.OutOfMemoryError: PermGen space
- tomcat内存溢出解决,java.lang.OutOfMemoryError: PermGen space
- tomcat内存溢出解决,java.lang.OutOfMemoryError: PermGen space
- tomcat内存溢出解决,java.lang.OutOfMemoryError: PermGen space
- linux
- Linux Mint 17下Eclipse设置GTK参数调整界面无效
- WPF:把Task, Lazy和INotifyPropertyChanged组装成一个超级属性
- Tomcat类加载机制
- docker安装部署
- Nginx的负载均衡
- docker: dockerizing postgreSQL(加入自己的测试数据)
- Shell 中的连接符:&&、||
- yum命令收集
- linux ---tail命令