Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: OpenGL QT
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.
Posted 8-Oct-10 1:40am
Edited 12-Oct-10 22:19pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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. Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();

}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 235
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 13 Oct 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100