#include <QApplication>
#include <osg/Node>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osg/StateSet>
#include <osg/PositionAttitudeTransform>
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgParticle/PrecipitationEffect>
// 雨雪效果
#include <osg/MatrixTransform>
// 粒子效果
#include <osgParticle/PrecipitationEffect>
#include <osgParticle/Particle>
#include <osgParticle/LinearInterpolator>
#include <osgParticle/ParticleSystem>
#include <osgParticle/RandomRateCounter>
#include <osgParticle/PointPlacer>
#include <osgParticle/RadialShooter>
#include <osgParticle/ModularEmitter>
#include <osgParticle/ParticleSystemUpdater>
#include <osgParticle/ModularProgram>
#include <osgUtil/Optimizer>
#include <osgUtil/Simplifier>
#include <osgParticle/FireEffect>
// 雾
#include <osg/Fog>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/StateSet>
#include <osg/StateAttribute>
#include <osgViewer/ViewerEventHandlers>
#include <osgWidget/ViewerEventHandlers>
//
#include <QDebug>
class MyDrawCallback : public osg::Drawable::DrawCallback
{
public:
void drawImplementation(osg::RenderInfo &renderInfo, const osg::Drawable *drawable) const
{
static double dColor = 0;//颜色
glColor3f(dColor, 0, 0);
glBegin(GL_TRIANGLES);//在OSG中画一个opengl三角形
glVertex3f(0.0, 0.0, -2.0);
glVertex3f(0.2, 0.0, -2.0);
glVertex3f(0.0, 0.4, -2.0);
glEnd();
dColor += 0.01;//颜色渐变
if (dColor > 1.0)
{
dColor = 0.0;
}
}
};
int main(int argc, char *argv[])
{
osgViewer::Viewer viewer;
osg::Geometry* geometry = new osg::Geometry;
//此处一定要把显示列表设置为false,
//否则DrawCallback的drawImplementation()函数只会调用一次,而不是在画一帧时都动态更新opengl图形
geometry->setUseDisplayList(false);
geometry->setDrawCallback(new MyDrawCallback);//Drawable设置动态更新opengl图形
osg::Geode* geode = new osg::Geode;
geode->addDrawable(geometry);
geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
osg::Group* group = new osg::Group;
group->addChild(geode);
viewer.setSceneData(group);
viewer.setUpViewInWindow(35, 35, 500, 500);
// return viewer.run();
osg::Matrix mt;
mt.makeIdentity();
while (!viewer.done())
{
viewer.getCamera()->setViewMatrix(mt);
viewer.frame();
}
}
zhujianqiangqq
- 粉丝: 30
- 资源: 388
最新资源
- 【小程序毕业设计】理财软件后台服务源码(完整前后端+mysql+说明文档).zip
- python实现非线性和线性控制方法+项目源码+文档说明+代码注释
- 南京米联精品文档,xilinx zynq soc 修炼秘籍
- 带收缩损失的深度回归跟踪+项目源码+文档说明+代码注释+论文
- 树莓派4B开发板上,通过Qt+FFMPEG以多线程分别解码、编码USB摄像头视频数据
- ffmpeg+D3D实现的MFC音视频播放器,支持录像、截图、音视频播放、码流信息显示等功能 (可执行程序下载)
- content_1731484846051.zip
- 【Unity动画编辑插件】Animation Designer 快速生成角色动画、修改现有动画并进行定制化调整
- java项目,课程设计-ssm大学生兼职跟踪系统
- 创维8A12机芯 E730A系列软件升级过渡包 主程序软件 电视刷机 固件升级包 V014.001.019
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0