渲染到纹理是个很重要的技巧,特别是做海洋,湖泊这种水体渲染的时候.这里在OGRE实现下,到时候我用DX写一个渲染到纹理的例子,那时再讲原理

/*------------------------------------------------------------main.cpp -- Render to texture demo(c) Seamanj.2013/8/16
------------------------------------------------------------*/
//phase1 : Add Framework
//phase2 : Add environment ,knot mesh and ogrehead
//phase3 : Add a plane;
//phase4 : add a texture
//phase5 : add frame  listener
#define phase1 1
#define phase2 1
#define phase3 1
#define phase4 1
#define phase5 1
#if phase1
#include "ExampleApplication.h"
#include <windows.h>
#if phase5
class MyFrameListener : public ExampleFrameListener
{
protected:Camera* mReflectCam;SceneNode* mPlaneNode;
public:MyFrameListener(RenderWindow* window, Camera* maincam, Camera* reflectCam,SceneNode* planeSceneNode) : ExampleFrameListener(window, maincam),mReflectCam(reflectCam), mPlaneNode(planeSceneNode){}bool frameStarted( const FrameEvent& evt ){if( ExampleFrameListener::frameStarted( evt ) == false )return false;// Make sure reflection camera is updated toomReflectCam->setOrientation( mCamera->getOrientation());mReflectCam->setPosition( mCamera->getPosition());// Rotate plane/// mPlaneNode->yaw(Degree(30 * evt.timeSinceLastFrame), Node::TS_PARENT);return true;}};
#endif
class MyApplication : public ExampleApplication
#if phase5, public RenderTargetListener
#endif
{
#if phase3
protected:MovablePlane* mPlane;Entity* mPlaneEnt;SceneNode* mPlaneNode;
#if phase4Camera* mReflectCam;
#endif
#endif
public:MyApplication()
#if phase3: mPlane(0)
#endif{}~MyApplication(){
#if phase3delete mPlane;
#endif}
protected:
#if phase5void preRenderTargetUpdate(const RenderTargetEvent& evt){// Hide plane mPlaneEnt->setVisible(false);}void postRenderTargetUpdate(const RenderTargetEvent& evt){// Show plane mPlaneEnt->setVisible(true);}
#endifvoid createScene(){
#if phase2// Set ambient lightmSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));// Set skyboxmSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");// Create a lightLight* l = mSceneMgr->createLight("MainLight");l->setType(Light::LT_DIRECTIONAL);Vector3 dir(0.5, -1, 0);dir.normalise();l->setDirection(dir);l->setDiffuseColour(1.0f, 1.0f, 0.8f);l->setSpecularColour(1.0f, 1.0f, 1.0f);// Create 3 knotsEntity* knotEnt = mSceneMgr->createEntity( "Knot", "knot.mesh" );knotEnt->setMaterialName("Examples/TextureEffect2");Entity* cloneEnt;for(int n = 0; n < 3; n++ ){// Create a new node under the rootSceneNode* node = mSceneMgr->createSceneNode();// Random translateVector3 nodePos;nodePos.x = Math::SymmetricRandom() * 750.0;nodePos.y = Math::SymmetricRandom() * 100.0 + 25;nodePos.z = Math::SymmetricRandom() * 750.0;node->setPosition(nodePos);mSceneMgr->getRootSceneNode()->addChild(node);// Clone knotchar cloneName[12];sprintf(cloneName, "Knot%d", n);cloneEnt = knotEnt->clone(cloneName);//Attach to new nodenode->attachObject(cloneEnt);}// Create an ogreheadEntity* ogreHead = mSceneMgr->createEntity( "Head", "ogrehead.mesh" );mSceneMgr->getRootSceneNode()->createChildSceneNode( "Head" )->attachObject( ogreHead );
#if phase3mPlane = new MovablePlane("ReflectPlane");mPlane->d = 0;mPlane->normal = Vector3::UNIT_Y;MeshManager::getSingleton().createPlane("ReflectionPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,*mPlane, 4000, 4000,1, 1, true, 1, 1, 1, Vector3::UNIT_Z);mPlaneEnt = mSceneMgr->createEntity( "Plane", "ReflectionPlane");mPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();mPlaneNode->attachObject(mPlaneEnt);mPlaneNode->attachObject(mPlane);mPlaneNode->translate(0, -10, 0);//mPlaneNode->roll(Degree(5));
#if phase4TexturePtr texture = TextureManager::getSingleton().createManual( "RttTex",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D,512, 512, 0, PF_R8G8B8, TU_RENDERTARGET );RenderTarget *rttTex = texture->getBuffer()->getRenderTarget();mReflectCam = mSceneMgr->createCamera("ReflectCam");mReflectCam->setNearClipDistance(mCamera->getNearClipDistance());mReflectCam->setFarClipDistance(mCamera->getFarClipDistance());mReflectCam->setAspectRatio((Real)mWindow->getViewport(0)->getActualWidth() / (Real)mWindow->getViewport(0)->getActualHeight());Viewport *v = rttTex->addViewport( mReflectCam );v->setClearEveryFrame( true );v->setBackgroundColour( ColourValue::Black );MaterialPtr mat = MaterialManager::getSingleton().create("RttMat",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);//TextureUnitState* t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RustedMetal.jpg");TextureUnitState* t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");// Blend with base texture
//      t->setColourOperationEx(LBX_BLEND_MANUAL, LBS_TEXTURE, LBS_CURRENT, ColourValue::White,
//          ColourValue::White, 0.25);t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);t->setProjectiveTexturing( true, mReflectCam );//rttTex->addListener(this);// set up linked reflectionmReflectCam->enableReflection(mPlane);// Also clipmReflectCam->enableCustomNearClipPlane(mPlane);mPlaneEnt->setMaterialName("RttMat");#endif
#endif#endif}
#if phase5void createFrameListener(){mFrameListener = new MyFrameListener( mWindow, mCamera, mReflectCam, mPlaneNode );mRoot->addFrameListener( mFrameListener );}
#endif
};
INT WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{MyApplication app;try{app.go();}catch( Exception& e){MessageBoxA( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);}return 0;
}
#endif

chap8_1 Render to texture in OGRE相关推荐

  1. 什么是渲染目标(render target) 渲染到纹理(Render To Texture, RTT)详解

    渲染到纹理(Render To Texture, RTT)详解 RTT是现在很多特效里面都会用到的一项很基本的技术,实现起来很简单,也很重要.但是让人不解的是网上搜索了半天只找到很少的文章说这个事儿, ...

  2. 音视频开发之旅(38) -使用FBO实现渲染到纹理(Render to texture)

    目录 FBO基本知识 FBO实现渲染到纹理的流程 实践 遇到的问题 资料 收获 在之前的学习实践中我们把图片.视频.图形等渲染到屏幕时,采用的是直接屏幕上即默认的帧缓冲区,如果我们在渲染时不想直接渲染 ...

  3. 渲染到纹理(Render to texture):使用FrameBuffer

    弄了一天,找啊找,没找到什么例子,幸好irrlicht里有个使用FrameBuffer渲染到纹理的例子,看了下,一copy,哇,ok了啊. 主要代码: // generate color textur ...

  4. Antialiasing 抗锯齿效果(render to texture锯齿问题处理)

    很多时候需要把相机得texture渲染到texture上.但是效果往往不理想. 如图对比: 没有处理过得效果                                              ...

  5. 使用Render Texture制作游戏中的摄像头

    Render Texture是什么呢? Render Texture是一种你可以在其上绘制,然后像使用其它精灵/纹理一样的纹理.其中,最酷的一件事就是你可以将它作为相机视图的目标--这样相机把它所看到 ...

  6. CeGui+Ogre

    GUI http://lixinyiabc123.blog.163.com/blog/static/140977406201021835146121/ 我们的模拟器与大多数的游戏一样,都有2个主要状态 ...

  7. OGRE 所有版本(从0.1到1.7) (SDK 及 源码 及 扩展库) 下载地址

    OGRE 所有版本 (SDK 及 源码) 下载地址 http://zh.sourceforge.jp/projects/sfnet_ogre/releases/ 或者SVN地址 https://svn ...

  8. DXT纹理压缩,Multiple Render Targets

    游戏中对于3D物体表面细节的表现最重要的还是靠贴图来实现的,那么越是高分辨率越是真彩色的贴图自然表现力也是越强,但是同时带来的问题是所需占用的内存会成倍的上升,而节省内存这一点在目前的游戏中还是非常非 ...

  9. 关于Texture Cache简单总结

    Texture Cache是一个存储图片数据的只读cache 按照正常uv顺序读贴图tex cache有高命中率 Texture Cache在 shader processor附近,所以它有高吞吐率, ...

最新文章

  1. C语言\b回退一格!_只愿与一人十指紧扣_新浪博客
  2. GnuPG如何安全地分发私钥(1)GnuPG的用法
  3. metasploit快速入门(一)安装部署
  4. 类型两个数相减_小学数学简便计算12种分类+5种易错类型,打印出来给孩子练习!(可打印!)...
  5. java中在做除法操作时,对有余数的结果进行取整
  6. centos7.6+vim8.1
  7. 美团杯2020 - 半前缀计数(后缀自动机)
  8. Android开发之自定义输入框无法弹起键盘输入法的解决方法
  9. 程序包com.sun.istack.internal不存在
  10. C语言的数组基础,C语言基础-数组
  11. 全开源新淘商城系统源码
  12. 计算机地图概括的原理,第五章地图概括与自动综合
  13. Instagram使用教程
  14. 用python写生日快乐说说_生日快乐的说说(精选50句)
  15. 黑盒测试用例编写八大方法
  16. 八皇后——(第一场 递归与回溯)
  17. 网站如何防止被篡改?
  18. 比excel好用,还能解决数据孤岛问题,这款报表工具千万别错过
  19. python读取数据出现UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid contin
  20. 小论文中添加脚注(可以不显示标号)

热门文章

  1. Python:OpenCV的默认优化
  2. 以眼睛的名义:一些光度学概念的解析
  3. Qt信号与槽传递QList动态数组
  4. java实现用户分组,根据用户指定的组分组数据
  5. percona mysql 同步_Percona MySQL5.6 半同步复制
  6. 双级减速器优化matlab,基于matlab的二级齿轮减速器的优化设计.doc
  7. linux mmap实例_Linux下通过共享内存和mmap实现进程间通讯(含实例)
  8. python widget_python 图形界面
  9. 针对自动化测试的23种Node.js优秀实践
  10. linux 周期性任务,Linux任务计划,周期性任务执行详解