统一的值和开放式着色器
uniform values and OpenGL shaders
本文关键字:开放式 更新时间:2023-10-16
,所以我在QT中使用着色器编码的程序中猜我有一个小动画。
我的动画随着时间的变化而变化。为了计算时间,我在插槽中使用的计时器会反复更新时间。
我有一个qwidget,我的顶点着色器很简单,所以我不包括代码。
现在,我的碎片着色器:
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);
然后我的时间更新方法:
void MyWidget::updateTime()
{
float seconds;
seconds = (float) ((double) clock() - startTime) / CLOCKS_PER_SEC;
program->setUniformValue("time", (float) seconds / (float) CLOCKS_PER_SEC);
}
最后我如何使用它:
timeTimer=new QTimer();
QObject::connect(timeTimer, SIGNAL(timeout()),this, SLOT(updateTime()));
timeTimer->start(20);
但是,当我运行程序时,它会编译和执行,但是计时器不会更新,无论我等待多长时间。我的直觉是我没有使用好方法来更新着色器中的时间,我在做什么错?
我的猜测是您正在正确更新时间,但您没有重新绘制小部件。您应该调用在UpdateTime末尾重新绘制小部件的函数(我认为该函数的名称是Repaver())。
相关文章:
- 开放式阅读WAV文件lib
- 矢量垫的开放式CV切片
- 如何在 2D 矢量中使用开放式 DFT
- 开放式颜色多边形表面的最简单方法
- 开放式AldistanceModel增益/衰减
- 比numpy/scipy openblas慢性 mkl或开放式布拉斯
- 通过HTTP(通过FFMPEG)流式开放式帧缓冲器
- 最小值/PIP用于开放式图
- 统一的值和开放式着色器
- 开放式CV相机校准过程
- 使用 ESP 开放式 SDK 部署到ESP8266
- 缺少使用中提琴opencv_core2410d.dll的开放式CV人脸检测
- 人脸识别开放式CV视觉工作室理解
- (开放式简历拼接)如何使用OpenCV Stitcher类获得更好的性能
- 为Dev C++安装开放式cv
- 什么是C++最好的开放式XML解析器