2d sprite manager, for Ogre

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1

Post by hmoraldo »

First make sure that the original code works ok, before adding the 2d sprite manager. If you can't make that work, go back here http://www.ogre3d.org/wiki/index.php/Se ... pplication and make sure you are setting your project settings well.

After that, add the 2d sprite manager in separate new files (and then add them to your vc project), don't just append its contents to other code files. Yes it could work otherwise too, but this is the right way to do it.

Also, make sure this line:

Code: Select all

Ogre2dManager* ogre2dManager;
is inside the public: section of your listener class code (that is: ogre2dManager should be a member variable of the class).

Do that again, and if that keeps failing, we can check where the error might be.

Edit: oh, and about the crash: please debug it and post here your stacktrace.
Last edited by hmoraldo on Thu Feb 01, 2007 3:38 pm, edited 1 time in total.
H. Hernan Moraldo
Personal website
User avatar
odyeiop
Halfling
Posts: 97
Joined: Fri Dec 22, 2006 4:56 am
Location: stoney creek

Post by odyeiop »

I was using this, and found that it was crashing in the blit function at this line
spr.texHandle=tp->getHandle();
I have the image I'm using in my General media folder. Do I have to reference the directory?
"Test/General/Image.jpg"
or can I just pass in
"Image.jpg" (which is what I am doing).
I'm Immortal as you are Divine.
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1

Post by hmoraldo »

odyeiop wrote:I have the image I'm using in my General media folder. Do I have to reference the directory?
"Test/General/Image.jpg"
or can I just pass in
"Image.jpg" (which is what I am doing).
No, the texture resource has to be already loaded in the system. Once it is, you only need to reference it by its file name: "Image.jpg".

I'll probably be creating a new sprite manager soon, using renderables and materials instead of textures, and managing this resource loading by itself.
H. Hernan Moraldo
Personal website
User avatar
odyeiop
Halfling
Posts: 97
Joined: Fri Dec 22, 2006 4:56 am
Location: stoney creek

Post by odyeiop »

So if not when the ResourceManager loads it from the .cfg file, then, excuse the noobishness, how would I load it into the system?

Would I need to use something to grab it from the material file?
I'm Immortal as you are Divine.
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1

Post by hmoraldo »

You'd do something like this:

Code: Select all

Ogre::TextureManager::getSingleton().load("Image.jpg",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
H. Hernan Moraldo
Personal website
pasman
Gnoblar
Posts: 14
Joined: Thu Jan 12, 2006 4:42 pm
Location: Cluj, Romania

Post by pasman »

Hi, an easier way is to add this code to your blit function:

Code: Select all

tp=Ogre::TextureManager::getSingleton().getByName(textureName);
		if (tp.isNull())	// must load texture
		{
			Ogre::String orpGroup;
			orpGroup = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.c_str();


			try
			{
				Ogre::TextureManager::getSingleton().load(textureName,orpGroup);
			}
			catch(...)
			{
				//Ogre::LogManager::getSingleton().logMessage("SpriteManager cannot locate resource "+textureName);
				return;
			}
		}

before the line:

Code: Select all

tp=Ogre::TextureManager::getSingleton().getByName(textureName);
Hope it helps, you won't be needing to load your resources prior to this.
Eternius
Gnoblar
Posts: 15
Joined: Fri Aug 11, 2006 9:43 am

Post by Eternius »

hmoraldo:
I spent some time to learn about linking and figured out how to include the code without pasting it directly inside mine so now it's clean like it should be. I also moved the declaration of ogre2dManager into the public section, but the result is still the same crash.

The node code is here
I'm not sure what a stracktrace is, but this was the most useful-looking info I saw in the IDE:

Code: Select all

>	test_2d.exe!std::list<Ogre2dSprite,std::allocator<Ogre2dSprite> >::end()  Line 538 + 0x7 bytes	C++
 	test_2d.exe!std::list<Ogre2dSprite,std::allocator<Ogre2dSprite> >::push_back(const Ogre2dSprite & _Val={...})  Line 654 + 0x18 bytes	C++
 	test_2d.exe!Ogre2dManager::spriteBltFull(std::basic_string<char,std::char_traits<char>,std::allocator<char> > textureName="10points.png", double x1=-0.50000000000000000, double y1=0.50000000000000000, double x2=0.50000000000000000, double y2=-0.50000000000000000, double tx1=0.00000000000000000, double ty1=0.00000000000000000, double tx2=1.0000000000000000, double ty2=1.0000000000000000)  Line 304	C++
 	test_2d.exe!TutorialFrameListener::frameStarted(const Ogre::FrameEvent & evt={...})  Line 36	C++
 	OgreMain_d.dll!10a56866() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for OgreMain_d.dll]	
 	OgreMain_d.dll!10a56ed8() 	
 	OgreMain_d.dll!10a5750b() 	
 	OgreMain_d.dll!10a57481() 	
 	test_2d.exe!ExampleApplication::go()  Line 58 + 0xe bytes	C++
 	test_2d.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * __formal=0x00000000, char * strCmdLine=0x00151f03, HINSTANCE__ * __formal=0x00000000)  Line 187 + 0x8 bytes	C++
 	test_2d.exe!__tmainCRTStartup()  Line 578 + 0x35 bytes	C
 	test_2d.exe!WinMainCRTStartup()  Line 403	C
 	kernel32.dll!7c816d4f() 	
 	kernel32.dll!7c8399f3() 	
 	msvcr80d.dll!_wstat32(const unsigned short * name=0x0073006f, _stat32 * buf=0x0066006f)  Line 298 + 0xc bytes	C
 	msvcr80d.dll!_wstat32(const unsigned short * name=0x0073006f, _stat32 * buf=0x0066006f)  Line 298 + 0xc bytes	C
 	msvcr80d.dll!_wstat32(const unsigned short * name=0x00650074, _stat32 * buf=0x0033006d)  Line 298 + 0xc bytes	C
 	msvcr80d.dll!_tsopen_nolock(int * punlock_flag=0x00cb45c6, int * pfh=0x558d016a, const char * path=0x458b52cb, int oflag=1359514380, int shflag=1136616, int pmode=214205184, int bSecure=1064681605)  Line 463 + 0x11 bytes	C
 	00000093()	
Edit: I should probably add that the code does run on it's own, and commenting out the call to the blit function in frame start also makes it run fine, so the error is down to that. Also as I said earlier, completely commenting out

Code: Select all

Ogre2dManager* ogre2dManager=new Ogre2dManager;
ogre2dManager->init(mSceneMgr, Ogre::RENDER_QUEUE_OVERLAY, true);
does not change the error, so the program is behaving as though the above is not called or called in the wrong scope?
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1

Post by hmoraldo »

pasman: I think I should have done that since the beginning. That's a good idea, and I was thinking in doing that for a new 2d sprite manager based on materials and renderables, but now I'll patch the original code as well.

However, I'm going to travel now, and I won't be able to touch that until I'm back (in one or two weeks).

The same for eternius... I'd like to test the code here in my computer but I'm closing a program now and going out... if you can wait until I'm back, I'll try to see it then. Sorry...
H. Hernan Moraldo
Personal website
Eternius
Gnoblar
Posts: 15
Joined: Fri Aug 11, 2006 9:43 am

Post by Eternius »

Yes I'd still like the help when you get back please =)
Upsilon
Gnoblar
Posts: 18
Joined: Fri Jan 26, 2007 9:01 am
Location: New York, USA

Post by Upsilon »

not to interupt Eternius problem, but i have one to. When i use a reflection with this, All the sprites are rendered on to the reflection texture rather than onto the screen. How would i avoid this, does any one know?
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1

Post by hmoraldo »

I haven't used reflections with the 2d manager, can you please detail what you are doing?

Eternius: I'm almost back now, maybe in monday or tuesday I'll be back in my usual computer and will check that.
H. Hernan Moraldo
Personal website
Upsilon
Gnoblar
Posts: 18
Joined: Fri Jan 26, 2007 9:01 am
Location: New York, USA

Post by Upsilon »

Ok, figured it out, i now add the sprites in the PosterRender callback of the reflection texture, rather than the Frame callback, that way they are added after i render to the reflection texture. Because they only render once, and rendering to a reflection and the scene requires two render calls.
User avatar
ghoulsblade
Halfling
Posts: 86
Joined: Sun Mar 05, 2006 2:55 pm
Location: Germany
x 2

Post by ghoulsblade »

i just wanted to say thank you very much for this sprite manager, the code has been very enlightening =)
Eternius
Gnoblar
Posts: 15
Joined: Fri Aug 11, 2006 9:43 am

Post by Eternius »

So any luck with my case?
My use of ogre is completely stopped till I can do this :/
rnodal
Gnoblar
Posts: 24
Joined: Mon Oct 02, 2006 11:05 pm

Post by rnodal »

Does anyone know why I'm getting an "Assertion Failed"
File: ogresharedptr.h
Line: 158

I have loaded all my resources. Could it be because I'm using the latest version of Ogre?

Code: Select all

ogre2dManager->spriteBltFull("loading_image.png", -0.1, 0.1, 0.1, -0.1);
any ideas? Thanks for your time.

-r
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1

Post by hmoraldo »

ghoulsblade: thank you!

Eternius: sorry, these weeks I've been working with stuff unrelated to Ogre, so I couldn't do much with this. I'll try to check this next days... can you look for my email address in my website and send me your full code by email?

rnodal: I didn't test it with Eihort yet, didn't have the time. I should check that next week.
H. Hernan Moraldo
Personal website
rnodal
Gnoblar
Posts: 24
Joined: Mon Oct 02, 2006 11:05 pm

Post by rnodal »

hmoraldo wrote: rnodal: I didn't test it with Eihort yet, didn't have the time. I should check that next week.
No problem. Take your time. Thanks for your time.

-r
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1

Post by hmoraldo »

I just wanted to announce that for a while I'll be very busy with some other stuff, so I'm not sure I'll be coding new stuff for the 2d sprite manager in some time. Please if you have questions or problems, ask them here and I'll try to see how I can help in my spare time.

Sorry for that :|
H. Hernan Moraldo
Personal website
User avatar
odyeiop
Halfling
Posts: 97
Joined: Fri Dec 22, 2006 4:56 am
Location: stoney creek

Post by odyeiop »

Is there an easy way to set the Sprites alpha?

I'd like to change the blit function to take in a float (clamped 1.0-0.0) and that would alter the alpha respectively.
I'm Immortal as you are Divine.
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1

Post by hmoraldo »

You should modify the code to separe sprites not only by texture, but also by alpha, so that no two sprites in a chunk have different alpha neither different texture, and then when this code is executed:

Code: Select all

   for (currChunk=chunks.begin(); currChunk!=endChunk; currChunk++)
   {
      renderOp.vertexData->vertexCount=currChunk->vertexCount;
      tp=Ogre::TextureManager::getSingleton().getByHandle(currChunk->texHandle);
      rs->_setTexture(0, true, tp->getName());
      rs->_render(renderOp);
      renderOp.vertexData->vertexStart+=currChunk->vertexCount;
   }
you should be doing your alpha settings per chunk after doing the _setTexture (whenever you actually need to change alpha).
H. Hernan Moraldo
Personal website
User avatar
odyeiop
Halfling
Posts: 97
Joined: Fri Dec 22, 2006 4:56 am
Location: stoney creek

Post by odyeiop »

ah, I hadn't thought of doing it like that.

what I had was a sheet that was going to be used sort of like a GUI overlay, and wanted to adjust it in code. I guess having a larger sheet with a bunch of different alphas will have to do.

Thanks =)
I'm Immortal as you are Divine.
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1

Post by hmoraldo »

Hmmm, I don't understand your sheet approach idea. Could you please explain?
H. Hernan Moraldo
Personal website
User avatar
odyeiop
Halfling
Posts: 97
Joined: Fri Dec 22, 2006 4:56 am
Location: stoney creek

Post by odyeiop »

It was a sheet full of fairly large objects (512x512 - 1024x1024) that were going to be used for some display purposes. Fading them properly in sprite form would take a pretty large texture, so I just wanted to be able to fade their alpha over time.

I'd do it with shaders.. but I don't have the time to learn shaders right now as this project is due relatively soon. Not to worried about it though, it's just a little bit of extra stuff that I'd be throwing in, it would be nice to have though.
I'm Immortal as you are Divine.
pwnedbyogre
Gnoblar
Posts: 4
Joined: Mon Apr 16, 2007 2:13 am

Post by pwnedbyogre »

Thanks a lot for making this. I've found it very useful in my group project! =)

I should probably let you know about a possible bug that I've found. I was drawing a tetrahedron from a png with a transparent background, and for some reason it looked like it mapped the bottom and left boarders of the images to the top and right! I solved the issue by adding blank space on the sides, but I figured you might want to know.

Anyway, thanks again for making this!
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1

Post by hmoraldo »

Thanks for your feedback!

Do you mean all images are being drawn that way? are you sure?
H. Hernan Moraldo
Personal website