将GL Shader应用于在QGLWidget上绘制的QImage [英] Applying GL Shader to QImage drawn on QGLWidget

查看:119
本文介绍了将GL Shader应用于在QGLWidget上绘制的QImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..

我是GLSL初学者.我正在将着色器与Qt的OGL模块一起使用.
我已经创建了一个着色器,并在QGLWidget上绘制了图像,但是对于如何将着色器应用于图像对象感到困惑.

例如我已经创建了用于亮度的着色器,但是如何将gl_fragcolor值应用于图像?


请看一下我的代码,让我知道如何在paintGL()函数中更新图像时使用gl_FragColor值.
无效GLWidget :: initializeGL()
{
//*************** Shader for Brightness ************************//
QGLShader * vshader1 =新的QGLShader(QGLShader :: Vertex,this);
const char * vsrc1 =
改变mediap vec4 Alpha;"
"void main(void)\ n"
"{\ n"
"vec3 col = vec3(0.40,1.0,0.0);"
"Alpha = vec4(col * 0.2 + col * 0.8 * 0.45,1.0);"
"Alpha =钳位(Alpha,0.0,1.0);"
"gl_Position = Alpha;"
} \ n";
bool b1 = vshader1-> compileSourceCode(vsrc1);

QGLShader * fshader1 =新的QGLShader(QGLShader :: Fragment,this);
const char * fsrc1 =
可变的mediump float Alpha;"
无效主(无效)"
"{"
"gl_FragColor = gl_Color * Alpha;"
}";
bool bl = fshader1-> compileSourceCode(fsrc1);
bool addS = program1.addShader(fshader1);
bool addS1 = program1.addShader(vshader1);
bool链接= program1.link();
}

感谢您提供快速帮助.
提前谢谢.

Bhavana M.

Hi all..

I am GLSL beginner. I am using shader with Qt''s OGL module.
I have created a shader and have drawn an image on the QGLWidget but stuck about how to apply the shader to the image object.

e.g. I have created a shader for brightness, but how to apply gl_fragcolor value to the image?


Please Hv a Look at my code and let me know how to use gl_FragColor Value while Updating the image in paintGL() Function.
void GLWidget::initializeGL()
{
//***************Shader for Brightness************************//
QGLShader *vshader1 = new QGLShader(QGLShader::Vertex, this);
const char *vsrc1 =
"varying mediump vec4 Alpha;"
"void main(void)\n"
"{\n"
"vec3 col = vec3(0.40, 1.0, 0.0);"
"Alpha = vec4(col * 0.2 + col * 0.8 * 0.45, 1.0);"
"Alpha = clamp(Alpha, 0.0, 1.0);"
"gl_Position = Alpha;"
"}\n";
bool b1 = vshader1->compileSourceCode(vsrc1);

QGLShader *fshader1 = new QGLShader(QGLShader::Fragment, this);
const char *fsrc1 =
"varying mediump float Alpha;"
"void main (void)"
"{"
"gl_FragColor = gl_Color * Alpha;"
"}";
bool bl = fshader1->compileSourceCode(fsrc1);
bool addS = program1.addShader(fshader1);
bool addS1 = program1.addShader(vshader1);
bool link = program1.link();
}

Quick help is appreciated.
Thanks in advance.

Bhavana M.

推荐答案

我不确定QT语法是什么...但是总的来说,GLSL是编译并附加到对象上的.

在这种情况下,
1.创建一个指向着色器程序的对象.
2.寻找一个attach()方法. (可能类似于widget-> attach(ShaderObject *)).

这样,您可以附加着色器程序.考虑查看QT API参考.

好运. :)
I''m not sure what QT syntax is...But in general a GLSL is compiled and Attached to an object.

In this case,
1. create an object which will point to your shader program.
2. look out for an attach() method. (may be like widget->attach(ShaderObject *)).

In this way you can attach shader programs. Consider going through QT API reference.

Best luck. :)


请先看一下我的代码,让我知道如何在paintGL()函数中更新图像时使用gl_FragColor值.

无效GLWidget :: initializeGL()
{
//*************** Shader for Brightness ************************//

QGLShader * vshader1 =新的QGLShader(QGLShader :: Vertex,this);
const char * vsrc1 =
改变mediap vec4 Alpha;"
"void main(void)\ n"
"{\ n"
"vec3 col = vec3(0.40,1.0,0.0);"
"Alpha = vec4(col * 0.2 + col * 0.8 * 0.45,1.0);"
"Alpha =钳位(Alpha,0.0,1.0);"
"gl_Position = Alpha;"
} \ n";
bool b1 = vshader1-> compileSourceCode(vsrc1);


QGLShader * fshader1 =新的QGLShader(QGLShader :: Fragment,this);
const char * fsrc1 =
可变的mediump float Alpha;"
无效主(无效)"
"{"
"gl_FragColor = gl_Color * Alpha;"
}";
bool bl = fshader1-> compileSourceCode(fsrc1);
bool addS = program1.addShader(fshader1);
bool addS1 = program1.addShader(vshader1);
bool链接= program1.link();

}
Please Hv a Look at my code and let me know how to use gl_FragColor Value while Updating the image in paintGL() Function.

void GLWidget::initializeGL()
{
//***************Shader for Brightness************************//

QGLShader *vshader1 = new QGLShader(QGLShader::Vertex, this);
const char *vsrc1 =
"varying mediump vec4 Alpha;"
"void main(void)\n"
"{\n"
"vec3 col = vec3(0.40, 1.0, 0.0);"
"Alpha = vec4(col * 0.2 + col * 0.8 * 0.45, 1.0);"
"Alpha = clamp(Alpha, 0.0, 1.0);"
"gl_Position = Alpha;"
"}\n";
bool b1 = vshader1->compileSourceCode(vsrc1);


QGLShader *fshader1 = new QGLShader(QGLShader::Fragment, this);
const char *fsrc1 =
"varying mediump float Alpha;"
"void main (void)"
"{"
"gl_FragColor = gl_Color * Alpha;"
"}";
bool bl = fshader1->compileSourceCode(fsrc1);
bool addS = program1.addShader(fshader1);
bool addS1 = program1.addShader(vshader1);
bool link = program1.link();

}


这篇关于将GL Shader应用于在QGLWidget上绘制的QImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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