Noobie Question - Displaying Images?

Danaugrs

17-09-2007 20:13:05

How can I simply display an image on the screen? Do i really need to use a GUI system just for that?
I managed to dysplay one image using CEGUI, but the code for it looks to be too much just to load and display images, specially just one!
And another thing, the image is displayed stretched horizontaly, but this probably happens because of the fact it isn't a perfect square.
If your image is a perfect square it doesn't get stretched.
If someone could show me an easier way of displaying images without a Gui system or using another one, like QuickGui, I would greatly appreciate.

The code for loading and displaying the images:


## setup GUI system
self.GUIRenderer = CEGUI.OgreCEGUIRenderer(self.renderWindow,
ogre.RENDER_QUEUE_OVERLAY, False, 3000, self.sceneManager)

self.GUIsystem = CEGUI.System(self.GUIRenderer)

CEGUI.SchemeManager.getSingleton().loadScheme("TaharezLookSkin.scheme")
self.GUIsystem.setDefaultMouseCursor("TaharezLook", "MouseArrow")

winMgr = CEGUI.WindowManager.getSingleton()

## load an image to use as a background
CEGUI.ImagesetManager.getSingleton().createImagesetFromImageFile("BackgroundImage", "transparent.png")

## here we will use a StaticImage as the root, then we can use it to place a background image
background = winMgr.createWindow("TaharezLook/StaticImage", "background_wnd")
## set position and size
background.setPosition(CEGUI.UVector2(cegui_reldim(0), cegui_reldim( 0)))
background.setSize(CEGUI.UVector2(cegui_reldim(1), cegui_reldim( 1)))
## disable frame and standard background
background.setProperty("FrameEnabled", "false")
background.setProperty("BackgroundEnabled", "false")
## set the background image
background.setProperty("Image", "set:BackgroundImage image:full_image")
## install this as the root GUI sheet
CEGUI.System.getSingleton().setGUISheet(background)

## now we create a DefaultWindow which we will attach all the widgets to. We could
## have attached them to the background StaticImage, though we want to be a bit tricky
## since we do not wish the background to be faded by the slider - so we create this
## container window so we can affect all the other widgets, but leave the background
## unchanged.
sheet = winMgr.createWindow("DefaultWindow", "root_wnd")
## attach this to the 'real' root
background.addChildWindow(sheet)

## load an image to use as a background
CEGUI.ImagesetManager.getSingleton().createImagesetFromImageFile("pane1Image", "TBlogo.png")

pane1 = winMgr.createWindow("TaharezLook/StaticImage", "pane_wnd1")
## set position and size
pane1.setPosition(CEGUI.UVector2(cegui_reldim(0.05), cegui_reldim( 0.1)))
pane1.setSize(CEGUI.UVector2(cegui_reldim(0.3), cegui_reldim( 0.3)))
## disable frame and standard background
pane1.setProperty("FrameEnabled", "false")
pane1.setProperty("BackgroundEnabled", "false")
## set the background image
pane1.setProperty("Image", "set:pane1Image image:full_image")
## install this as the root GUI sheet
sheet.addChildWindow(pane1)


I hope someone can help me :(

bharling

18-09-2007 16:29:42

Look into Ogre's overlay system, its all in the main documentation. You don't need to use CEGUI or anything apart from standard Ogre to display an image. Also, look into OgreCore.zip in the demos/media folder which has the overlay setup scripts for the default display (fps etc.)

Or, if you don't want to do that even, you can just make a plane object, with your own material file, and position that in front of the camera, but overlays are probably best for what you're trying to do.

Danaugrs

21-09-2007 19:38:11

Thank you!
I am gonna have a look at the overlay system and try to use it.
When I get it done i will post the code here.
If I found it's too complicated, i might just use a plane, but I'll try the overlay first. Hehe

Danaugrs

22-09-2007 15:38:43

I got it!
I made an overlay element Panel using the image I wanted.

.overlay file:

Tetris/Logo
{
container Panel(Tetris/Logo)
{
metrics_mode pixels
vert_align top
left 12
top 12
width 300
height 300
material Tetris/Logo
}
}


.material file

material Tetris/Logo
{
technique
{
pass
{
scene_blend alpha_blend
depth_writing off

texture_unit
{
texture TBlogo.png
}
}
}
}


On my program I wrote:

self.Logo = ogre.OverlayManager.getSingleton().getByName("Tetris/Logo")
self.Logo.show()


If you want to center your overlay you can do this:

Tetris/Logo
{
container Panel(Tetris/Logo)
{
metrics_mode pixels
horz_align center
vert_align center
left -150 // minus half of the width
top -150 // minus half of the height
width 300
height 300
material Tetris/Logo
}
}


Thank you again!

Danaugrs

NickM

22-10-2007 22:34:27

Thanks for posting up the answer, it saved me some research time. :D

scriptkid

23-10-2007 11:50:02

Do however note that if you use Overlays and Cegui together, you might need to make this call on your guirender:


self.GUIRenderer.setTargetRenderQueue(Ogre.RENDER_QUEUE_OVERLAY, True)


Because i experienced (when using overlays for backgrounds) that they would always draw on top of my Cegui windows.

Danaugrs

27-10-2007 14:36:12

If anyone is having trouble displaying images,
just post a reply here and I will be happy to help you!

Thanks for posting up the answer, it saved me some research time. Very Happy

Its good to know our endeavor is worth the trouble! Hehehe

Cya guys!