[英]uniform values and OpenGL shaders
so I have a little animation I guess in openGL in a program I'm coding with shaders in QT. 所以我猜我在用QT中的着色器编码的程序中的openGL中有一些动画。
My animation changed as a function of the time. 我的动画随时间变化。 To calculate time I used a Timer in a Slot that would repeatedly update the time.
为了计算时间,我在插槽中使用了一个计时器,该计时器会反复更新时间。
I have a Qwidget, my vertex shader is very plain so I wont include the code. 我有一个Qwidget,我的顶点着色器很简单,所以我不会包含代码。
now for my fragment shader: 现在为我的片段着色器:
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
const char *fsrc =
"uniform float time;\n"
"in vec4 coordinates;\n"
"out vec4 outcolor;\n"
"void main(void)\n"
"{\n"
" float l,z=time;"
" outcolor=vec4(coordinates * time);" //<- pretend i did something with time here
"}\n";
fshader->compileSourceCode(fsrc);
and then my time update method: 然后我的时间更新方法:
void MyWidget::updateTime()
{
float seconds;
seconds = (float) ((double) clock() - startTime) / CLOCKS_PER_SEC;
program->setUniformValue("time", (float) seconds / (float) CLOCKS_PER_SEC);
}
and finally how I use it: 最后是我的用法:
timeTimer=new QTimer();
QObject::connect(timeTimer, SIGNAL(timeout()),this, SLOT(updateTime()));
timeTimer->start(20);
however when I run my program it compiles and executes but the timer doesn't update, no matter how long I wait. 但是,无论我等待多长时间,当我运行程序时,它都会编译并执行,但计时器不会更新。 My hunch is that I am not using a good way to update the time in my shader, what am I doing wrong?
我的直觉是我没有使用好的方法来更新着色器中的时间,我在做什么错?
My guess is that you are updating the time correctly but you are not re-drawing your widget. 我的猜测是您正在正确更新时间,但没有重新绘制窗口小部件。 You should call the function that re-draw the widget at the end of updateTime (I think the name of that function is repaint()).
您应该在updateTime结束时调用重新绘制窗口小部件的函数(我认为该函数的名称为repaint())。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.