Gorilla - minimal hud and overlay replacement for OGRE

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by cullam »

Alternatively, is there a way that I can treat the image created by a Caption or MarkupText as an image, and therefore be able to change and scale it like I would a Rectangle background? After carefully going through the functions in both Caption and MarkupText, I haven't found a way to do either of these things...
Spekoda
Halfling
Posts: 40
Joined: Wed Jun 12, 2013 5:38 pm
Location: Finland
x 2

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by Spekoda »

cullam wrote:Is it possible to change the display size of text, other than by selecting a different pre-set size? I'm rebuilding a 2D animation manager to use Gorilla, instead of Ogre Overlays, but all the size functions for Captions and MarkupText seem to only change the bounding box for text, and not the displayed size. Is it possible to change the size arbitrarily at runtime? That would be necessary for any growing or shrinking animations.
Thanks.
Here is one way to make font of any size from one size (I'm not saying it's best or even good, just a quick idea):
You could create a caption in 3d space and have a camera render it into a texture. The screenRenderable (layer) that created the caption will be attached to a scene node that is always facing the camera. The node is translated to a position away from the camera along a camera to viewport ray. The distance of the node's position from the camera is proportional to the size of the font rendered onto the texture.
Unfortunately the size is also related to the projection parameters, so it gets a bit involved. Anyways it's one way of doing it.
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by cullam »

That won't work in this case, as I'm using these menus with the Oculus Rift. So you can't use the side effect of apparent size through changing distance, as your eyes can quite clearly see the distance. This is why I'm using Gorilla in the first place, repacing the Ogre Overlay system - the overlays work by being overlays onto the screen (sensibly), but that won't work for getting them to show up properly in 3D space, as they need to when using a head mounted display. Gorilla does this part beautifully, but I can't (as of yet) figure out how to re-implement my scaling/sizing GUI animations, as Gorilla appears to want all text sizes pre-hard-coded. I've been away at Gen Con for the last week, but now I'm back, hoping to finally squash this problem. Any other suggestions? There was one I saw that looked rather messy, as it involved doing some scaling on each individual letter, which would be expensive to be doing to a paragraph of text, 60 times a second. I might be able to adapt that approach on the whole block though... maybe. So yeah, taking any and all suggestions!
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by cullam »

I still haven't solved my initial text issue, and I've run into a second one, so I'm now looking for a way to render the graphics of a Caption as an image, so I can assign it to a rectangle, and treat text blocks exactly like I treat all other images. Is this a thing that people have done with Gorilla before? If I can render the pixel data of my Caption to the background of a Rectangle, then just treat it as image information, all the issues go away, as I'm never editing text, once it's displayed on screen. Any know a starting point for doing this? T'would be appreciated.
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58
Contact:

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by betajaen »

Hi Guys,

I'm still alive, just been busy with non-OGREy stuff. I was thinking who would like to take up the challenge of porting this to Gorilla/OGRE.

https://github.com/memononen/nanovg

I mean who doesn't want 2D Vector Graphics :)

Your Friend,

Betajaen
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by c6burns »

No one doesn't :o I kudos you for the mere idea lol
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am
x 24

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by N0vember »

I'm using gorilla for a homemade Ui library, but I'm facing one dead-end :
Did anyone get to clip text vertically in Gorilla, in a patch or with the builtin functionality ?

(Also, much less important, but did anyone else notice that the size reported by Caption::_calculateDrawSize isn't exactly the size needed to contain the full caption ?)
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by AshMcConnell »

Is there a way to set the background of the entire screen to transparent? I am rendering my driver name to texture to use on a billboard, but it always has a black background. I may be missing something really obvious as I am really sleep deprived (baby teething ;))

Here is how it looks: -
Image
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am
x 24

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by N0vember »

A screen in Gorilla doesn't have a color by itself. Only the elements that you add to it do (Captions, Rectangles...)
So if your texture has a colored background, it's either :
- That your texture was not transparent to begin with before Gorilla did anything
- Or that you somehow used a feature of gorilla which colored the background (again, a Caption, a Rectangle...)
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by AshMcConnell »

Thanks November. I realised the texture I was rendering to didn't have an alpha component, I also had to add _billboardSet->setRenderQueueGroup(Ogre::RENDER_QUEUE_SKIES_LATE + 1);

It's been a while since I've done much with Ogre itself, so I can't quite remember how everything works, but it's almost as I'd like it. The only odd thing is that it seems to be about 0.5 opacity for some reason, I'll continue tweaking :)

Image
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by AshMcConnell »

Apologies for the images, but I'm finding it hard to get to the bottom of this one. Seems if I set the colour to anything other than white it starts to become transparent, progressing up to black which is completely transparent.

For the image below the text is white (fully opaque), the border on the rectangle is DarkGrey (even though it appears white) and the rectangle itself is set to fully opaque purple (which looks transparent)

Image


What I'm doing is: -

- Creating a dedicated scene manager
- Creating a camera for that scene manager
- Creating a texture (rendertarget) to render the player name into - I've tried LOTS of different pixel formats (currently using Ogre::PixelFormat::PF_R8G8B8A8)
- Assigning the texture to a basic material: -

Code: Select all

material PlayerNameBannerMaterial1
{
	technique test
	{
		pass testpass
		{
			scene_blend add
			lighting off
			depth_write off
			depth_test off
			
			texture_unit FS01dash
			{
				
				texture PlayerNameBannerTexture1
			}
		}

	}

}
- create a billboardset / billboard and set the material name to PlayerNameBannerMaterial1 (as above)
- Here is the code to Create the username text and licence colour rectangle : -

Code: Select all

_textLayer = _gorillaScreen->createLayer(0);

_nameCaption = _textLayer->createCaption(24, 256 + 5, 0,_playerName);
_nameCaption->align(Gorilla::TextAlignment::TextAlign_Centre);
_licenceColourRect = _textLayer->createRectangle(0,4, 10,32);
_licenceColourRect->background_colour(Gorilla::Colours::Colour::Purple);
_licenceColourRect->border_colour(Gorilla::Colours::Colour::DarkGrey);
_licenceColourRect->border_width(2);


Ogre::Vector2 knownSize;
_nameCaption->_calculateDrawSize(knownSize);
_licenceColourRect->left(256 - (knownSize.x *  0.5f) - 10);
_gorillaScreen->getViewport()->clear();
_gorillaScreen->getViewport()->update();
Is there anything I'm forgetting / doing wrong?

Thanks for your help!
- Ash
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am
x 24

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by N0vember »

AshMcConnell wrote: - Creating a texture (rendertarget) to render the player name into - I've tried LOTS of different pixel formats (currently using Ogre::PixelFormat::PF_R8G8B8A8)
How are you filling the texture pixel data ? Manually ? If yes can you show that part of the code ?
In my mind it can only come from that part... If the rectangle is purple and transparent, it means the pixel data has been fucked up and its alpha value has been tampered with.
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by AshMcConnell »

HI N0vember, thanks for your help!

Sorry I missed a part: -

- I add a viewport to the texture's rendertarget.
- This viewport is passed to the createScreen factory method
- When I do a manual update of the viewport it will render everything in this scene (which is only the Gorilla screen as I'm using a dedicated scenemanager).

I'm not sure at what point the alpha value is being messed up. I traced through Gorilla.cpp until the PUSH_VERTEX calls and the mBackgroundColour correctly has an alpha element of 1.0.
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am
x 24

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by N0vember »

I would try to write the texture to a file just to check that it's messed up (it probably is). Just to be sure that the problem is in the pixel data, and that the purple ones are not at the max alpha.
Or just check manually the right pixel in the texture, but I'm lazy and saving the whole texture is almost simpler.

Something like that :

Code: Select all

		Ogre::HardwarePixelBufferSharedPtr buffer = texture->getBuffer();
		buffer->lock(Ogre::HardwareBuffer::HBL_NORMAL);

		Ogre::Image img;
		img.loadDynamicImage(static_cast<Ogre::uchar*>(buffer->getCurrentLock().data), atlasWidth, atlasHeight, texture->getDepth(), texture->getFormat());
		img.save("filename.png");

		buffer->unlock();
But then I'm not savy enough about the process of rendering to a rendertarget to determine how it happened. Can you show the parameters you created the rendertexture with ?
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by AshMcConnell »

Thanks N0vember, with a clear head and a bit of time I have solved it.

I had 2 problems. I had to set the background colour of the viewport to transparent: -

Code: Select all

_gorillaScreen->getViewport()->setBackgroundColour(Ogre::ColourValue(1,1,1,0));
2nd problem was the material blend. I had it set to scene_blend add whereas it should have been scene_blend alpha_blend

Thanks for your help!

Image

PS. There is a slightly more direct way of writing the contents to file: -

Code: Select all

_gorillaScreen->getViewport()->getTarget()->writeContentsToFile("PlayerNameBanner.png");
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am
x 24

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by N0vember »

AshMcConnell wrote: 2nd problem was the material blend. I had it set to scene_blend add whereas it should have been scene_blend alpha_blend
Wow, I didn't even see that part in your script. Anyway, I'm far from being an Ogre guru :p
Nice that you finally found out.
codetemplar
Gnoblar
Posts: 22
Joined: Mon Nov 24, 2014 8:02 pm

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by codetemplar »

Hi all,

I have a 3rd party DLL that fills in a buffer with pixel data to be rendered on to a texture and presented. In my old graphics library I would lock a texture, copy the data buffer onto the texture using memcpy and then unlock the texture.

Does gorilla support this behaviour and if not is it possible for me to add it without much fight from gorilla?
If so how is it best to go about it?

Thanks
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am
x 24

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by N0vember »

codetemplar wrote:Hi all,

I have a 3rd party DLL that fills in a buffer with pixel data to be rendered on to a texture and presented. In my old graphics library I would lock a texture, copy the data buffer onto the texture using memcpy and then unlock the texture.

Does gorilla support this behaviour and if not is it possible for me to add it without much fight from gorilla?
If so how is it best to go about it?

Thanks
Can you explain the link with gorilla in this case ? I don't really understand. What you describe can be done with an Ogre texture.
But Gorilla uses TextureAtlas, and each TextureAtlas is on one Ogre Texture. And gorilla uses only one Texture per Screen.
Why not render directly to an Ogre Texture ? Why do you need Gorilla to handle this at all ?
codetemplar
Gnoblar
Posts: 22
Joined: Mon Nov 24, 2014 8:02 pm

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by codetemplar »

Thanks for the reply.

I am using gorilla for 2d rendering and I need to render this texture on a gorilla layer giving me complete control of where it gets rendered in relation to other gorilla sprites.

Thanks again
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am
x 24

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by N0vember »

Okay, it's a bit tricky since there is one Texture per Screen.
Basically it will always boil down to a "manual trick". Gorilla will not handle this problem for you.

You have a few options :
- Render your textured rectangle manually before Gorilla draws its stuff. In the end it's the simplest solution I believe.
- Try creating multiple gorilla Screens (Silverback::createScreen) on the same RenderTarget, one for the Ui stuff, and another just for your texture, and get the Texture of the TextureAtlas manually and lock it / update it / unlock it .
- Use a custom modification I made to gorilla and posted somewhere to embed a Viewport which is basically a textured Rect, and update this Rect texture. I made Gorilla render the Viewport before any Ui element is drawn, so it is under them.

In all these cases Gorilla will not handle the ordering for you, so you will have to choose : either draw your textured rect on top (after Gorilla), but it will always overlap your Ui elements, or either draw it on the bottom, but then no Ui element has to be on top of it or it will be hidden, but you can have small elements cover it.
Honas
Gnoblar
Posts: 23
Joined: Thu May 31, 2012 2:09 pm

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by Honas »

Hello everyone,

I want to put speech bubbles in my 3D world, but the drawing order is messed up. Here's a picture:

Image

The smallest text is far away, while the big text in the front is very near to the camera. But the middle one gets overdrawn by the farthest text. If I invert the order of construction then the order seems fine from this perspective, but when you turn the camera by 180° degrees you get the exact same problem. Here's some code of the construction:

Code: Select all

   Ogre::Vector2 size = Ogre::Vector2(3,1);
	Gorilla::Layer* _screen = silverback->createScreenRenderable( size, "dejavu");
	
	_node = Ogre::Root::getSingleton().getSceneManager("main")->getRootSceneNode()->createChildSceneNode();
	_node->setPosition(spawnPos);
	_node->attachObject(_screen);
	
	_layer= _screen->createLayer(0);
	
	Gorilla::Rectangle* _background = _layer->createRectangle(0,0, size.x * 100, size.y * 100);
	_background->background_image("bubble"); // sprite defined in dejavu

	Gorilla::MarkupText* _markUpText = _layer->createMarkupText(14, 15,15, "");
If I do something like

Code: Select all

_screen->setMaterial("SomeMaterial");
the depth checking is correct, but I cannot see my sprite and the markup gets messed up badly. Something like

Code: Select all

_screen->getMaterial()->setDepthCheckEnabled(true);
has also no effect. The material name seems to be "Gorilla3D.dejavu.png", which seems weird to me. Any ideas?
rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by rpgplayerrobin »

Hey!

This project is amazing, I will try to use it for my game for sure. Awesome job betajaen! :D

I saw a tile experiment on the first page in code, but I can't see it anywhere in the downloaded code from git, so I made my own tile function.

If you want tiling to work, place this in Rectangle::_redraw() after the Border but before the Fill (but you manually need to add variables/functions so it actually makes it into the if case):

Code: Select all

if(mTileX != 1.0f || mTileY != 1.0f)
{
	Vertex temp;
	Ogre::ColourValue tmpColour = mBackgroundColour[0];

	Ogre::Real tmpUVLeft = mUV[0].x;
	Ogre::Real tmpUVTop = mUV[0].y;
	Ogre::Real tmpUVRight = mUV[2].x;
	Ogre::Real tmpUVBottom = mUV[2].y;

	Ogre::Real tmpVertexWidth = (mRight - mLeft) / mTileX;
	Ogre::Real tmpVertexHeight = (mBottom - mTop) / mTileY;
	Ogre::Vector2 aCurrent = Ogre::Vector2::ZERO;
	Ogre::Vector2 bCurrent = Ogre::Vector2::ZERO;
	Ogre::Vector2 cCurrent = Ogre::Vector2::ZERO;
	Ogre::Vector2 dCurrent = Ogre::Vector2::ZERO;
	Ogre::Real tmpVertexTranslateX = 0.0f;
	Ogre::Real tmpVertexTranslateY = 0.0f;
	for(Ogre::Real j = mTileY; j > 0.0001f; j -= 1.0f)
	{
		for(Ogre::Real i = mTileX; i > 0.0001f; i -= 1.0f)
		{
			float tmpPercentageWidth = 1.0f;	 
			if(i < 1.0f)
				tmpPercentageWidth = i;

			float tmpPercentageHeight = 1.0f;
			if(j < 1.0f)
				tmpPercentageHeight = j;

			Ogre::Real tmpRight = mLeft + (tmpVertexWidth * tmpPercentageWidth);
			Ogre::Real tmpBottom = mLeft + (tmpVertexHeight * tmpPercentageHeight);

			aCurrent.x = mLeft + texelOffsetX; // Top left
			aCurrent.y = mTop + texelOffsetX;
			bCurrent.x = tmpRight + texelOffsetX; // Top right
			bCurrent.y = mTop + texelOffsetX;
			cCurrent.x = mLeft + texelOffsetX; // Bottom left
			cCurrent.y = tmpBottom + texelOffsetX;
			dCurrent.x = tmpRight + texelOffsetX; // Bottom right
			dCurrent.y = tmpBottom + texelOffsetX;

			aCurrent.x += tmpVertexTranslateX;
			aCurrent.y += tmpVertexTranslateY;

			bCurrent.x += tmpVertexTranslateX;
			bCurrent.y += tmpVertexTranslateY; 

			cCurrent.x += tmpVertexTranslateX;
			cCurrent.y += tmpVertexTranslateY;

			dCurrent.x += tmpVertexTranslateX;
			dCurrent.y += tmpVertexTranslateY;

			Ogre::Vector2 tmpUV[4];
			tmpUV[0].x = tmpUV[3].x = tmpUVLeft - texelOffsetX;
			tmpUV[0].y = tmpUV[1].y = tmpUVTop - texelOffsetY;
			tmpUV[1].x = tmpUV[2].x = tmpUVLeft + ( (tmpUVRight - tmpUVLeft) * tmpPercentageWidth ) + texelOffsetX; // Clips the texture if < 1.0
			tmpUV[2].y = tmpUV[3].y = tmpUVTop + ( (tmpUVBottom - tmpUVTop) * tmpPercentageHeight ) + texelOffsetY;

			// Triangle A
			PUSH_VERTEX(mVertices, temp, cCurrent.x, cCurrent.y, tmpUV[3], tmpColour);    // Left/Bottom  3
			PUSH_VERTEX(mVertices, temp, bCurrent.x, bCurrent.y, tmpUV[1], tmpColour);    // Right/Top    1
			PUSH_VERTEX(mVertices, temp, aCurrent.x, aCurrent.y, tmpUV[0], tmpColour);    // Left/Top     0

			// Triangle B
			PUSH_VERTEX(mVertices, temp, cCurrent.x, cCurrent.y, tmpUV[3], tmpColour);    // Left/Bottom   3
			PUSH_VERTEX(mVertices, temp, dCurrent.x, dCurrent.y, tmpUV[2], tmpColour);    // Right/Bottom  2
			PUSH_VERTEX(mVertices, temp, bCurrent.x, bCurrent.y, tmpUV[1], tmpColour);    // Right/Top     1

			tmpVertexTranslateX += tmpVertexWidth;
		}

		tmpVertexTranslateY += tmpVertexHeight;
		tmpVertexTranslateX = 0.0f;
	}

	// Return the function, we do not want to render the normal background
	return;
}
I have one question though... How do you pack everything together?
I have a directory with around 50+ textures (and I want around 3 font sizes), how do I get them into the Gorilla format? :(

EDIT: I have now searched for the font packer for Gorilla for hours with no results... All links are broken, even the ones on the wiki, and also all posts by zarlox (who made the Gorilla export of BFG).
Is there anyone out there that still have that application/code?

EDIT 2: Nevermind, I made my own program for this, although it is not close to be perfect hehe.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by c6burns »

No one has a copy of Bitmap Font Generator lying around? Would be nice to have that stashed somewhere ... all wiki and forum links are indeed dead :?
User avatar
Thyrion
Goblin
Posts: 224
Joined: Wed Jul 31, 2013 1:58 pm
Location: germany
x 8

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by Thyrion »

I'm using this one. It's a VS2010 project.

http://www.filedropper.com/fontgen
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Gorilla - minimal hud and overlay replacement for OGRE

Post by c6burns »

Thanks Lannister!
Post Reply