eduard martorell chanzá loto - wgm #32ruttan/gameengines/lectures/introduction to ogre… ·...

43
Eduard Martorell Chanzá LOTO - WGM #32

Upload: others

Post on 23-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

Eduard Martorell Chanzá

LOTO - WGM #32

Page 2: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� What is Ogre3D?

� Ogre3D features.

� Plugins, additional libraries and tools.

� An Ogre3D application.

� Step by step:� Installing OgreSDK.

� Base application.

� Configuration files.

� Exporting Blender meshes.

� Meshes, lamps and shadows.

� The dotScene format.

� Move your body!!!

� What about user input?

� Picking things

� Overlays

� Materials

� Documentation, tutorials and tools.

Zombie Driver

2

Page 3: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

�OGRE3D stands for Object-Oriented Graphics

Rendering Engine.

�Open Source implementation of a Scene

graph.

� Runs under Windows, Linux and Mac OSX.

�Abstraction to the underlying system libraries

(OpenGL or Direct3D).

� http://www.ogre3d.org

Garhasp

3

Page 4: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Materials.� Material declaration language.

� Supports vertex/fragment shaders (Cg,HLSL,GLSL).

� Material LOD.

� Meshes.� Curved bezier patches.

� Automatic or manual LOD.

� Animation.� Skeletal: blending of animations, manual bone control.

� Shape animation.

� SceneNode paths.

� Animate any object parameter.

Torchlight. Runic games.

4

Page 5: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Scene.� Multiple scene managers.

� Many shadow techniques.

� Special effects.� Full screen composition effects via scripts (blur, glow, HDR…).

� Particles.

� Others.� Resource management.

� Flexible plugin architecture.

SteamPunk Legends

Victory: The age of racing

5

Page 6: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Full addon list at

http://www.ogre3d.org/developers/addons

� OgreODE: ODE physics engine into Ogre.

http://www.ogre3d.org/tikiwiki/OgreODE

� CEGUI: UI library for creating windows and widgets.

http://www.cegui.org.uk/wiki/index.php/Main_Page

� Blendersceneexporter: Export dotScene from Blender.

� 3ds2mesh: Convert from .3ds to .mesh.

� Rmogreexporter: Export OGRE-compatible materials and

shaders from RenderMonkey.

6

Page 7: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

Root

ResourceManager Plugins

RenderSystem

SceneManager

SceneNode

Entity Light Camera

Viewport

7

Page 8: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

Creating an Ogre3D application

8

Page 9: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

�Download OgreSDK:

� http://www.ogre3d.org/download/sdk

� Run installer and select location:

� C:\OgreSDK is a good place.

�Add environment variable OGRE_HOME with

OgreSDK base directory.

� E.g.: C:\OgreSDK\OgreSDK_vc9_v1-7-2

9

Page 10: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Creating project from scratch.� Step by step guide for Visual Studio:� http://www.ogre3d.org/tikiwiki/Setting+Up+An+Application+-+Visual+Studio

� If you don’t want to start from scratch:� Visual Studio Ogre3D Wizard.� http://code.google.com/p/ogreappwizards/downloads/list

� Download Ogre Wiki Tutorial Framework:� http://www.ogre3d.org/tikiwiki/tiki-download_wiki_attachment.php?attId=61&page=Ogre%20Wiki%20Tutorial%20Framework&download=y

� Contains:� BaseApplication.cpp

� BaseApplication.h

� TutorialApplication.cpp

� TutorialApplication.h

10

Page 11: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Ogre Wiki Tutorial Framework is great for testing and followingOgre Wiki’s Tutorials.

� Pops up a configuration dialog and creates a window with anempty scene (and a camera handler to move around the scene).

mRoot->showConfigDialog();

mWindow = mRoot->initialise(true, “Title");

Show config dialog:

Create window:

11

Page 12: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� BaseApplication uses configuration files to load resources, plugins, etc.

� While testing set working directory to$(OGRE_ROOT)\bin\debug or$(OGRE_ROOT)\bin\release.

� Plugin configuration file contains all needed plugins(and others not always needed).

� Resource configuration file ( resources.cfg ) containsall media included in OgreSDK.� You can edit this file to add your own resource directory

(not recursive):

…[General] // Resource group nameFileSystem=../../mediaFileSystem=D:/Eduard/Ogre/TestOgre/media

12

Page 13: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Get Blender 2,4x (2,49b works fine):

� http://download.blender.org/release/

� Get and install Blender exporter for Ogre3D:

� http://www.ogre3d.org/download/tools

� Get and install Ogre Command Line Tools.� http://www.ogre3d.org/download/tools

13

Page 14: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Select a mesh to export.� Exporter can handle only one mesh at once.

� File->Export->OGRE Meshes.

• Selected mesh.

• Action animation to be exported.

• Add new actions.

• Game engine materials have diffuse

textures. Rendering materials material

color.

• Run OgreXMLConvertor to export to

.mesh.

• Preferences pannel. Here you can set

OgreXMLConvertor path.

14

See Ogre Meshes Exporter

manual, wich comes along

with the scripts, for more

details.

Page 15: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� To load an exported mesh:� Mesh files must be in one of “resources.cfg” directories.

� To create a lamp:

� Set shadow technique:

Ogre::Entity * entPulpo = mSceneMgr->createEntity( "Pulpo“ , "Pulpo.mesh“ ) ;Ogre::SceneNode * node = mSceneMgr->getRootSceneNode()->createChildSceneNo de();node- >attachObject( entPulpo );node- >setPosition( px , py , pz );node ->setScale( sx , sy , sz );node ->setOrientation( w , x , y , z );

mSceneMgr->setAmbientLight( Ogre::ColourValue( 0 , 0 , 0 ) );mSceneMgr->setShadowTechnique( Ogre:: SHADOWTYPE_STENCIL_ADDITIVE );

l ->setCastShadows( true );entity ->setCastShadows( true );

Ogre::Light* l = mSceneMgr->createLight( “LightName” );l ->setType( Ogre::Light:: LT_POINT );l ->setDiffuseColour( Ogre::ColourValue( 1.0 , 1.0 , 1.0 , 1.0 ) );l ->setAttenuation( range, constant, linear, quadrati c );l ->setPosition( Ogre::Vector3( x , y , z ) );

15

Page 16: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Light attenuation formula:� Luminosity = 1 / Attenuation

� Attenuation = Constant + Linear * Distance + Quadratic * Distance^2

� Some usefull values for given ranges:

16

Range Constant Linear Quadratic

3250 1,0 0,0014 0,000007

600 1,0 0,007 0,0002

325 1,0 0,014 0,0007

200 1,0 0,022 0,0019

160 1,0 0,027 0,0028

100 1,0 0,045 0,0075

65 1,0 0,07 0,017

50 1,0 0,09 0,032

32 1,0 0,14 0,07

20 1,0 0,22 0,20

13 1,0 0,35 0,44

7 1,0 0,7 1,8

http://www.ogre3d.org/tikiwiki/-Point+Light+Attenuation

Page 17: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Blender (2,4x) can also be used as a scene editor

(I’m afraid you’ll have to learn to use

Blender...).

� There is a plugin to export your scene (Cameras, lights and objects) to dotScene format.

� dotScene is a XML document describing the objects in your scene (position, name, attributes…).

<scene formatVersion="1.0.0"><nodes>

<node name="Columna"><position x="0.000000" y="0.000000" z="4.000000"/><quaternion x="0.000000" y="0.000000" z="-0.000000" w="1.000000"/><scale x="1.000000" y="1.000000" z="1.000000"/><entity name="Columna" meshFile="Columna.mesh"/>

</node><node name="Lamp">

<position x="0.000000" y="7.296784" z="0.000000"/><quaternion x="-0.284166" y="0.726942" z="0.342034" w="0.523275"/><scale x="1.000000" y="1.000000" z="1.000000"/><light name="Spot" type="point">

<colourDiffuse r="1.345455" g="1.231515" b="2.000000 "/>…

17

Page 18: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� DotScene format does not store mesh data, so each mesh mustbe exported manually.� No one said it was perfect…

� If you create 6 “link duplicates” in Blender, only ONE mesh should be exported.

� Unfortunatelly, the addon to load .scene (a.k.a. dotScene) files can’t be found on addons page.� An alternative is to add dotScene.h and dotScene.cpp to your project(see attached files).

� These files will read the .scene file and create the scene for you.

� TinyXML is needed to read the document.

� “GroupName” refers to the resource group name where dotScene file can be found. Usually “General”.

parseDotScene(“File.scene”,“GroupName”,mSceneMgr);

18

Page 19: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

Let’s take a break.

19

Page 20: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

• Rendered with Blender internal

renderer using approximate ambient

occlusion.

• Model exported with Rendering

materials.

• Animation “Action” from frame 1 to

100.

20

Page 21: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

• Rendered using Blender internal

renderer (without textures).

• Models exported with Game

Materials.

• Column model is only exported once.

• Scene exported as “.scene”.

• Notice that yelow light casts no

shadows.

21

Page 22: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

• OpenGL renderer.

• Scene loaded with parseDotScene.

• Octopus loaded manually.

• Yelow light casts shadows but it

shouldn’t.

• Additive stencil shadows.

22

Page 23: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

There are many things to learn yet.

23

Page 24: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

�Moving objects bring life to your scene.

� Skeletal animation.

� Shape key animation.

� Rigid body physics.

� Path animations.

� …

� For an object to be animated it needs to

update its position/pose/whatever every

frame.

� We need a FrameListener.

24

Page 25: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� A FrameListener provides 3 virtual methods:� virtual bool frameStarted( const FrameEvent& evt);

� Called just before a frame is rendered.

� virtual bool frameRenderingQueued( const FrameEvent& evt);

� Called while the GPU is bussy with rendering stuff.

� virtual bool frameEnded( const FrameEvent& evt);

� Called after the frame has been rendered.

� We usually use frameRenderingQueued method.� FrameEvent& evt contains the elapsed time since lastframe.

� FrameListeners must be registered.� How to tell the ROOT object we are a FrameListener?� Like this: mRoot->addFrameListener( this );

� Luckily for us, BaseApplication already is a FrameListener, so we only have to overload its methods.

25

Page 26: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Great, but how can I make my skeletal animated model move?� Create a pointer to an AnimationState.� Ogre::AnimationState *as;

� Get the current AnimationState for an action from your mesh.� as = myEntity->getAnimationState(“NameOfAction”);� Each action has its own AnimationState.

� Set properties for the AnimationState and enable it.� as->setLoop( true );� as->setEnabled( true );

� Update the AnimationState every frame.� as->addTime(evt.timeSinceLastFrame);

� IT’S ALIVE!!!

26

Page 27: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Animation states must be ENABLED before using them, otherwise no animation will be shown.

� You can use an Ogre::AnimationStateSet to hold ALL animations fromyour mesh and iterate through or access individual animation states.

� If more than one animation is playing at once, they will be blended.

#include <OgreAnimationState.h>

[...]Ogre::AnimationStateSet *ass = myEntity->getAnimation StateSet();

Ogre::AnimationStateSetIterator i = ass->getAnimatio nStateSetIterator();

while (i.hasMoreElements()) {i.current()->second->addTime(,01);i.moveNext();

}

ass->getAnimationState( “Walk” )->setEnabled( true );

ass->getAnimationState( “Walk” )->addTime(x);ass->getAnimationState( “Attack” )->addTime(x);

27

Page 28: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

�User input is achieved via OIS (ObjectOriented Input System).

�We can have keyboard, mouse and joystick input.� Buffered or unbuffered.

28

Page 29: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Buffered input.� Well known event-based system. Inherit from one of thefollowing classes:� OIS::KeyListener

� keyPressed(),keyReleased().

� OIS::MouseListener

� mouseMoved(),mousePressed(),mouseReleased().

� OIS::JoystickListener

� povMoved(),axisMoved(),

sliderMoved(),buttonPressed(),

buttonReleased().

� Must register as event listener to an OIS::Keyboard , OIS::Mouse or OIS::Joystick object.� These objects only accept ONE event listener.

� Look into BaseApplication’s createFrameListener()method.

� For more info follow this link:� http://www.ogre3d.org/tikiwiki/Using+OIS

� Or take a look to BaseApplication.

29

http://izkyoot.tumblr.com

Page 30: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Keyboard, mouse and joystick objects must be created

through an InputManager object, wich needs a handle to

our window.

� Since our BaseApplication is registered as eventListener for

keyboard and mouse, an easy and fast solution:

� Call our keyPressed(), keyReleased() etc. methods from

TutorialApplication::keyPressed(), keyReleased()… methods.

30

size_t mWindow->getCustomAttribute( "WINDOW", &windowHnd);OIS::InputManager *mInputMgr = OIS::InputManager::cre ateInputSystem( windowHnd );

OIS::Keyboard * mKeyboard = static_cast <OIS::Keyboard*>(mInputMgr->createInputObject( OIS::OISKeyboard, true ));

OIS::Mouse * mMouse = static_cast <OIS::Mouse*>(mInputMgr->createInputObject( OIS::OISMouse, true ));

bool TutorialApplication::keyPressed(const OIS::KeyEv ent &arg) {myKeyListener->keyPressed(arg);return BaseApplication::keyPressed(arg);

}

Page 31: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

�Unbuffered input.

� Query a device about its status.

� Create an instance of OIS::Keyboard ,

OIS::Mouse or OIS::Joystick .

� Refresh object status each frame:

� Query objects whenever you want.

mMouse->getMouseState().buttonDown(OIS::MB_Left);mKeyboard ->isKeyDown(OIS::KC_LSHIFT);

mKeyboard ->capture(); //This goes inside frameRenderingQueued()mMouse->capture();

OIS::Keyboard * mKeyboard ;OIS::Mouse * mMouse;//Created and initialised in “BaseApplication.cpp”

31

Page 32: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Mouse-Object picking is very easy in Ogre3D.

� Create an Ogre::Ray from our camera.

� Create an Ogre::RaySceneQuery* with our Ogre::Ray .

� Or update current query.

� Execute query and store its result.

� Iterate through results with an iterator.

mRayScnQuery = mSceneMgr->createRayQuery(ray);

mRayScnQuery->setRay(ray);

Ogre::RaySceneQueryResult& result = mRayScnQuery->e xecute();

Ogre::RaySceneQueryResult::iterator iter = result.beg in();while (iter != result.end())

iter++;

Ogre::Ray ray = mCamera->getCameraToViewportRay(Ogre::Real x, Ogre::Real y);

32

Page 33: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Each RayQuery’s result has two pointers (One of themis allways NULL):� worldFragment� Collision with static world geometry.

� Contains collision coordinates.

� Depends on wich SceneManager used.

� movable� Collision with any other mesh.

� Pointer to entity.

� Access scene node with:

� getParentSceneNode() .

� Get node name.

� Get node position.

Chess

33

Page 34: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Ogre3D provides overlay objects to create HUDs, menus, etc.� Overlays can be defined in an .overlay script file.

� Or you can create them in your code.

� 2D or 3D objects.

� More info about overlays here:� http://www.ogre3d.org/tikiwiki/-Overlay

Family Farm

34

Page 35: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� To display 2D text using overlays (code):

� Create an OverlayConainer (panel).

� Create TextAreaOverlayElement (textArea).

� Set textArea’s text, font and attributes.

� Create an Overlay (overlay).

� Add panel to overlay.

� Add textArea to panel.

� Show overlay.

Chess

35

Page 36: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

#include “OgreTextAreaOverlayElement.h”#include “OgreFontManager.h”[...]OverlayManager& overlayManager = OverlayManager::get Singleton();

// Create a panelOverlayContainer* panel = static_cast<OverlayContainer*>(overlayManager.creat eOverlayElement("Panel", "PanelName"));panel->setMetricsMode(Ogre::GMM_PIXELS); panel->setPosition(10, 10); panel->setDimensions(10 0, 100); //panel->setMaterialName("MaterialName"); // Option al background material

// Create a text areaTextAreaOverlayElement* textArea = static_cast<TextA reaOverlayElement*>( overlayManager.createOverlayElement("TextArea", "Te xtAreaName")); textArea->setMetricsMode(Ogre::GMM_PIXELS); textArea->setPosition(0, 0); textArea->setDimension s(100, 100); textArea->setCaption("Hello, World!"); textArea->setCharHeight(16); textArea->setFontName( “Fontname” ); textArea->setColourBottom(ColourValue(0.3, 0.5, 0.3 )); textArea->setColourTop(ColourValue(0.5, 0.7, 0.5));

// Create an overlay, and add the panelOverlay* overlay = overlayManager.create("OverlayNam e"); overlay->add2D(panel);// Add the text area to the panelpanel->addChild(textArea);// Show the overlayoverlay->show();

//from: http://www.ogre3d.org/tikiwiki/Creating+Overlays+vi a+Code

36

Page 37: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� It’s always better to use overlay scripts:� Less code.

� No recompilation needed ifchanged.

� Reusable between applications.

� .overlay format info here:� http://www.ogre3d.org/docs/m

anual/manual_41.html#SEC244

� Overlay general info here:� http://www.ogre3d.org/docs/m

anual/manual_12.html

// The name of the overlay comes first

MyOverlays/TestOverlay {

zorder 200

// Add a TextArea element inside the container

container Panel(MyOverlayElements/TestPanel) {

// Center it horizontally, put it at the top

left 0.25

top 0

width 0.5

height 0.1

material MyMaterials/APanelMaterial

// Add a TextArea element inside the container

element TextArea(HelloWorldText) {

font_name myFont

char_height 0.05

left 0.0

top 0.0

width 1.0

height 0.1

caption Hello World!!!

}

}

}

37

Page 38: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Fonts must be defined in .fontdef files.� Ogre3D uses rendered fonts.� .fontdef files allow you to define truetype or bitmapfonts.

MyArialFont {type truetypesource arial.ttfsize 16resolution 96

}

MyBitmapFont {type imagesource ImageFontFile.png // Alpha channel!!!

glyph A 0 0 0.1 0.1 // Top-Left and Bottom-Rightglyph B 0.1 0 0.2 0.1 // Relative coordinates…

}

38

Page 39: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Like overlays, materials can be created viacode or defined in a script material.

� For detailed info on material scripts see:� http://www.ogre3d.org/docs/manual/manual_14.html#SEC23

�Many materials can be defined inside a .material file.

�Materials can use fixed-pipeline or vertexand fragment programs.

39

Page 40: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Basic material template.� Material name:

“walls/wall1”.� 1 technique.� 1 pass.� 2 NAMED texture

units: Diffuse & Light.� Named texture

units allow us tocreate new materialsinheriting fromthis.

// This is a commentmaterial walls/wall1 {

// first, preferred techniquetechnique {

// first passpass {

ambient 0.5 0.5 0.5 diffuse 1.0 1.0 1.0

// Texture unit 0 texture_unit Diffuse {

texture bricks.jpg}

// Texture unit 1 (this is a multitexture pass)

texture_unit Light { texture lightmap.png colour_op add

} }

}}

40

Page 41: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Ogre comes with many example materials.� Normal mapping, transparent materials, etc.

� You can create your own materials by inheriting from anyother material and overriding some parameters.� To change texture files follow this example:

� To set an entity’s material just adjust its material name.� myEntity->setMaterialName(“materialName”);

material myMaterial : parentMaterial {set_texture_alias TextureUnitNAME myTexture.png

}

41

Page 42: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

� Ogre3D wiki IS THE ANSWER:

� http://www.ogre3d.org/tikiwiki/

� Tutorials, tools, FAQ, manual… anything you shouldneed is there.

� Ogre3D support forums:

� http://www.ogre3d.org/forums/

42

Page 43: Eduard Martorell Chanzá LOTO - WGM #32ruttan/GameEngines/lectures/Introduction to Ogre… · OGRE3D stands for Object-Oriented Graphics Rendering Engine. Open Source implementation

Any question?

Venetica

43