Ogre中级教程7翻译版

2020-04-21 02:15

Ogre中级教程7 翻译by CatD

Table of contents 目录

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

Introduction 先决条件

Setting Up the Scene 创建场景

Creating a Texture 创建纹理

Writing Our Texture to a File 写出我们的纹理到文件 Implementing the Miniscreen 实现迷你场景

Creating a Material From Scratch 从头创建一个材质

Using a RenderTargetListener 使用一个渲染目标监听器

Render to Texture and Shaders 渲染到纹理和阴影

Exercises 练习

? ? ? ? ? ? ? ?

Easy 简单

Intermediate 中级

Difficult 困难

Advanced 地狱(括弧笑)

? ? ? ? ? ?

Conclusion 总结

Full Source 全部代码

Next 下一节

Introduction 先决条件

This tutorial covers the basics of rendering a scene to a texture. This technique is used for a variety of effects. It is particularly useful in combination with shaders. Motion blur effects can be created in this way.

本教程涵盖了渲染纹理到一个场景,这个技术用于制作出各种效果,它在结合着色器时格外的有用,可以用这种方法创建动态模糊效果。

The basic idea is rather simple. Instead of just sending render information strictly to our render window, we will also send the information to be rendered directly to a texture in our scene. This texture will then be used like a texture loaded from the hard drive.

基本的想法非常简单,咱在咱的场景里发送直接渲染的信息到纹理来代替咱发送严格的渲染信息,这种结构将用起来像是使用一个已经被硬盘加载的纹理。 The full source for this tutorial is here. 本教程的完整代码链接。

Note: There is also source available for the BaseApplication framework and Ogre 1.7 here. 注意:我们同时也准备了Baseapplication框架和Ogre1.7的资源链接。

Setting Up the Scene 建立场景

First, as usual, we are going to set up a basic scene. Add the following variables to your project.

首先,和往常一样,咱准备建立一个基本的场景,为你的工程添加下面的代码:

BasicApp.h

Ogre::MovablePlane* mPlane; Ogre::Entity* mPlaneEntity; Ogre::SceneNode* mPlaneNode; Ogre::Rectangle2D* mMiniscreen;

Remember to initalize them all in the constructor. 记得在构造器里面注册这些:

BasicApp.cpp

mPlane(0), mPlaneEntity(0), mPlaneNode(0), mMiniscreen(0)

Finally, we'll set up the basic scene elements we need. Add the following to createScene: 终于,咱准备好了咱创建基本场景所需要的所有元素辣,将下面的代码扔进咱的createScene()创建场景函数里:

mSceneMgr->setAmbientLight(Ogre::ColourValue(0.2, 0.2, 0.2));

//设置环境灯光颜色为0.2,0.2,0.2最大值为1

Ogre::Light* light = mSceneMgr->createLight(\); light->setPosition(20, 80, 50);

//创建MainLight这里没有设置灯光的类型,采取了默认的设置 mCamera->setPosition(60, 200, 70); mCamera->lookAt(0,0,0);

//设定了摄像机的位置和LookAt(指向)的点 Ogre::MaterialPtr mat =

Ogre::MaterialManager::getSingleton().create( \,

Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); //使用材质管理器创建了材质

Ogre::TextureUnitState* tuisTexture = mat->getTechnique(0)->getPass(0)-

>createTextureUnitState(\); //不知道在干啥(括弧笑

mPlane = new Ogre::MovablePlane(\); mPlane->d = 0;

mPlane->normal = Ogre::Vector3::UNIT_Y; //创建一个平面

Ogre::MeshManager::getSingleton().createPlane( \,

Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, *mPlane,

120, 120, 1, 1, true, 1, 1, 1,

Ogre::Vector3::UNIT_Z);

mPlaneEntity = mSceneMgr->createEntity(\); mPlaneEntity->setMaterialName(\); //实体化平面

mPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

mPlaneNode->attachObject(mPlaneEntity); //将平面绑定到场景节点中

If any of this is confusing, refer to previous tutorials. Compile and run your application. You should see a rotating grass-textured plane.

加入你对上面的代码有任何不太懂的地方,那么你需要复习一下前面的教程辣!完成并运行一下你的程序,你应该可以看到一个在不停的旋转的草地。

Creating a Texture

The first step is to create a texture we can render to. Add the folowing to createScene: 第一步咱要做的事情就是创建一个纹理以便咱渲染,添加下面的代码到咱的createScenen()函数内:

Ogre::TexturePtr rttTexture =

Ogre::TextureManager::getSingleton().createManual( \,

Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,

mWindow->getWidth(), mWindow->getHeight(), 0,

Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);

The first parameter of this function is the name to give the texture (\standard). The second specifies the default resource group. The third specifies the type of the texture to be 2D. The fourth and fifth specify the width and height of the texture. The sixth parameter is the number of mipmaps to be used. The seventh is a texture format, and the last is a usage flag.

这块函数的第一个参数功能是给材质命名,第二个参数则指定了默认的资源包,第三个参数指定了材质的类型为2D,第四个参数和第五个参数指定了材质的高和宽,第六个参数则是咱要使用的mipmaps(纹理图片)的数量,第七个则是材质的格式,最后一个是用法标记。 There are many different texture formats, but the simplest one is PF_R8G8B8. This produces a 24-bit RGB texture. If you need an alpha channel, then PFR8G8B8A8 will work fine. 材质的格式有非常多种,但是最简单的一种就是PF_R8G8B8,是一种24-bit RGB材质,如果你想修改下透明图,那么PFR8G8B8A8就能胜任。

Next we need to get a pointer to the render target of this texture in order to set some parameters. It will also be used later to add a RenderTargetListener.

接下来我们需要获得一只指针指向纹理的渲染目标以便我们设定一些参数,同时待会也会用于添加RenderTargetListener()渲染目标监听器:

Ogre::RenderTexture* renderTexture = rttTexture->getBuffer()->getRenderTarget();

renderTexture->addViewport(mCamera);

renderTexture->getViewport(0)->setClearEveryFrame(true); renderTexture->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black);


Ogre中级教程7翻译版.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:溶剂罐区作业指导书

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: